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

  1. Add a NION to your project.
  2. Expand the device tree to display Control / Knobs, Faders Etc. / Generic Controls.
  3. Drag a Generic Controls device over to the design page.
  4. Click OK to create a single knob control.
  5. Open the Controls block, and copy the knob control to the design page.
  6. Click the knob control to select it, and then press SHIFT+CTRL+M to add a master wiring node.
  7. Expand the device tree to display Control / Live Python.
  8. Drag the Live Python folder over to the design page, and then click 1 input - 0 output.
  9. On the toolbar, click the Wire Mode button to switch to wiring mode.
  10. 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

  1. Emulate the project.
  2. Double-click the Live Python block to open it.
  3. Double-click the Edit button to open the Python source code editor.
  4. 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.

  5. 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.

See also

Introduction

Changing Python code while a project is running

Debugging Python scripts

An example with multiple input devices

Building an example that processes both inputs and outputs