Building a simple Python example in NWare
In this example, we are going to wire a knob control to a Live Python block. The Python code will display a message when the value of the knob reaches 1.
To add the devices and wire them together
- Add a NION to your project.
- Expand the device tree to display Control / Knobs, Faders Etc. / Generic Controls.
- Drag a Generic Controls device over to the design page.
- Click OK to create a single knob control.
- Open the Controls block, and copy the knob control to the design page.
- Click the knob control to select it, and then press SHIFT+CTRL+M to add a master wiring node.
- Expand the device tree to display Control / Live Python.
- Drag the Live Python folder over to the design page, and then click 1 input - 0 output.
- On the toolbar, click the Wire Mode button to switch to wiring mode.
- Drag the master wiring node on the knob control over to the input wiring node on the Live Python block to wire the devices together.
To add the Python code and test out the project
- Emulate the project.
- Double-click the Live Python block to open it.
- Double-click the Edit button to open the Python source code editor.
- Type the code below into the editor and then save the file.
message.string_set( "" )
if (inputs[0].value_get() == 1):
message.string_set( "Knob value set to 1" )
The code looks at the value received via the input on the Live Python block. If it is equal to 1, a message is displayed in the Message field on the control surface of the device.
- Gesture the knob and watch the control surface on the Live Python device.
While the value stays at 1, the message is displayed. However, if the value of the knob reduces, the message will be hidden.
The link between the devices allows Python code in the Live Python block to monitor the value of the knob control as it is gestured by the user.