LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use settings with a state machine?

I have a "classic" data acquisition program that acquires voltages from different sensors. Each DAQ read subvi has some settings for the scale, range of voltage etc.; additionally I have set a certain buffer size, sampling rate etc.
I would like to show on the front panel only the start, stop type of buttons, file name and charts, and 'hide' the settings in a subvi. I already built the subvi but now the problem is how to hide it and how to call it through a "settings" button whenever I want to change something. I tried this using New events handler (using events in a while loop); the problem is when I start the program, the settings in the application do not take the settings in the subvi, they all go to 0 (I used shift registers). I started to wonder if this is a good approach or what could I do to make the settings available right from the start.
Did anybody have the same problems and could give me some suggestions and an example?
 
Thank you. 
0 Kudos
Message 1 of 9
(3,540 Views)
Hello,
 
Attached is an example to help you get started.  The popup VI in the event structure is called and shows it's front panel when called because of the subVI node setup (right click to check this) - the instance of the subVI outside the loop, which initializes the shift register, does not pop up because it's subVI node setup is not set that way. 
 
If you run the example and study the code, you'll find comments in the code to help you understand the behavior.
 
I hope this helps!
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 2 of 9
(3,521 Views)

OK. I think I did something similar but now, after you stop the application and then restart it, you get the initial, old values, not the new values that you input before stop. In other words, your settings will always be initialized with fixed values from the subvi that doesn't pop up and I don't want this. I want them to be the ones that i last picked when I updated the settings...

Any other suggestions?

Thank you for your time and will to help

0 Kudos
Message 3 of 9
(3,511 Views)

If you are running the program in LabVIEW, you can use an invoke node on the subVI to "Make Current Values Default" and then save the subVI.

If you are running an executable, the easiest way is to save and load the settings in some kind of file (.ini files work well since there are good VIs for reading and writing these). Make Current Values Default only works on an executable until it is removed from memory. When reloaded from disk, it will come up with what the settings were at the time that the executable was compiled.

     Rob

0 Kudos
Message 4 of 9
(3,501 Views)

Thank you Rob.

I think you are pretty close to the answer...

Nevertheless, I do not want some default values to be always available for the vi. I want the current settings to become 'default' or the settings for the next time I open that main vi.

Maybe this is what you said already but I did not understand. Would you have a simple example to show me?

Thanks a lot.

0 Kudos
Message 5 of 9
(3,485 Views)
If your settings are inside a cluster, you could flatten that into a binary string, and write it to disk in your last state. Then open this file in your initialize state.
0 Kudos
Message 6 of 9
(3,469 Views)

Thank you UncleBump (I enjoyed the name by the way).

I do have the settings in a cluster but I do not know how to do this:"you could flatten that into a binary string, and write it to disk in your last state. Then open this file in your initialize state." Sorry, would you have an example?

Meanwhile I came up with this solution: I have the cluster with settings in an event structure window; I made an indicator (that I hide) of the cluster in that window and then a global variable for that indicator. Then, I put the global variable outside the state machine to initialize the 'loop'. I also put shift registers on the while loop that includes the event structure. Thus, when I upgrade the settings they upgrade also in the initializing global variable. It appears this works. Every time I open the program I have the latest settings available and if I change any setting it imediatly becomes available to the acquire program from adjacent event case due to shift registers, and updates the initializing variable also. I still need to test this better... Do you see any problem?

Would this work in an executable? I would have to try but if you know the answer, please, let me know.

Thank you.

0 Kudos
Message 7 of 9
(3,460 Views)

Try changing your settings and when you stop the program, quit LabVIEW. Restart LabVIEW and see if the changed settings were remembered. If you did not save your VI after you changed the settings then they will not be remembered. The same is true for an executable. You can not write to the executable.

I think that the easiest is for the settings to come from outside the program (a separate file). I have included one of my early test VIs for this.

     Rob

0 Kudos
Message 8 of 9
(3,448 Views)

Thank you Rob. It's a start.

unfortunately it looks kinda complicated for me now. I'll take a closer look...maybe my mind will open...

Thanks

0 Kudos
Message 9 of 9
(3,439 Views)