Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I tell if a serial port is already in use?

I am using VISA to communicate with up to 4 serial ports.
 
I can get a list of all available serial ports on the computer by using  "VISA Find Resource" with the expression "ASRL[0-9]*::?*INSTR", and then present the user with a list of COM ports to select from.
But how do I tell if a particular port is already being used?
If a serial port is being used by another (non-LabVIEW) application, then "VISA Open" will return an error if I try to open the serial port. But I get no error if the serial port is already being used in the same LabVIEW application.
I only want to present the user with a list of free serial ports that he can choose from.
 
Thanks,
 
Mark.
0 Kudos
Message 1 of 5
(8,142 Views)
Mark,

I am at the moment not aware of any system ressource you can check, that will give you the required info. Have checked a lot of VISA properties...

So I'd suggest doing it yourself. The idea is to use a global as cluster of (updated: boolean, array of  myports: cluster of (VISA-Ressource, used: boolean)). Typedef this structure and create a global.
Than replace all VISA: Open-nodes with a self-made VI 'myOpen', that, for the VISA-Ressource to open, first checks the global if it is in use, opens it (if unused) and replaces the global value for that ressource that it is now open. The same has to be done with VISA close ('myClose), as this should free the ressource.
Now, in every VI using serial ports, you can do this:
* Find VISA ressources, if Global.updated is False.
* Get a list of all VISA-Ressources from Global, that are not used
* provide this to your operator
* Open the desired Ressource with 'myOpen'
... use it
* Close it with 'myClose'

Greetings from Germany!<br>-- <br>Uwe

Message Edited by LuI on 08-10-2005 07:49 AM

0 Kudos
Message 2 of 5
(8,138 Views)

Thanks Uwe,

 

I have implemented your suggestion, and it works well.

 

I sort of figured I would have to do something like this, but I was hoping there was a way that VISA could do it for me.

 

Mark.

0 Kudos
Message 3 of 5
(8,123 Views)

Hi,

 

I have the same request and it looks strange that we can't access to this property because the (serial) "Visa resource name" control present a dedicated pictogram near each serial port already openned in the selectionnable list.

In LabVIEW 2010, is there a way to obtain this VISA property ?

 

Thanks for your help

Emmanuel

0 Kudos
Message 4 of 5
(7,432 Views)

I believe that you can achieve what you want using the options available on VISA Open. You should set Duplicate Session to true, and Access Mode to Exclusive Lock, on every call to VISA Open in your application. With these settings, the second call to VISA Open will fail with an error.

 

This will prevent the VISA Open from using the cached handle to the serial port. Of course for this to work properly, you will have to always explicitly Open and Close your serial ports, rather than relying on LabVIEW to automatically open them as needed.

 

-Jason S.

0 Kudos
Message 5 of 5
(7,412 Views)