How to obtain and set DIDO in one's own application on the EG series devices?

How to obtain and set DIDO in one's own application on the EG series devices?

Overview

When using Robustel's EG series gateways (like the EG5120 or EG3110) running RobustOS Pro, you often need to interact with the physical world through Digital Inputs (DI) and Digital Outputs (DO). For instance, you might need to read the state of a connected switch (DI) or turn on an alarm light (DO). This guide provides the specific command-line instructions to read DI states and control DO states from the device's terminal. These commands are useful for scripting and remote diagnostics, and can be easily executed from within custom applications written in various programming languages.

What You'll Need

Hardware list:

  • 1 x Robustel EG Series Gateway (e.g., EG5120, EG3110) with DI/DO ports.
  • Power supply for the gateway.
  • An Ethernet cable.
  • (Optional) Equipment for testing, such as a switch or sensor for DI and an LED or multimeter for DO.

Software/Firmware:

  • An SSH client (e.g., PuTTY, Windows Terminal, macOS Terminal).

Prerequisites:

  • You have already created a sudo user account through the RobustOS Pro web interface. 

Step-by-Step Configuration Guide

The entire process is performed through the gateway's command-line interface (CLI).

Step 1: Access the Gateway's Command Line

First, you need to establish an SSH connection to your gateway to access its terminal.

  1. Connect your gateway to your local network via an Ethernet cable.
  2. Open your SSH client.
  3. Connect to the gateway's IP address (default is 192.168.0.1).
  4. Log in using your sudo user credentials.
ssh your_sudo_user@192.168.0.1

Step 2: Configure and Enable DI Port in WebUI

For applications requiring real-time, event-driven DI status updates, it is recommended to monitor the device file (e.g., /dev/DI1) for EV_KEY events using standard Linux input event handling methods. The following steps, however, configure the port for use with the usi command, which is suitable for periodic polling of the DI state.  

  1. Navigate to Interface > DI/DO.
  2. Go to the DIDO tab.
  3. Locate the DI you want to use (e.g., Index 1 for DI1) and click its corresponding edit button (pencil icon).
  4. In the pop-up window:
    • Toggle the Enable switch to ON.
    • Select ON-OFF from the Mode dropdown menu.
    • Click Submit.
  1. Click the "Save & Apply" icon in the upper right corner to make the changes effective.

Step 3: Get Digital Input (DI) Status

You can read the status of any DI port using the built-in usi command.

  1. To get the status of DI1, execute the following command. The output will be either High or Low.
sudo usi get dido.di[1].level
  1. If you require a binary output (0 or 1) instead of text, you can pipe the command through grep to convert it. This command will output 0 if the state is "Low" and 1 if the state is "High".
sudo usi get dido.di[1].level | grep -qx "Low" && echo 0 || echo 1

Note: To check a different DI port, simply change the number inside the brackets, e.g., dido.di[2] for DI2.

Step 4: Get Digital Output (DO) Status

The status of DO ports is managed through the standard Linux /sys filesystem.

  1. To check the current status of DO1, read the brightness file for the corresponding DO. 1 indicates the DO is set to High (On), and 0 indicates Low (Off).
cat /sys/class/leds/do1/brightness

Note: To check a different DO port, change do1 to do2, etc.

Step 5: Set Digital Output (DO) Status

You can change the state of a DO port by writing to the same brightness file. This requires superuser privileges, so sudo tee is used.

  1. To set DO1 to High (On), execute the following command:
echo 1 | sudo tee /sys/class/leds/do1/brightness
  1. To set DO1 to Low (Off), execute the following command:
echo 0 | sudo tee /sys/class/leds/do1/brightness

Verification & Testing

After running the commands, you should verify that they work as expected.

  • To Test DI: Physically connect a switch or apply a voltage to the DI terminals. Run the sudo usi get dido.di[x].level command and observe the output change between "Low" and "High" as you toggle the input.
  • To Test DO: Run the echo 1 | sudo tee ... command. Observe the corresponding DO status on the gateway; it should turn on. Running echo 0 | sudo tee ... should turn it off. You can also connect a multimeter to the DO terminals to verify the voltage change.

Troubleshooting / FAQ

  • Q: I get a "permission denied" error when trying to set the DO state.
    A: Writing to /sys/class/leds/ requires root permissions. Make sure your command includes sudo tee. Simply using sudo echo 1 > ... will not work due to how shell redirection handles permissions.
  • Q: The command usi is not found.
    A: The usi utility is a key part of RobustOS Pro. If this command is missing, you may be on a different firmware or operating system. Please ensure your device is running a compatible version of RobustOS Pro.
  • Q: The path /sys/class/leds/do1/brightness does not exist.
    A: The exact naming can sometimes vary. Use the command ls /sys/class/leds/ to list all available LED controls on your specific gateway model and find the correct identifier for your DO ports (e.g., it might be user:do1 or similar).

Revision History

Revision

Date

Author

Notes

1.0

2025-10-11

Jens Zhou

Initial Release



    • Related Articles

    • How to install the MQTT broker service on EG series devices?

      Overview This article provides a step-by-step guide for installing and configuring the Mosquitto MQTT broker on a Robustel EG series gateway (e.g., EG5120, EG5200) running RobustOS Pro. This setup is ideal for scenarios where you need a reliable, ...
    • How to Set up Python Scripts with Crontab

      Note: This method is applicable to all EG Series/RobustOS Pro devices Author: Eldar Mustafin 1. Creating a Python Script First, create your Python script with proper logging and error handling. Here's a template: #!/usr/bin/env python3 import logging ...
    • How to Update EG Series Device via USB

      This guide explains how to update your EG Series/RobustOS Pro device using a USB drive with the firmware package mg460-uuu-udisk-upgrade-2.1.5.tgz. Here take MG460 for example. ⚠️ Important Warning CAUTION: This process will restore the device to ...
    • How to set up Wi-Fi AP mode on RobustOS Devices?

      Overview This guide provides step-by-step instructions on how to configure your Robustel gateway to function as a Wi-Fi Access Point (AP). This setup allows you to create a local wireless network, enabling devices such as laptops, smartphones, and ...
    • How to Set up RS422 Serial Connection

      1. Physical Connection Setup Hardware Requirements MOXA Uport 1150 device Serial cable RobustOS PRO device with RS422 interface Pinout Connections Connect the following pins between your devices: T+ → RX1+ T- → RX1- R+ (D+) → TX1+ R- (D-) → TX1- GND ...