LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to understand how to apply LV2 Globals to the UI


I've been trying to improve my programs by getting away from using Local Variables and replacing them with LV2 Style Globals.  

For the most basic of operations, I think I understand their use.  But sometimes I need to write to a control, or maybe make it invisible or disabled.  In the past my UI would run in it's own loop right on the main VI and I would use Local Variables and Property nodes in State Machine loop also in the main VI to change values, and properties at various points in the program.  

I'd hoped that using LV2 Style Globals that I could really clean up my main VI's block diagram by moving the UI to it's own VI that could be dynamically called from the State Machine.  So far, this works....if I only need to read from controls and write to indicators.  But now I'm stuck on a good way to write to controls and adjust their properties if needed.  

Maybe I'm still envisioning things wrong, and there really isn't a "good" way of what I'm trying to do because it's inherently a bad programming practice.  I'm not really sure.  

A typical example would be a "Log In" Boolean on the UI.  The State Machine would wait until it saw a True value on the "Log In" Boolean, and then it would exit that state and perhaps make a previously invisible button visible, as well as then set the "Log In" Boolean back to the false state.  

I know that I could change the Mechanical Action of the "Log In" Boolean to "latch when pressed" so that it would return to the false state on its own.  But then I'm worried that it might be possible to miss the button press.  I'm also unsure of how I can adjust the properties of a boolean in another VI.  I tried creating a reference and writing to the property node in my State Machine, but that didn't work.  

I'm wondering if it's even possible to do what I'm thinking.  Or if it would end up being such a bad practice that I may as well stick with the way I'm doing it now.  

Any feedback would be greatly appreciated. 
---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 1 of 7
(2,833 Views)
Hello,

Why not use the event structure to handle events on the UI. Polling the control costs processing time, the event structure when not using the time out case does nothing unitl an event occurs.

Hiding property settings and other operation on a particular control in a LV2 style global (when using an enum  you can add numerous operations on the control in question).

Kind regards,

André

Regards,
André (CLA, CLED)
Message 2 of 7
(2,821 Views)
I'm still not completely familiar with using the Event Structure for polling the UI.  It's something I'm working on.

As far as "hiding the property settings and other controls" in the LV2 Global; I'm not really sure how to do that.  (Hence my post) 

I understand using an Enum to set the "mode" of an LV2 Global.  This is how I'm able to write to it in one VI and read it in another.  I've thought about creating another mode for setting properties.  But so far I've not been able to come up with anything that would work. 
---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 3 of 7
(2,819 Views)
First of all the beauty of the event structure is that it doesn't poll the UI elements.

Add a Boolean control to a frontpanel. Put an event structure inside a while loop on the block diagram.

Add an event case in the event structure and select the boolean. Browse down to the value change event and press OK.

Now you've added an event case to catch a value change of the Boolean control. Make sure its latched.

Create a reference for the Boolean control and create a control thereof. Copy the control to a LV2 Global frontpanel and hoop it up to the connector pane.
Now you can wire the reference of the Boolean control to the Lv2 Global and use property node and invoke node on the reference, to e.g. change its boolean text on each press.

I hope this helps.

Post some code, so we can review it and give some pointers.

Kind regards,

André
Regards,
André (CLA, CLED)
Message 4 of 7
(2,803 Views)

You can create an Action Engine that has states like.

Init - Cache reference to controls on FP in a shift register. All future calls to the AE will act on these references.

     - Set visability of controls using an array of booleans to set visable/no.

 

Set Login - Shows "Enter" button and hides "Login" button.

SHow Privledged - Shows controls only accessable by supervisors

This AE can then becalled by the rest of your code when required using the approiate state (Add more if to suit your needs).

If that AE also kept track of all its settings in a history, then actions like

Back - Pops a state of the stack and restores the previous screen configuration.

 

If you need to get at control specific properties of controls via control references froma sub-VI (phew) then use the "More SPecific" operator to cast the control reference to the target type. Note: Good idea to check the return value from the "More Specific" operator to make sure you are acting on the proper type.

Please start a new thread for the Event structure question.

Have fun,

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 7
(2,801 Views)
Thanks for you reply Andre,

I was playing a little with the Event Structure again yesterday and I think it would probably be a very good exercise for me to create a piece of code as you describe.  I'll give it a shot and post what I come up with.


Regards,
---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 6 of 7
(2,772 Views)
Thanks Ben,

I think I found some references to the Action Engine post yesterday when I was searching the boards for information.  Although on first read it seemed to be a little "over my head".  I'll pick though it a little more closely and see if I can create something here.  It certainly sounds like exactly what I'm looking for.


Regards,

---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 7 of 7
(2,768 Views)