From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

visa error handling in serial communication

Greetings,


I have a problem with the serial communication in my Labview program.
I have made an application that reads from serial port, searches for beggining characters, and later counts data after that beggining characters into variables in Labview program.

Everything work fine, but problem starts when I unplug the device from computer.
Program blocks and I could not do anything. Even Visa Close does not do anything.

I need to restart my computer to make my application works.

I made some indicators in subVi, and I see that when I unplug the device the error from READ VISA changes.
My question is:  How to handle this event(error) to restart or unblock my serial device.

I am attaching a SubVi, that searches for starting characters " KBON,"

 

Best regards,
Chris

0 Kudos
Message 1 of 3
(5,167 Views)

Hi Biedak,

 

you should actually use that "changed error" information.

Right now you just look for any error by the status boolean, but you should also use the error number to decide what to do next...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 3
(5,158 Views)

Hi Chris,

 

From the standpoint of VISA capabilities, you should be able to programmatically handle the desconection of the serial port. I am however not certain that your specific serial port hardware is OK with that.

 

As to how to handle disconnection using VISA:

I recommend using the "timeout" pin of the VISA Configure Serial Port VI

when the timeout is reached and no data is transferred, you will get a timeout error on the error wire.

You can then programmatically handle this error case in your code in a very similarly to this example.

 

I recommend experimenting to see what error codes your application throws, or alternatively you can use the VISA error codes documentation to create the case structures needed to hande these errors.

 

In all cases, you should close the VISA reference. Leaving the serial port rescource "open" in your operating system may be the reason why you need to restart your computer every time (as restarting will for sure free up the serial port rescource).

Best Regards,
T Simon
National Instruments
Applications Engineer
Certified LabVIEW Developer - Certified TestStand Architect
Message 3 of 3
(5,129 Views)