LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I combine a ton of strings into an object so that it's easy to have all of them at hand?

Hi, so I have a Labview program that's controlling a couple of machines and naturally it has about a million variables that I set with controls before I run the experiment. I'd like to write these variables to a text file that would accompany the data file, and be like something of the form:

 

var1: someval1
var2: anotherval2
...

And so on. I know how to write to text files, so my naive way of doing this would be to just build a big array of all the variable names and their values, and then write that to a text file, but since there are ~50 variables, that would require an unholy rats' nest of wires in my block diagram from the string controls for each variable to the array.

 

So I'm guessing there's a more elegant way to do it, it being Labview. If this were another language I'd do something like have some sort of global object that I could add variables and their value to, and then just reference later and dump all the entries into the text file. Is there some sort of thing I can do like that in Labview?

 

thanks!

0 Kudos
Message 1 of 15
(4,091 Views)

See the snippet, please:

Get references.png

0 Kudos
Message 2 of 15
(4,056 Views)

I'd do something like this:

Ini file.png

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 15
(3,998 Views)

It sounds like you are talking about a Configuration File, something that you read once at the start of the Program, and that remains relatively constant (that is, you aren't adding new elements to be read, nor are you making daily changes to the Configuration).

 

We had a related situation -- we're running behavior tests, with multiple trials, each having over a hundred (mostly numeric) parameters.  We decided on using an Excel Worksheet to hold the variables (with Row 1 being the name of the Variable, and rows 2 .. whatever being the values for each Trial).

 

In the original version of this routine, we had a Worksheet that "mapped" each Variable, by name, to the corresponding Excel column on the Trials Worksheet.  It also gave the Type (Integer, Dbl, Boolean, String) of each element.  I won't go into the nightmare of having arrays for String Variables, Dbls, etc., indexed (I think -- who remembers?) with a TypeDef naming the corresponding LabVIEW variable -- suffice to say it was a mess.

 

We now have a LabVIEW Cluster corresponding to the Trial.  Each element of the Cluster is one of the LabVIEW variables, and has whatever is the appropriate Type.  To access, for example, the Pulse Width, we just "unbundle by name" our Cluster and specify Pulse Width.

 

One (minor) drawback to this scheme is that "nothing is static" -- we are on the fourth Version of this "new" version of the code, each requiring more Excel columns, hence a new LabVIEW Cluster.  We've designed the code to be "backward compatible" -- if a variable, say "Pulse Width", is not defined in Version 2.1 (and we are coding Version 2.3), we assign a suitable "default value" to it in the Cluster.

 

You might find that using a Cluster in this way to hold all of your Configuration data makes it easier to conceptualize and handle a collection of 50 or more related Experiment Variables, particularly if they are of inherently mixed type (numeric, string, boolean).  You do have to do Type conversion when you read it in, but you do that once, can "hide" the messy details in a sub-VI, then you are done.

 

Bob Schor

0 Kudos
Message 4 of 15
(3,952 Views)

OpenG has the Write Panel To INI.vi and Read Panel From INI.vi all ready for you to use.  Dirt simple to use.


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
Message 5 of 15
(3,948 Views)

@crossrulz wrote:

OpenG has the Write Panel To INI.vi and Read Panel From INI.vi all ready for you to use.  Dirt simple to use.


Ah, interesting, I hadn't heard of it. You mean this, right? https://www.ni.com/en/support/downloads/tools-network/download.openg-libraries-for-labview.html

 

I have one worry -- since it's open source, if I upgrade my Labview version, could it possibly break something there? Or is that just really unlikely.

 

thanks!

0 Kudos
Message 6 of 15
(3,917 Views)

optoelectro wrote:

Ah, interesting, I hadn't heard of it. You mean this, right? https://www.ni.com/en/support/downloads/tools-network/download.openg-libraries-for-labview.html

 I have one worry -- since it's open source, if I upgrade my Labview version, could it possibly break something there? Or is that just really unlikely.

 thanks!


At worst the tool will break, but since it's open source you can open it and fix it.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 15
(3,902 Views)

Hi Yamaeda, thanks for the response. I like your example, but I'm confused about a couple parts of it.

 

I haven't used references before so I'm a little unsure of it. In your example, those references (going to the build array) aren't actually attached to the variables, right? They're just placeholders, I assume.

 

So if I wanted to make references for those variables, would I right click on the variable in the block diagram->create->reference, and that'd be what I use?

 

Okay, I think I've got that. Now I'm trying to make a subVI that will basically let me just pass it an array of references of some type and the refnum for the config file, but it's driving me nuts.

 

The first problem is that when I create a Property Node in the loop (as you have) and choose the properties to be Label.Text and Value, when I try and string the Value field up to the 'Value' input of the Write to Config File VI, it says "These cannot be wired together because their data types do not match. The type of the source is Variant. The type of the sink is boolean (TRUE or FALSE)."

 

I know what this error means, but how can I get around that? It has no trouble writing doubles to the config file when it's expecting them, and same with strings obviously, but apparently it freaks out when it doesn't know to begin with what type of variable it'll be.

 

My second problem is figuring out how to make the Config file refnum an input for this subVI. Normally I'd just create a Control and then wire that to one of the input ports in the Front Panel, but I can't figure out for the life of me where to get a refnum for Config files. I tried wiring several types of reference controls to the input of the Write to Config File VI but it keeps saying "the type of sink is typedef 'config data refnum.ctl' datalog file reference of."

 

So I'm assuming I need to load/make some sort of typedef to use that as an input?

 

 

0 Kudos
Message 8 of 15
(3,884 Views)

@optoelectro wrote:

I haven't used references before so I'm a little unsure of it. In your example, those references (going to the build array) aren't actually attached to the variables, right? They're just placeholders, I assume.


No.  They are actual references to the controls/indicators on the front panel.  With these references, you can do all kinds of things like set font colors, set the value, etc.

 

I recommend you get "variable" out of your vocabulary when it comes to LabVIEW since it is not the same as a variable in a text based language.

 


optoelectro wrote:

My second problem is figuring out how to make the Config file refnum an input for this subVI. Normally I'd just create a Control and then wire that to one of the input ports in the Front Panel, but I can't figure out for the life of me where to get a refnum for Config files.


The simple way is to just right-click on the config file reference input of one of the config file VIs and choose Create->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 9 of 15
(3,854 Views)

@crossrulz wrote:

@optoelectro wrote:

I haven't used references before so I'm a little unsure of it. In your example, those references (going to the build array) aren't actually attached to the variables, right? They're just placeholders, I assume.


No.  They are actual references to the controls/indicators on the front panel.  With these references, you can do all kinds of things like set font colors, set the value, etc.

 

I recommend you get "variable" out of your vocabulary when it comes to LabVIEW since it is not the same as a variable in a text based language.

 


optoelectro wrote:

My second problem is figuring out how to make the Config file refnum an input for this subVI. Normally I'd just create a Control and then wire that to one of the input ports in the Front Panel, but I can't figure out for the life of me where to get a refnum for Config files.


The simple way is to just right-click on the config file reference input of one of the config file VIs and choose Create->Control.


Ah, in the first thing you quoted, I was referring to his VI where his references actually weren't connected to the controls.

 

Awesome, I didn't know about creating controls from the VI inputs, that's really useful, thank you!

 

Do you know if it's possible to have the property node value connect to the value input of the Write to Config File VI if I haven't defined the type of property node?

 

thank you very much!

0 Kudos
Message 10 of 15
(3,848 Views)