LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading irregular blocks from a file.

Solved!
Go to solution

 

I would like to read from a file 1 or more blocks like this:

            An int (this is not absolutely necessary but desired) 

            An array ofints where array size varies by block

            One or moreordered pairs of ints and doubles.

 

The values would then be loaded into TestStand variables.The TestStand Property Loader does not seem appropriate for this but LabViewcan read .ini and other types of files. Preferably the source file would beconstructed by hand and be human readable. If not a construction tool would bethe last resort.

 

I see that data read from Config files must be in pairs. SoI considered converting my int array into a string for storage but the wholestring must fit on one line. This may not be a problem as it seems text filelines can be quite long.

 

Any suggestions?

 

 

thanks,

 

jvh

(An old grey headed text programmer grasping at straws) 

Message Edited by jvh75021 on 03-16-2010 07:06 PM
0 Kudos
Message 1 of 10
(3,586 Views)
Solution
Accepted by jvh75021

you know- I do sometimes use a .ini (or .txt) file like this.......

 

[steps]

Step=State,LLim,ULim,data1,data2,something propriatary3,got the idea?4,

 

[Step_States]

Step_data1=VAR

Step_data2=VAR

Step_Something propriatary3=VAR

......

 

just a sugestion But you could meditate on it... and develop a type def or two  (hint: Var>str then Str>flattened keeps VAR properties)

Message Edited by Jeff Bohrer on 03-16-2010 07:56 PM

"Should be" isn't "Is" -Jay
Message 2 of 10
(3,575 Views)

Why do you say "that data read from Config files must be in pairs"?

 

The whole block must be on one line?  Why not define your own text file protocol.  Let a carriage return/line feed define the end of the line and separation between blocks.  Use other characters as markers and delimiters within your line of text.  Tabs, pipe symbols "|", commas, other stuff could be used to separate the various sections.

 

Integer# tab Size of array Pipe each array element as a number separated by commas Pipe Numer of ordered pairs, pairs are separated by tabs commas separate the two numbers in each pair.

 

Knowing your own protocol, you could read in a line, parse it for the key characters and break it up into the various numbers.  Then repeat for the next line which is your next block.

Message 3 of 10
(3,573 Views)

RF- Better detail than I.  Better abstaction as well- Kudos

 

Smiley Very Happy 


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 10
(3,571 Views)

 

Thanks for posting Ravens Fan.
I should have stated my goal. That would be to have an array of containers in TestStand, wherein the container has an index and an associated frequency (and maybe a string). This array would be accessed by a FOR EACH to run a set of subsequences in a set order. The array of ints was to have the indexes in order of running since they are not sequential. However if I can be sure the containers are loaded in order and FOR EACHed in order I do not need the int array. Perhaps I am being too wary here. In C/C++ I am sure of my orders, with scripting languages like Tcl you can't bet on the order. Hopefully LV and TS are more like C in this regard.
Why do you say "that data read from Config files must be in pairs"
Per LabView help: To use the Configuration File VIs, you must format each line of text in an .ini file correctly. A line must either be empty or contain a section name, a key-value pair, or a comment. 

 

The whole block must be on one line?

 

I said the whole string must be on one line, again per the help file: Keep all the characters on one line. 

 

 Why not define your own text file protocol? Had considered it but I am quite inexperienced with TestStand so I was trying to use built in concepts like config files or Property loader.

 

I appreciate what you say. Maybe after a couple more cups of coffee comprehension may start to ooze into my thick skull.

 

 

Thanks again,

 

jvh 

 

 

0 Kudos
Message 5 of 10
(3,552 Views)
Thanks for posting Jeff.
Again what I read in LV help:A line must either be empty or contain a section name, a key-value pair, or a comment. So your statement "Step=State,LLim,ULim,data1,data2,something propriatary3,got the idea?4" seems to violate the rule.

Jeff Bohrer wrote:

you know- I do sometimes use a .ini (or .txt) file like this.......

 

[steps]

Step=State,LLim,ULim,data1,data2,something propriatary3,got the idea?4,

 

[Step_States]

Step_data1=VAR

Step_data2=VAR

Step_Something propriatary3=VAR

 

 

Pardon my density but not sure I follow "Var>str then Str>flattened".

 

Thanks again,

 

jvh 

 


 

0 Kudos
Message 6 of 10
(3,550 Views)

 

[steps]

Step=State,LLim,ULim,data1,data2,something propriatary3,got the idea?4,

 

OK it looks like this is legal because by config file rules there is only one item on the right side of the "=". So now it need to be broken apart somehow? Is that correct? (The commas caught my eye but not my mind...) 

 

0 Kudos
Message 7 of 10
(3,543 Views)

One thing to keep in mind with configuration files is that key values are limited in length if someone else has to read them outside of LabVIEW and use the Windows functions to do it. The standard Windows API functions have limitations of 256 characters for key values.

 

LabVIEW doesn't have this issue since it doesn't use the Windows functions, but you mentioned TestStand...

Message 8 of 10
(3,519 Views)

jvh75021 wrote:

 

[steps]

Step=State,LLim,ULim,data1,data2,something propriatary3,got the idea?4,

 

OK it looks like this is legal because by config file rules there is only one item on the right side of the "=". So now it need to be broken apart somehow? Is that correct? (The commas caught my eye but not my mind...) 

 


Exactly, Commas are a useful delimiter to use in interperating the "value" 

 

Here is a code snippet elaborating on varient data and how to get it in a .ini file.  Flattening.png

As you can see the top function, "Varient to Flattened string", can be used to cast anything to a string however, not all of the properties of the varient type in the cluster are preserved.  (In fact, only the VISA Alias is contained in the top string)

 

However casting the cluster to a varient and using "Flatten to String" gives us a much larger output.  Why?  Easy the varient type (VISA Resource) attributes are also contained in the output.

Message Edited by Jeff Bohrer on 03-17-2010 09:38 AM

"Should be" isn't "Is" -Jay
Message 9 of 10
(3,512 Views)

Thanks Jeff I will keep this for future use.  But the dark forces here are insistent that the .ini or .txt file be human readable so that the "users" can modify limits and add or delete index/frequency blocks.

 

So I am going to persue the option of  step=string,llim,ulim,mylim,outOnALim for now a perhaps mix in some | separators.

 

Best Regards,

 

jh 

0 Kudos
Message 10 of 10
(3,504 Views)