From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

USB Serial 232, LabVIEW hang-up when usb cable pulled out

Hi,

I have an application where i initialize a serial port of SeaLevel USB-232 converter, and continuosly send serial commands. i am trying to do error handling in case the USB cable got pulled out. If i recieve one of these errors i want to stop the application

-1073807298 - Could not perform operation because of I/O eror
-1073807246 - Resource Valid But cannot connect
-1073807194 - Connection has been lost

 

but LabVIEW doesnot stop the program it goes into hang-up ( not responding) state. the front panel seems to have the run arrow stopped but the block diagram run arrow still running. i have to connect the USB cable back on to stop the application.

and even the device manager seems to have the COM port still listed when the cable is disconnected as opposed to device manager refreshing the ports, which does happen only when the LabVIEW program is not running. so i am unable to close the visa resource or force re-open it again as the resource goes into some hang-up state. i used STOP and QUIT, both of them still require me to connect the cable back on so that it will do either of those. 

 

i tried opening and closing reference after every send but causes a delay in my responses that is not acceptable as i need the serial commands to be sent very quickly continously. 

is there a way for the program to close or close the reference without hang-up in case usb cable got pulled out. VISA doesnot seem to play well with usb adapter

 

any help is appreciated

Thanks

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

COM ports get hung if theres a disconnection while you have an open VISA port; you'll see the green computers of death. How often are you polling these ports? If it's anything less frequent that once every 30 seconds, my personal recommendation is to close the connection as soon as you're done reading from it. Your application will then attempt to open it again and give you an error which you can then handle, with no problems from the GCOD.

 

I once ran into a similar problem when controlling some USB programmable pumps. I had set it up to just open the connection and write to it once every 5-10 mins, and close it when the application was shut down, sometimes 8-12 hours later. What I saw was that after a certain amount of time, these connections get "stale" and need to be closed. Due to how fast it is to open and close connections (a couple hundred ms at worst), it's often best to just open it, use it, and close it back up.

Message 2 of 5
(3,508 Views)

Once i get one of those 3 errors. i go to 

Serial: Close reference

Serial : Refresh ports (to find the SeaLevel Adapter)

Serial : Init --> send serial command

 

the problem is that since it still shows up in device manager it thinks that the port exists and tries to initialize and connect but i get the same error back and it goes on in this loop until i plug the cable back on.

0 Kudos
Message 3 of 5
(3,496 Views)

You need to close the reference every time you use it (again, unless you're polling this thing really frequently). Then you can handle this on open rather than on read. The problem is that you likely have a long timeout, and th execution is stalled while it's trying to read, even though the connection is no longer available. Closing the connection after the device is already unplugged will do no good; the resource is already busy, and actual closure requires the device to be connected.

Message 4 of 5
(3,494 Views)

Does changing the read timeout have any impact on how long it 'hangs' for? If your timeout is set to 10s and it hangs for 10s, then you need to reduce the timeout. If it hangs for longer than your timeout, then I suspect there is something funny going on with the OS/LabVIEW interaction.


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 5 of 5
(3,468 Views)