08-23-2015 11:17 PM
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!
08-24-2015 12:35 AM
See the snippet, please:
08-24-2015 03:16 AM
I'd do something like this:
/Y
08-24-2015 07:05 AM
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
08-24-2015 07:09 AM
OpenG has the Write Panel To INI.vi and Read Panel From INI.vi all ready for you to use. Dirt simple to use.
08-24-2015
09:58 AM
- last edited on
03-25-2024
02:57 PM
by
Content Cleaner
@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!
08-24-2015
10:10 AM
- last edited on
03-25-2024
02:57 PM
by
Content Cleaner
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
08-24-2015 11:25 AM
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?
08-24-2015 01:08 PM
@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.
08-24-2015 01:16 PM
@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!