An example with multiple input devices

In this example, we will see see how to work with the values of multiple controls wired to the inputs on the Live Python block.

By default, a Live Python block is configured to monitor all the inputs, and run the Python code inside the block as soon as an input value changes. This is the behavior that we want for this example, so we will leave the property (watch input) set to any on the device properties.

To set up a Live Python block with multiple input devices

  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. On the Controls Properties dialogs box, in the Number of controls box, click 3.
  5. Click OK.
  6. Open the Controls block, and copy the knob controls to the design page.
  7. Drag a selection box around the knob controls, and then press SHIFT+CTRL+M to add master wiring nodes.
  8. Drag the Live Python folder over to the design page, and then click 3 input - 0 output.
  9. On the toolbar, click the Wire Mode button to switch to wiring mode.
  10. Wire all three knob controls to the inputs of the Live Python block.

  11. Emulate the project.
  12. Double-click the Edit button to open the Python source code editor.
  13. Type the following Python code in the editor:

    total=0

    average=0

    for x in range(len(inputs)):

        total += inputs[x].value_get()

    average=round(total/len(inputs),3)

    message.string_set("The average of the input values is " + str( average ))

  14. Save the Python code.
  15. Gesture the knobs.

    The message on the control surface of the Live Python block will show the average of the knob values.

See also

Introduction

Building a simple Python example in NWare

Changing Python code while a project is running

Debugging Python scripts

Building an example that processes both inputs and outputs