LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you create an array without using a shell on the FP?

I want to be able to read the status of front panel controls (value, control box selection, etc.) and save it to a file, as a "configuration" file -- then be able to load it and have all the controls set to the same states as were saved in the file. I was thinking an array would be a way to do this, as I have done that in VB. (Saving it as a text file, then reading lines back into the array when the file is read and point the control(s) values/states to the corresponding array element.

So how do I create an array of X dimensions without using a shell on the front panel? Or can someone suggest a better way to accomplish what I am after? (Datalogging doesn't allow for saving the status by a filename, so I
do not want to go that route.)
0 Kudos
Message 1 of 16
(3,629 Views)
One of the easiest ways I have found to save multiple controls to disk is to bundle them, flatten the cluster to XML, then write the flattened data to an XML file. To restore your variables, you feed that same (empty) data type/bundle into the VI that reads the XML from disk, then unbundle the output data in the same order and write it back to your controls.

Three tips:

To add more items you want to save to disk, just increase the bundle size and wire them in.

Here is where the XML VI's are located.
Advanced > Data Manipulation > XML

You will need to select the polymorphic instance of the XML read from disk.vi in order for it to output a string instead of an array.

I have attached a screenshot which would really be broken down into two sub
VI's with a common cluster.
Message 2 of 16
(3,629 Views)
Instead of using an array, you could use the configuration file vi's to save
the value of front panel controls. The OpenG toolkit also has configuration
file vi's which, among other things, allow you to save all the controls on
the front panel at once. See
http://openg.org/tiki/tiki-index.php?page=OpenG+Lib%3A+Variant+Configuration
+File+IO The documentation doesn't provide a lot of explanation, but it is
worth downloading and installing.


"GregM" wrote in message
news:50650000000800000057FF0000-1079395200000@exchange.ni.com...
> I want to be able to read the status of front panel controls (value,
> control box selection, etc.) and save it to a file, as a
> "configuration" file -- then be able to load it and have all the
> controls set to the same s
tates as were saved in the file. I was
> thinking an array would be a way to do this, as I have done that in
> VB. (Saving it as a text file, then reading lines back into the array
> when the file is read and point the control(s) values/states to the
> corresponding array element.
Message 3 of 16
(3,456 Views)
m3nth and DD - Thanks so much for the suggestions. I am going to look at what you both suggested -- although the link to the OpenG Toolkit may not be correct -- it leads me to a "page cannot be found". No matter, I know what to look for and feel sure I can find it.

I'm a relative newbie to LabVIEW (couple of months). In addition, I'm not a formally trained programmer. What I know I've learned on my own using books and just diving into small project of utilities, etc. for myself with Basic(predating VB) and VB.

Strangely, I find LabVIEW almost counter-intuitive when you've come from non-graphical programming. In a way, the physical icons conflict with MY mental images and organization when programming. It might be more efficient once you've "learn
ed" the icons and the functions they represent but they need to be learned just like you have to learn keywords and commands in text-based programming.

Anyway, thanks to you both. I am using this one comment to reply to both of you -- seems like there ought to be one more button on these forum commands: "Post a general comment" so that you can make one reply to thank others. (Just as I was about to submit this the forum was suspended for maintenance.)
0 Kudos
Message 4 of 16
(3,629 Views)
The button you seek is the one that answers your own question (Answer This Question)--it will create a new post in the thread that is not a comment in response to what someone else posted.

The idea of using the control values from the FP was intriguing... I threw together an example of how to do that. In conjunction with the XML save/restore routines I already posted, this would allow you to not have to use bundling and local variables to save/restore your front panel controls. This would also be especially convenient if you just wanted to do all of them and not be selective.

The top half of this example would be if you wanted to selectively save and restore control values... you would put the name of the control into the array.

The
bottom half is if you wanted to save and restore all control values.

In between the left and right halves you would have to have save-to-disk routines such as the XML ones I posted earlier.
0 Kudos
Message 5 of 16
(3,629 Views)
Thanks so much m3nth! This definitely looks like what I was wanting... just not really knowing how to get there.

I'm not sure I follow all the icons. Is that an array (top left with 0 constant) in the top example? And if so, that gets back to part of my original question of how to create an array without using a shell on the FP. Do I follow your diagram correctly?

If I seem a tad green... well I am. 🙂

I hope you understand the LabVIEW environment and icons are still very new to me.

Also, I had a response from an NI app. engineer about this problem. He sent me a couple of VI's that he threw together approaching this by using Keys. (I still think you are pointing to the best solution.) I assume he wouldn't mind m
e posting his reply and the VI's for the sake of a good, thorough, Roundtable discussion. So here are his comments with VI's attached:

"I was implementing this exact functionality this morning for an application I'm working on. I only have five controls I want to save, but they are all of different data types. I simply wrote a key for each control, and read back that key on initialization. I simply passed in property node values to the save VI at the end, and passed the values out to property nodes at
the beginning. I've attached my initialize and save VI's for you to view. If you have so many controls that this would not be feasible, you may want to look into clustering the controls and saving the cluster as a datalog file.
Download All
0 Kudos
Message 6 of 16
(3,629 Views)
Perhaps the reason you find LV counter-intuitive is that is uses a data-flow paradigm while most text based languages use control flow. Data flow means that the order of execution is determined by the availability of data, not the sequence in which the commands were written.

Check tutorials or search for data flow to help you get started. It is very different. It can be quite powerful, but it is definitely a change from the other way of thinking.

Lynn
0 Kudos
Message 7 of 16
(3,456 Views)
First of all, the two examples you posted will work. That's how I used to save things. Doing things that way also falls into one of the most miserable time-consuming experiences I have ever had also. It's not very flexible and very difficult to change later.

To make an array constant drag an empty array constant to the BD then an empty string constant, then drag the string into the array and resize it. After that you can edit the array items.

To programmatically make an array you would want to wire data into the Build Array terminal, which is expandable, and would output an array. On my BD array menu it's over one down one from the top left. The advantage of this is wiring a control into an ar
ray, instead of just a constant.

What version of LabVIEW are you using?
Download All
0 Kudos
Message 8 of 16
(3,629 Views)
A note about configuration file VI's is that you probably don't want to use them if you don't have to, and the circumstances in which you want to use them will be mainly when you want to give a power user easy access to change the settings of a compiled program without touching the code. In that specific case, using the configuration file VI's becomes extremely intuitive for changing a few programmatic settings. Saving data however is probably best done using other means that make it easier to modify what's being saved at some later point, if the program changes.
0 Kudos
Message 9 of 16
(3,456 Views)
I'm using LV 7.1.

Yes, what you proposed is much more what I had in mind...it's looks like the implementation of what I had in mind. I just didn't have a clue how to get there in LV. I could sense that the "Key" idea was more convoluted. And it wasn't clear that that can be done on the fly with the VI running... I don't know enough yet to know that answer.

Complexity is what I'd been running up against in my attempts to do this -- it started becoming too specific and to cluttered.

Thanks for the directions on creating an array. I had tried the "Build Array" but I guess because I still know so little about the functions/icons I wasn't able to successfully complete what I'd set out to do.

I've been working wit
h your idea and have a couple of questions: First, what is the constant to the left of "Open FP Reference"? And second, I've invoked a Front Panel Node but can't seem to find "Get Control Vlue", "Control Name", etc. among the items listed. Are these user modifiable from the Invoke Node icon?
0 Kudos
Message 10 of 16
(3,629 Views)