From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the right way to have variables controlled by both buttons and programmatically?

Solved!
Go to solution

First of all, I apologize if this has been discussed before.  I am not sure how to succinctly phrase the request, so maybe I just missed the search terms.

 

We have several pieces of Labview software in the lab that control things like valves and heaters automatically.  Sometimes we also need to manually control these same things.  I am in the process of switching us from old NI PCI boards (and old versions of Labview) to a system based on compactRIO and network shared variables.  However, I am still not sure about the best practice for doing this.  I need to be able to have a control panel script running at all times so that I can access, for example, a valve controller (which is just a boolean), and I need to be able to open and close the valve programatically from other scripts.  I need, of course, the control panel to keep track of the state of the valve so that if another script opens it, the control panel shows that it is open, and the next push on the control panel will close it.

 

Historically, this has been dealt with using case structures to switch between "computer control" and "manual control" with global variables that define the states of the valves.  This is obviously not best practice.


So far, I have been playing with using two variables, one for valve status and one for button status.  The control panel then loops, reads the valve status, and changes the button status if the valve status has changed.  I can do this with shift registers or with event structures, but either way it also becomes very cluttered and seems inefficient.  Is there a right way to do this in Labview?  It seems like it would be a common problem, so I am hoping there is an easy, elegant solution that I have just missed.

0 Kudos
Message 1 of 3
(2,160 Views)
Solution
Accepted by topic author stephencox

Use network published shared variables.  Your script and your manual interface and edit the shared variable and then your cRIO just reads the value and writes the appropriate values out.

 

Now for a cool part.  On your manual interface, right-click on your cotrol that you want to use to control the shared variable and go to properties.  There should be a Data Binding tab in the properties dialog.  You can link a control/indicator to a network published shared variable.  So that button will always be set to the current state.

 

Your script should just read the shared variable before resuming to verify it is in the right state.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 3
(2,146 Views)

Awesome!  That sounds like exactly what I knew had to exist but could not figure out.  I can't wait to be able to take the machine offline and implement it.

0 Kudos
Message 3 of 3
(2,111 Views)