LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.INI files vs .TXT files for changing default values in a .EXE?

Solved!
Go to solution

Hi,

I have a two-part question related to updating the default values of controls in an executable:

 

I am creating a LabVIEW executable for installation on two different production-floor computers.   I need to be able to change the default values of the front panel controls (as I would do with the “make this value default” command during development). From reading prior posts, I understand that I could use the “Write Configuration Settings File.vi” and “Read Configuration Settings File.vi” to generate a .INI file that would be read by the .EXE and would establish the desired values of the controls. However when I took a look at the block diagrams for those configuration .VIs, they don’t appear (to me) to be any easier to use than just reading values from a spreadsheet file. IE: Instead of using these configuration files and a .INI file, could I not instead just read values from a .TXT file that contains the desired values?   I’ve never used a .INI file before, or had to worry about “keys” and “sections,” so from my (perhaps naïve) perspective, the .INI method seems less easy to use. Is there any advantage to the .INI format?

 

Regardless of whether I use the .INI file or a .TXT file, I have this additional problem: One of the things that changes when I install my .EXE file on a new computer is the COM port numbers used by two serial devices.   (On my development computer, the two serial devices use COM5 and COM6, whereas on the two production-flood computers, the COM ports will almost certainly be different).   I suppose I could use the Device Manager on the production-floor computers to change the COM ports to be the same as those on my development computer, but I’d prefer to be able to (again) change the default value of the COM ports in my .EXE.   However, I’m not sure how to do that.   The configuration VIs, have options for reading / writing Booleans, strings, paths, and numeric, but not, (so far as I can tell) for a VISA class.

 

Any thoughts / suggestions are welcome. Thanks.

Message 1 of 10
(7,480 Views)
Solution
Accepted by Dan_the_Clam

Starting from the end, the Visa name is a string, typically "Com1" and you can open a VISA session with a string parameter, so that's not a problem.

Yes you can use normal .txt files, but generally it's alot more sensitive, as hard coded order of keys, capitalization sensitivity and so on. It's also a problem if you want to reuse a key name, i.e. if you use 3 clusters with the same parameters.

 

With an ini file it works like this:

 

[Balance1]  (section)

port=com1 (key name, value)

baudrate=9600

parity=odd

 

[Balance2]  (section)

port=com2 (key name, value)

baudrate=19200

parity=even

 

The ability to read numbers directly with the ini-functions is to save you the step of reading a string and converting it, though it's fairly common if you e.g. loop through all keys and read them all as strings for simplicity in that stage.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 10
(7,471 Views)
Solution
Accepted by Dan_the_Clam
I prefer the ini file as well since the reading/writing is associated with specific sections and keys. The read/write functions do the searching for you.

I don't understand your comment on VISA class. Are you talking about the aliases (Com2, etc.)? If so, they are just stored as strings. A string can be wired to Open VISA Resource with no conversion required.
Message 3 of 10
(7,460 Views)

Thanks for your reply, Yamaeda,

 

Great that I can use a string to open a VISA session - I had no idea.  I'll try that.  

 

And - ah - you are right about the .INI files.  I just did an experiment in which I re-ordered the sections and randomly changed which letters were capitalized in the key values, and the "read configuration settings.VI" still read the file correctly.  Thanks for that.

 

Unfortunately, in my existing code, the controls on the block-diagram aren't all co-located together; they are scattered throughout the block diagram - some of them in case structures and loops.   I suppose that means I'll have to move them all to the left side of the block diagram, route them to these "Write Key.VIs" and then wire them up into the cases and loops with fairly long wires.   It's just a hassle, and is going to make my block diagram more complicated.  Well, I suppose that's how one learns...

 

Thanks again.

dan

0 Kudos
Message 4 of 10
(7,453 Views)

There are also ways to simplify this process. I usually do something along the lines of what's in this example - https://decibel.ni.com/content/docs/DOC-15349


___________________
Try to take over the world!
Message 5 of 10
(7,445 Views)

Thanks, tst.  I've downloaded the LLB and will try that one as well.  It may take me a few days to finish this up, but when I do, I'll post what I've done, just to complete the thread.  Thx.

0 Kudos
Message 6 of 10
(7,428 Views)
Solution
Accepted by Dan_the_Clam

@Dan_the_Clam wrote:

Thanks for your reply, Yamaeda,

 

Great that I can use a string to open a VISA session - I had no idea.  I'll try that.  

 

And - ah - you are right about the .INI files.  I just did an experiment in which I re-ordered the sections and randomly changed which letters were capitalized in the key values, and the "read configuration settings.VI" still read the file correctly.  Thanks for that.

 

Unfortunately, in my existing code, the controls on the block-diagram aren't all co-located together; they are scattered throughout the block diagram - some of them in case structures and loops.   I suppose that means I'll have to move them all to the left side of the block diagram, route them to these "Write Key.VIs" and then wire them up into the cases and loops with fairly long wires.   It's just a hassle, and is going to make my block diagram more complicated.  Well, I suppose that's how one learns...

 

Thanks again.

dan


Assuming you have a state machine and an Init state it's a fair use of Local Variables to update controls from the ini-file. The same goes for saving the values.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 10
(7,374 Views)

I use .ini files a lot, but you may take a look at XML also, for example here: Reference Library for Converting Between LabVIEW and XML Data (GXML)

Nick

0 Kudos
Message 8 of 10
(7,336 Views)

Dennis_Knutson a écrit :
I prefer the ini file as well since the reading/writing is associated with specific sections and keys. The read/write functions do the searching for you.

Me too.

0 Kudos
Message 9 of 10
(7,329 Views)

I changed my VIs to use the configuration files, and it works well.  I used local variables to read the values in, prior to the main loop executing.  For writing, I wired the values directly instead of using local variables.   

 

The method TST recommended might also have worked, and the XML suggested by chembo.   But with limited time available, I went with the .INI and configuration file method and did not try the other techniques.  I may try them later, if I have time and/or a new project to try them out in.  Thanks to all for your replies.

0 Kudos
Message 10 of 10
(7,274 Views)