LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Force VISA to release device

Hello group.

 

I am using VISA to communicate to a system that has a USB serial port. The user can unplug/replug the system from the PC and the application has to support this scenario and recover communications. I get a proper -1073807343 error code when the device is removed from the system. However, since the device is not present anymore all the VISA VIs that use the resource don't execute. In particular, it is not possible to close the port and internally VISA never releases it, so when the user replugs the device the application is not able to open it again. Closing and opening the application is the only workaround but this is not desirable.

 

Is there a way to force VISA to release the port when I detect that it has been removed so I can reopen it again once it has been replugged?

 

Regards.

0 Kudos
Message 1 of 6
(4,835 Views)

I think this application would be well-handled with state machine.  My suggestion would be to use a state machine to catch error 1073807343.  When the error is caught, it could close the VISA session, then go back into the state where the VISA session tries to establish a connection to the device.  If the device has not yet been plugged in again, then stay in the state where you try to discover the device and open a new VISA session.  If the device has been plugged in and discovered, then proceed as normal.

 

0 Kudos
Message 2 of 6
(4,808 Views)

Hello Rory.

 

Thanks for your reply. The problem is not that I can't detect and act upon the error. The issue is that any attempt to close the device that is not present in the system does not execute, in particular the close VISA resource VI. So the program is stuck with a VISA resource that is permanently in an error state and it can never open and use it again.

 

I have been looking around and it seems this is a well-known internal VISA issue. It also happens with real hardware serial ports in Windows systems. I still don't find a solution to programmatically reset the VISA state.

 

Regards.

0 Kudos
Message 3 of 6
(4,788 Views)

pbleyer,

 

Take a look at my attached code.  Here, I'm opening a connection on COM3 to an Arduino (just a USB device I had sitting on my desk at the time), and writing an arbitrary character to it every second. When I physically unplug the device from my computer, a VISA error is thrown in the VISA Write VI, and thus the loop is stopped.  Then, I close the VISA connection (with the device still unplugged) and use the Simple Error Handler to display the error to me.  The Simple Error Handler isn't necessary, but I just wanted to see it for myself.  After that, I clear all current errors and wait 5 seconds.  During these 5 seconds, I plug the VISA USB device back in and try to re-open a connection to it.  This works without any problems.  Perhaps you could try something like this in your code.

 

Best of luck!

visa_test.png

Download All
Message 4 of 6
(4,757 Views)

5 Seconds is the key!

0 Kudos
Message 5 of 6
(3,456 Views)

I Almost hate to tell you this, but you have the WRONG ANSWER!

 

The correct answer is to place physical gaurds on the USB connections.  Period, the user should not be able to access the physical layer while a test application is running.

 

In some Condition Monitoring applications you may find cases where a USB device needs to be swapped/ removed/ replaced for maintainance issues.  If this is the case handle it elegantly by entering a "Maint Mode For MyDev_nnn" close the resource, prior to the connection being disconnected then open it again after leaving the maintainance mode.  (Make sure you add the maintanence activities to the log file)

 


"Should be" isn't "Is" -Jay
Message 6 of 6
(3,438 Views)