Use Python to set the state of LEDs

The following example uses an interactive Python session to set the state of all LEDs to flashing:

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

  2. Import the led submodule:
    >>> from digidevice import led
  3. Import the Led and State objects from the led submodule:
    >>> from digidevice.led import Led, State
  4. Use led.acquire() to gain control of the all LEDs:
    >>> led.acquire(Led.ALL)
  5. Use led.set() to set the state of the LEDs:
    >>> led.set(Led.ALL, State.FLASH)
  6. (Optional) Use led.release() to release the LEDs to system control:
    >>> led.release(Led.ALL)
  7. Use Ctrl-D to exit the Python session. You can also exit the session using exit() or quit().

The use(led) function

The use(led) function can be used to acquire control of LEDs and then release them back to system control.

To create a function that acquires control of the power LED, sets it to a state of fast flashing, and then releases control when the function has completed, use the following code in a python application:

with use(Led.POWER) as pwr:
    pwr(State.FLASH)

Releasing the LEDs to system control

During a Python interactive session, or from within a Python script, you can release control of the LED from Python to system control using the led.release() method.

If the Python script or session terminates prior to releasing control to the system, the LEDs will continue to have the state that Python set to them, until the device is rebooted. See Configure scripts to run automatically for information about configuring the device so that the LED state is controlled by the Python script even after reboot.

If any system processes attempt to take control of the LED while Python is in control of it, the state information from the system process is recorded but the LED state is not updated until Python releases control of the LED. When the LED is returned to system control, the state of the LED will reflect the correct, recorded state information.

Setting the state of multi-colored LEDs.

Use Python to control the color of multi-colored LEDs

One or more LEDs in the IX40 are RGB (red, green, and blue) LEDs, capable of producing a wide range of colors. You can use the digidevice.led Python module to control the color as well as the state of these LEDs.

For example, the LTE connection indicator can be set to various colors:

LED attribute name Color State
Led.COM

Red

ON
Led.ETH OFF
Led.ONLINE OFF
Led.COM

Red flashing

FLASH
Led.ETH OFF
Led.ONLINE OFF
Led.COM

Green

OFF
Led.ETH ON
Led.ONLINE OFF
Led.COM

Green flashing

OFF
Led.ETH FLASH
Led.ONLINE OFF
Led.COM

Blue

OFF
Led.ETH OFF
Led.ONLINE ON
Led.COM Blue flashing OFF
Led.ETH OFF
Led.ONLINE FLASH
Led.COM White ON
Led.ETH ON
Led.ONLINE ON
Led.COM White flashing FLASH
Led.ETH FLASH
Led.ONLINE FLASH
Led.COM Yellow ON
Led.ETH ON
Led.ONLINE OFF
Led.COM Yellow flashing FLASH
Led.ETH FLASH
Led.ONLINE OFF
Led.COM Purple ON
Led.ETH OFF
Led.ONLINE ON
Led.COM Purple flashing FLASH
Led.ETH OFF
Led.ONLINE FLASH
Led.COM Cyan OFF
Led.ETH ON
Led.ONLINE ON
Led.COM Cyan flashing OFF
Led.ETH FLASH
Led.ONLINE FLASH

See The digidevice led submodule for a definition of the IX40's LEDs, including RGB leds, and the names of the attributes for each LED that will be used by the digidevice.led module.

Example: Set the LTE connection indicator to flashing purple

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

  2. Import the led submodule:
    >>> from digidevice import led
  3. Import the Led and State objects from the led submodule:
    >>> from digidevice.led import Led, State
  4. Use led.acquire() to gain control of the all LEDs:
    >>> led.acquire(Led.ALL)
  5. Use led.set() to set the state of the Led.COM and Led.ONLINE to FLASH:
    >>> led.set(Led.COM, State.FLASH)
    >>> led.set(Led.ONLINE, State.FLASH)
  6. Set the state of the Led.ETH to OFF:
    >>> led.set(Led.ETH, State.OFF)
  7. (Optional) Use led.release() to release the LEDs to system control:
    >>> led.release(Led.ALL)
  8. Use Ctrl-D to exit the Python session. You can also exit the session using exit() or quit().