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: 

How to set the Serial Connection dynamically

Hello,

 

   I have a small project where I send a string over at 1Hz over an RS-232 connection.  Now that I got everything working nice, I'd like to be able to set the COM1, COM2, COM3, etc. by what's set inside of an INI file.  I made an integer value that controls what the port is selected (value 1 = COM1, value 2 = COM2, value 3 = COM3, etc.) and I got that reading out of the INI file without a hitch.  My question is how do I get it now to set to COM1?  Is there some function or sub-VI that missed?  I contemplated entering COM1 and the rest in a switch case, but that struck me as being very kludgy.  Ideally, it would be me passing in an integer and then the VI (or function) returns the Serial Connection reference.

0 Kudos
Message 1 of 7
(2,996 Views)
Why don't you just store 'Com1', 'Com2', etc. in the ini file instead of the more cryptic numeric? Why even use an ini? You can use the VISA Find Resource function to return all com ports and query each to see which is connected to your instrument/
0 Kudos
Message 2 of 7
(2,981 Views)

If you want to call it from your config file you could do something similar to below...

 

code.JPG

Message 3 of 7
(2,969 Views)

Dennis, the decision was made by others and not something that I could change.  It's a central INI file that other apps draw information from (this was done to centralize where the settings are stored so that we don't have 10 files and 2 years from now, when we have to change something, we don't have to kill ourselves finding where all of them are just to change the color of some button 🙂 .)

 

Personally, I would have gone with XML, but I got added on to the project later on, so...

 

I thought about putting in a string as you recommended, but the rest of the values are doubles and for the sake of simplicity and making the code more understandable, it's easy to just put in another double.

Message Edited by RS_233 on 02-16-2010 08:50 AM
0 Kudos
Message 4 of 7
(2,954 Views)
Why not just convert the number which point to the port to a string and then join it with the string constant "com"


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 5 of 7
(2,949 Views)

If stuck with an ini file and stuck with a numeric, just use the Format Into String.

 

Even if others are using an ini file, still don't see why you could not use the VISA Find Resources. Then you would not be dependent on someone entering the correct port.

0 Kudos
Message 6 of 7
(2,937 Views)

In what way should I use the VISA Find Resource?  Could you please post a little sample if that's not too much to ask?

 

The way I have it setup at the moment is the Find Resource VI is called and outputs an array of strings.  Then I select the one that I want and it becomes part of a cluster.  The cluster has a bunch of doubles and one VISA Resource Name (which, after look at it with the Context Help, it seems to be just a character array.)  That cluster gets fed into a bunch of Sub-VIs where the real work gets done.  The one thing that unnerves is that when I plug-in the cluster into one of the Sub-VIs I have a little red triangle at the connection, should I be concerned about this?  I interpret these as warnings when you compile C/C++ code.

 

I'd post what I have, but we have strict rules against doing something like that at work, which is why I haven't done this by now.

0 Kudos
Message 7 of 7
(2,932 Views)