LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Config ini file for serial port number!

Solved!
Go to solution

Hello guys,

 

I am trying to create one config ini file to save the serial port VISA selected. 

I will fit if the file ini doesnt exist then search the serial ports in pc and choose one of them. If the file exist read the value to use when I use the acquisition data.

 

In example attached. I have a event structure (like my app), where I have one bottom to open the setting window 'options'. If you open the main vi and pass the error, open the options subvi and choose comport, if you click 'ok' it save the ini file, if you click 'cancel' it close and show in indicator the value of comport in ini file. The subvi works ok.

 

The problem is when I try to read the value of comport a the begining of application. I have put the code but it is wrong.

I used the 'easy saving and loading of control values' from tst ( https://decibel.ni.com/content/docs/DOC-15349 ) and it works ok for control the subvi.

 

Why I got error and I can not read the value of ini?....  section and key is correct. I dont find the problem.

 

Regards

Fred.

0 Kudos
Message 1 of 9
(6,677 Views)

Your INI file contains a line like "COM port = "\13\00€\00\00\00\00\02\00\1E\007ÿÿÿÿ\00\04\13\00€\00\00\00\00\01\00\04\00\00\00\01\00\00\00\00\00\00\00.@p\00\0E\05Instr\00\01\00\00\13\00€\00\00\00\00\01\00\04\00\00\00\01\00\00\00\00\00\00\08COM port\00\00\01\00\01\00\00\00\04COM3\00\00\00\00"  I would prefer ASCII text in my ini files.

 

there is also a typo of the File constant "options.vi.ni" instead of "options.vi.ini" 

 

try using a constant path instead of the Application directory path, as for me, it resulted in <Not A Path>

 

I would advice to use the OpenG variant config files. Those are at least 'readable'.

 

Good luck! 🙂

0 Kudos
Message 2 of 9
(6,649 Views)

I would also use the OpenG code for this.  Flattening and Unflattening of VISA resources could be doing some weird things that might not work the way you want.  Since you are filling in the drop down, you chould change it be a combo box instead of the VISA control.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 9
(6,637 Views)

Thanks guys,

 

Can you show me any link or example using OpenG for this?.

 

I already change it with file text. It is easier to build. But I am interested in check openG.

 

Regards, Fred.

0 Kudos
Message 4 of 9
(6,609 Views)

I usually save serial com port numbers as a simple string to external config files. WHen I need to open the port I simply typecast the string to the VISA reference then send that to the open port function.

This makes LabVIEW handle all the 'gory stuff' instead of the external config file having to contain more information than might be needed.

It simplifies (for me) keeping info in external ini files.

 

I realize that perhaps this is not terribly robust but it has served me rather well for my 'in-house' applications.

 

 

 

 

 

 

0 Kudos
Message 5 of 9
(6,595 Views)
A VISA resource alias (Com 1) or canonical name (ASRL1::INSTR) can be saved as a string and no type casting is required. The string can be wired directly to a VISA Open or the VISA Configure Serial Port. No need to make it any more difficult.
0 Kudos
Message 6 of 9
(6,589 Views)
Solution
Accepted by topic author Fonsi

OpenG INI example explained on  the-openg-vis-that-i-couldnt-live-without

 

 

0 Kudos
Message 7 of 9
(6,564 Views)

Hi,

 

Kindly explain the flow of execution once it starts. Thanks

 

 

 

Maheboob_0-1721408233209.png

 

0 Kudos
Message 8 of 9
(276 Views)

The VI takes an array of references to controls, uses the first one to get the name of the owning VI, generates an INI file with the name of that VI and saves or loads the values of those controls to or from the file. If you still don't understand it, it might help to run in highlight execution.

 

It's also explained in the link in the original post.

 

By the way, there's a reference leak in that code, because the OwningVI property creates a new reference to the VI every time it's called. That VI reference should be closed after being used.


___________________
Try to take over the world!
0 Kudos
Message 9 of 9
(221 Views)