LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I make controls save their state when the project is closed?

Solved!
Go to solution

I'm currently working on program for a compact RIO that will be used with a variety of instruments. Some calibration data about each of these instruments needs to be entered into the program via front panel controls so they can output the correct value (for example, the input range and units of a pressure transducer are needed for the program to scale the 4-20 mA reading into a pressure reading).

 

The problem I'm running into is that every time I close the project and open it again, all the calibration controls revert to their default value. What I'd like them to do is save their state every time the program is closed so that if you reopen the project without changing the hardware you don't have to reenter the calibration values. Can anyone tell me how this can be done automatically?

 

I know this can be done manually by telling each control to set the current value to it's default value, but I'd rather not have to do that every time we change the calibration constants. Ideally the user wouldn't have to use right-click menus like that.

0 Kudos
Message 1 of 43
(4,074 Views)

I don't know if there is a method to set the current values to default programmatically, but I suggest saving the control values and properties to file on exit. On startup, load the file and set the values/properties to the control.

0 Kudos
Message 2 of 43
(4,059 Views)

@SLee2004 wrote:

I don't know if there is a method to set the current values to default programmatically, but I suggest saving the control values and properties to file on exit. On startup, load the file and set the values/properties to the control.


This method has the advantage that you can change the values in the file without having to open the VI.  This is especially important if you've made it an executable.  In fact, if the calibration has been saved as a file, you can probably parse that file instead.

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 3 of 43
(4,054 Views)

I'm sure lots of people here have written VIs to grab the value of every control on a front panel and write it to a file on exit, then read the file and restore values on startup. Here's a pair I'm using in a project now. In this case I'm reading every control off a tab page, not the entire front panel, but it would be easy to modify. It doesn't handle every data type but does handle most common ones.

0 Kudos
Message 4 of 43
(4,044 Views)

Well, I tried doing that, but it looks like that would be both extremely complicated (I started doing it for just 3 controls and it's become a mess of wiring) and not actually possible (You can't set the state of a control from the program as far as I can tell, they only accept input from the front panel). It seems like there should be a much simpler way considering that the "Make Current Value Default" option exists. If only I could trigger that option from the program.

 

I'm starting to realize LabView is like every other graphical language I've used: If they've thought of what you want it's as easy as drag-and-drop, but if you want to do something they overlooked it's difficult or impossible due to lack of customizability. In trying to make things simple they make it harder to do complex things. But I suppose there isn't a way to switch to a customizable text-based language here because I'm programming an NI product.

0 Kudos
Message 5 of 43
(4,041 Views)

@DroidFreak wrote:

(You can't set the state of a control from the program as far as I can tell, they only accept input from the front panel).


You can set the state of a control programmatically using a local variable, or a property node. A local variable is more efficient if you know at edit-time which control you want to update; a property node is less efficient but you can pass a reference to it, and set properties other than just the value. Do not use local variables or property nodes as substitutes for wires - for example, if you need the same piece of data in several locations in your code, it will be more efficient and better coding style to wire the data there than to put local variables all over the place.

0 Kudos
Message 6 of 43
(4,035 Views)

"I'm sure lots of people here have written VIs to grab the value of every control on a front panel and write it to a file on exit, then read the file and restore values on startup. Here's a pair I'm using in a project now. In this case I'm reading every control off a tab page, not the entire front panel, but it would be easy to modify. It doesn't handle every data type but does handle most common ones."

 

Ok... I don't understand how these work at all. And I don't understand what to put into the page refnum input. I suppose it's supposed to allow you to choose which tab, but I don't see how to do that.

0 Kudos
Message 7 of 43
(4,021 Views)

I'm sorry for uploading somewhat complex code with little explanation. I don't have time right not to explain it in detail. Here's a small project that demonstrates how you could use those VIs, with a modification so that they look at the entire front panel, not just one panel of a tab control. However, if your user interface does include tabs, it won't get the controls that are part of that tab - to do that, you'll need to make further changes. I'm posting this mostly to demonstrate that what you want to do is possible, if not necessarily immediately apparent to a new LabVIEW user.

0 Kudos
Message 8 of 43
(4,009 Views)

OpenG also has two VIs that do basically the same thing called "Write Panel to INI" and "Read Panel From INI".  It saves the values in the front panel controls to an INI file and then can set their value back given an INI file.  It's under the Variant Config package.

0 Kudos
Message 9 of 43
(3,993 Views)

@DroidFreak wrote:

I'm starting to realize LabView is like every other graphical language I've used: If they've thought of what you want it's as easy as drag-and-drop, but if you want to do something they overlooked it's difficult or impossible due to lack of customizability.


I would scratch the word "graphical" from there. LV is a programming language cobined with a visual UI editor - some things are built in* and some are either not directly built in or require fully custom code - that's what you do with a programming language. You wouldn't expect to know everything about Java immediately and you shouldn't expect to know everything about LV immediately.

 

NI does have CVI, which is a C compiler, but I have no idea if it can compile code to the RT OS running on the cRIO.

 

* And you can actually programmatically set all the values on the FP to have their current value as the default, but that probably won't help you, because you would have to save the VIs for that to persist and you probably can't do that. The examples the others gave are a good way to do this, but they do require you to understand what's going on. There's no going around that.


___________________
Try to take over the world!
0 Kudos
Message 10 of 43
(3,977 Views)