Example Code

Programmatically Controlling One VI's Front Panel from Another Using VI Server

Code and Documents

Attachment

These VIs demonstrate the use of VI Server to control the front panel objects of one VI from another. Run the Master.vi, and it will (in turn) run the Slave.vi. You can then use the controls on the front panel of the Master.vi to change the controls on the front panel of the Slave.vi.

Master.vi
Master.vi uses VI Server to open another VI (Slave.vi) that is located in the same directory. The Property Node makes sure that Slave.vi's front panel is visible, while the first Invoke Node runs the VI (like calling a subVI), but with the "Wait until done" set to False, it will run independently of Master.vi. However, Master.vi can programmatically update the values of the controls on Slave.vi's front panel.

The Case Structure inside the While Loop is optional. It is included so that the programmatic control of Slave.vi's front panel can be turned on and off. The four Invoke Nodes within the True case affect the correspondingly named controls on Slave.vi's front panel. It is critical that the Control Name input be an exact match for the name of the control on the other VI's front panel. The Flatten to String functions are used to flatten the data for the Type Descriptor and Flattened Data inputs.

The Close VI Reference on the outside of the While Loop ends the VI Server session. Please note that, even after Master.vi stops, Slave.vi will continue to run until
its own Stop button is pushed.

Slave.vi
Slave.vi has four front panel controls (two digital controls and two boolean buttons), a chart that displays the current values of the digital controls, and two LEDs that indicate the current values of the boolean buttons. A 250 ms delay in Slave.vi's While Loop is optional, but makes it easier to notice changes in the controls.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors