LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Read array from .ini file

It is possible read a ini file with duplicate names on keys?

 

Example:

menu =first
        subMenu =Temperature "0.5;5;1"
        subMenu = Pressure "0;5;0.4852"
        subMenu = Flow "0;5;1.2350"
        subMenu =Mass "Serial"

 

I always get the same value for all key 'submenu'.

Labiew show me:

[Section]->menu
[key]->      subMenu =Temperature "0.5;5;1"
[key]->      subMenu = Temperature "0.5;5;1"
[key]->      subMenu = Temperature "0.5;5;1"
[key]->      subMenu =Temperature "0.5;5;1"

 

 

Always the same value

0 Kudos
Message 1 of 13
(4,836 Views)

Hi jawier,

 

no, you can't have duplicate keys (with different values) in one section!

One solution would be to keep an index in the key name like submenu01, submenu02, …

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(4,833 Views)
@jawier130 wrote:

It is possible read a ini file with duplicate names on keys?

 

Example:

menu =first
        subMenu =Temperature "0.5;5;1"
        subMenu = Pressure "0;5;0.4852"
        subMenu = Flow "0;5;1.2350"
        subMenu =Mass "Serial"

 

I always get the same value for all key 'submenu'.

Labiew show me:

[Section]->menu
[key]->      subMenu =Temperature "0.5;5;1"
[key]->      subMenu = Temperature "0.5;5;1"
[key]->      subMenu = Temperature "0.5;5;1"
[key]->      subMenu =Temperature "0.5;5;1"

 

 

Always the same value

The ini function will always take the first match, so no. 
What you could do is have a key for Submenu with a list "submenu = temperature, pressure, flow, mass"
Read this list and then read in those keys "Temperature = 0.5;5;1" and so on.
/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 13
(4,828 Views)

Another alternative is to have the section submenu, get the key-list and read all those keys

 

[submenu]

Temperature = "0.5;5;1"
Pressure = "0;5;0.4852"
Flow = "0;5;1.2350"
Mass = "Serial"

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 13
(4,824 Views)

Thanks. But the .ini file is from another manufacturer, and i can not modify it. (I would do it but is very hard mod all files for all machines).

 

 

0 Kudos
Message 5 of 13
(4,779 Views)

Hi jawier,

 

then you need to implement your own parser.

Read the ini file as simple text and use MatchPattern (and similar) functions!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 13
(4,773 Views)

It's possible using the OpenG Read Section Cluster function. The trick is to enclose it in a cluster and to unbundle it after the section cluster is read.Here is an example of how I use it:

In the ini file:

 

[runs-1-2]
data.<size(s)> = "3"
data 0.RunNumber = "1"
data 0.veloc = "60"
data 0.accel = "61"
data 0.targetPos = "3723"
data 1.RunNumber = "2"
data 1.veloc = "60"
data 1.accel = "61"
data 1.targetPos = "-4500"
data 2.RunNumber = "3"
data 2.veloc = "60"
data 2.accel = "61"
data 2.targetPos = "3723"

 

Loading code:

Array in ini file.png

Ben64

 

edit: of course you will need to modify the ini file to fit this pattern, if you can't then you will have to parse the file as already said.

0 Kudos
Message 7 of 13
(4,764 Views)

That doesn't look like a standard config (ini) file.  You probably have to parse it out yourself.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 13
(4,749 Views)

@GerdW wrote:

Hi jawier,

 

no, you can't have duplicate keys (with different values) in one section!

One solution would be to keep an index in the key name like submenu01, submenu02, …


I've seen someone parse this out in a WHILE loop where they started with Test00 and use the [i] in the WHILE loop as a suffix (with leading zero).  The parameters for each test were indexed into an array.  You knew you were done when it couldn't find the key, so you threw out the last element in the array.  That way, you didn't even have to know how many tests there were.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 13
(4,745 Views)

@billko wrote:

@GerdW wrote:

Hi jawier,

 

no, you can't have duplicate keys (with different values) in one section!

One solution would be to keep an index in the key name like submenu01, submenu02, …


I've seen someone parse this out in a WHILE loop where they started with Test00 and use the [i] in the WHILE loop as a suffix (with leading zero).  The parameters for each test were indexed into an array.  You knew you were done when it couldn't find the key, so you threw out the last element in the array.  That way, you didn't even have to know how many tests there were.


I use Get Key Names and then iterate over the keys.  If necessary, I can apply a filter with a FOR loop.


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 10 of 13
(4,723 Views)