LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Choosing COM ports without troubling the user

Solved!
Go to solution

I am writing a LabVIEW application that uses at least 2 COM ports.  It will compile to run on different machines.  Now I expect that at any one machine the COM ports will stay fixed, but there is no way I can expect the serial devices I use to pop up at the same COM port on every different machine (especially as some will have legacy RS232 ports, others USB to RS232 converters).

 

This is a problem I solved before when programming in "C", by putting a text file on each PC, which in the spirit of an INI file names which COM port is used for each of the peripherals I need.

 

It occurs to me that I can do exactly the same in LabVIEW, open a text file and parse it to see what COM ports are named, then use the resulting number as the selector for a CASE structure, in which each case holds a (VISA Resource) constant COM1, COM2 and so on.

 

Is this crazy, or is there a much easier way ?

 

On trying it out, one problem occurs, and that is that I can't create constants for ports that don't exist on the machine I'm developing it on (I'm using 2009).  Well, I can go into WIndows device manager and do some reallocation to eventually get a full set of COM ports for my CASE structure, but can I trust LabVIEW not to change them as the ports disappear again ?

 

Thanks

 

p.s. I think this is my first post, came here often before but always found the answer without posting.  Apologies if this is already covered, but it seems a bit too "wooly" to be amenable to searching without getting tens of thousands of results.

0 Kudos
Message 1 of 7
(3,804 Views)

Indeed, machineparameters should be in a INI file.

Just create a parameter for each COM port you want to use with the value of a COM port.

 

That's the way to do it.

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
0 Kudos
Message 2 of 7
(3,799 Views)

This is an example of one of my INI files I'm using :

 

 

[Hardware]
Microscope.Address=COM1
DI.Address=Dev1/Port0/line0
IBR.Address=COM1

 

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
Message 3 of 7
(3,796 Views)
Solution
Accepted by topic author Branta

You don't need a case structure for every port.

 

You can use Variant to Data to convert a string name to a VISA reference.

 

Attached is a snippet of one of my programs where I retrieve Comport settings from a config .ini file.

 

There are a few special things about it.

1.  I used a typedef'd enum that designates each of my com ports of interest.

2.  I stored the VISA com port references in a functional global variable so I can use them elsewhere.  The typedef enum is important as part of the selection to get the correct reference out of the FGV.

3.  I used an OpenG function get strings from enum so that my string name that I use for the key and enum value are cross referenced.

Message 4 of 7
(3,792 Views)

Thanks, I learned a lot today !  I didn't even know there was all that inbuilt support for INI files in LabVIEW, I had expected I would be parsing the file "the hard way".  Now I'm enthused to go as far as writing an INI file from LabVIEW if none was found.

 

I especially like Ravens Fan's "Variant to Data" trick to avoid my case structure, very neat, I would never have found that function in months of browsing the palettes.

 

0 Kudos
Message 5 of 7
(3,733 Views)

No problem at all.  Can you set this item to solved? 😉

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
0 Kudos
Message 6 of 7
(3,727 Views)

I had a similar problem with USB-Comport on laptops that as the users would unplug and plug in different USB comports each time they might start up the program. Windows would assign new comport numbers to USB devices that it had not seen before.

 

Lucky I could detect the device by either it's command prompt or it was a SCIP compliant device and would reply to an "*IDN?" command.

 

I used the "VISA Find" function to get a list of available comports and then went looking for my devices.

Omar
0 Kudos
Message 7 of 7
(3,708 Views)