03-16-2023 07:57 AM
I implemented a .net approach for establishing serial port COMS with my UUT. This approach utilizes the System.IO.Ports.SerialPort class and works as intended. However, I intermittently receive a popup message when the port is closed. This happens only once or twice a month. During execution a popup window appears with the following text:
TestStand has Detected a Fatal Error
System.IO.IOException: The handle is invalid
at System.IO.Ports.InternalResources.Win/0Error/(int 32 errorCode, String str)
at System.IO.Ports.InternalResources.Win/0Error()
System.IO.Ports.SerialStream.Dispose(Boolean Disposing)
System.IO.Ports.SerialStream.Finalize()
One interesting behavior of the popup is that it isn't modal, so I can continue execution and obtain passing results and a clean test report. On the other hand, if I select OK in the popup window the TestStand application will close.
I am using TestStand 2017. The DotNet version is 4.0.0.0.
I am unable to share my code but I utilize the same commands as the ones indicated in the following post (which I attached here): Solved: Sequence using .NET serial port class works only once after TestStand starts - NI Community
I have tried flushing the input and output buffers before closing the port and I think there was some improvement in the frequency of this error but it has not been eliminated.
Anyway, I would appreciate if anyone could share their experience with this class and/or if they had any thoughts on how I might troubleshoot this further. I would also consider an alternative approach if someone could offer a suggestion.
Thanks!
03-17-2023 08:15 AM
From the error message, your serial port may have lost objects during operation.
My guess:
I see that there is no delay time between sending data, receiving data streams asynchronously, and destroy serial port objects.
If the serial port asynchronously receives data with a delay for some reason, but the asynchronous operation does not block the main thread from continuing execution, it is possible that teststand has already run to the destroy object step of the clear group.
Now there is a contradiction: The receiving event has not yet been completed, but the serial port object has been discarded.
To verify this situation, I suggest that you can find some tools that can monitor serial communication. When Teststand repeatedly runs your sequence, use the monitor tool to synchronously view the entire communication process until the above error message is detected, then you will know where the problem is and what caused it.
However, in order to ensure the stability of serial communication, I will package the entire serial communication in C # as a class into a module, and then call this module to complete serial communication. In this class, I will handle many exceptions and optimize receiving events and threads to ensure that I can receive them completely and accurately, and that objects can be created and released correctly. This process can help you understand serial communication more clearly.
03-24-2023 10:53 AM
Thank you for taking the time to reply. I will take your advice into consideration. I have also opened a NI support ticket.
06-22-2024 12:18 PM
Hi A_I,
We also found this issue in one of our projects in which from time to time (5-7 days interval) we get this error.
Did you get any reply from NI? Did you managed to find a solution?
Thanks in advance.
Best Regards,
Rui Morais
08-15-2024 09:15 AM
Rui, this is still an ongoing problem, but it is occurring so infrequently that we haven't spent any additional time trying to debug it. NI offered a few suggestions but nothing conclusive. One suggestion they had was to confirm that the error occurs on more than one test station and I determined that is the case. As I mentioned, the popup we receive isn't modal so when we encounter this issue (popup window) we ignore it and test execution will continue.
Please reply if you make any progress with your issue.