Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I break a serial read operation

I have a serial read operation set up to wait until something is there (timeout set to its max value). The problem is when I want to close the program with a stop button, I can not exit the read operation. The only way to stop is press the stop button. How can I programatically exit the read operation and end the program.

Thanks
0 Kudos
Message 1 of 4
(3,114 Views)
Set the timeout to something reasonable!

After the read times out, check if you should stop.

Otherwise repeat the read attempt.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 4
(3,114 Views)
Hello,
I am attaching an example VI (with serial read inside the while loop) which uses the error cluster to check if there is a timeout and if there is then it exits out of the while loop and ends the program.
Please examine the VI and let me know if that helps you out. If not, please email me back so that I can assist you further.
Thank you and have a great day!
Koninika
National Instruments
0 Kudos
Message 3 of 4
(3,114 Views)
Thanks for the help. I was assuming there was a way to stop a read operation before it times out, but since that function apparently does not exist, I wrote the program a little differently. I wanted to be able to end the program with a stop button but that read opertation hung everything up. The way I fixed it was to wire the read operation in a while loop and configure the serial port with a 250 ms timeout. In the loop, I read the error cluster and tested for the timeout code. If the code was there and the stop button was not pressed, the loop tried to read again. If the stop button was pressed, it would clear the error and exit. If that loop was a successful read and there was no error, the loop would exit and the program could continue. Th
anks for the input.
0 Kudos
Message 4 of 4
(3,114 Views)