Use Python to control the digital I/O ports

The dio Python module allows you to control the device's digital I/O ports.

Return information about digital I/O ports

  1. Select a device in Remote Manager that is configured to allow shell access to the admin user, and click Actions > Open Console. Alternatively, log into the IX30 local command line as a user with shell access.

    Depending on your device configuration, you may be presented with an Access selection menu. Type shell to access the device shell.

  2. At the shell prompt, use the python command with no parameters to enter an interactive Python session:

    # python
    Python 3.10.1 (main, Mar 30 2023, 23:47:13) [GCC 11.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

  3. Import the dio module and the Name class:
    >>> from digidevice import dio
    >>> from digidevice.dio import Name
    >>>

    The Name class uses the following naming:

    • Digital I/O port 1: Name.dio1

    • Digital I/O port 2: Name.dio2

    • Digital I/O port 3: Name.dio3

    • Digital I/O port 4: Name.dio4

  4. To determine the direction of a digital I/O port, use the get_direction function:
    >>> dio.get_direction(Name.dio1)
    <Direction.input: 'IN'>

    Returns either:

    • Direction.input: IN: The direction is input.

    • Direction.output: OUT: The direction is output.

  5. To determine the whether a digital I/O port is set to active-low or active-high, use the get_input function:
    >>> dio.get_input(Name.dio1)
    <State.on: '1'>

    Returns either:

    • State.off: 0: The port is set to active-low.

    • State.on: 1: The port is set to active-high.

  6. To determine the current output state of a digital I/O output port, use the get_output function:
    >>> dio.get_output(Name.dio1)
    <State.on: '1'>

    Returns either:

    • State.off: 0: The current output state is off.

    • State.on: 1: The current output state is on.

    • If the port direction is input, an error is returned.

  7. To determine whether the pulse counter of a digital I/O input port is enabled, use the get_pulse function. This function is available for Digital I/O port 1 only.
    >>> dio.get_pulse(Name.dio1)
    0

    Returns 0 if the pulse counter is enabled. If the pulse counter is not enabled, the following error is returned:

    digidevice.dio.DIOException: Pulse counter is not enabled on port Name.dio1
  8. Use Ctrl-D to exit the Python session. You can also exit the session using exit() or quit().

Set the state of a digital I/O output port

If the direction of a digital I/O port is set to output, you can set the current state of the port:

  1. Select a device in Remote Manager that is configured to allow shell access to the admin user, and click Actions > Open Console. Alternatively, log into the IX30 local command line as a user with shell access.

    Depending on your device configuration, you may be presented with an Access selection menu. Type shell to access the device shell.

  2. At the shell prompt, use the python command with no parameters to enter an interactive Python session:

    # python
    Python 3.10.1 (main, Mar 30 2023, 23:47:13) [GCC 11.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

  3. Import the dio module and the Name and State classes:
    >>> from digidevice import dio
    >>> from digidevice.dio import Name, State
    >>>
    • The Name class uses the following naming:

      • Digital I/O port 1: Name.dio1

      • Digital I/O port 2: Name.dio2

      • Digital I/O port 3: Name.dio3

      • Digital I/O port 4: Name.dio4

    • The State class has the following values:

      • on: Sets the current state of the output port to on.

      • off: Sets the current state of the output port to off.

  4. To set the current state of the output port:

    • To set the current state to on:

      >>> dio.set_state(Name.dio1, State.on)
      >>>
    • To set the current state to off:

      >>> dio.set_state(Name.dio1, State.off)
      >>>
  5. Use Ctrl-D to exit the Python session. You can also exit the session using exit() or quit().