Objective: Configure a RevPi base module as a Modbus TCP Server so that external Modbus TCP Clients can access data from the RevPi.
The configuration is performed in the PiCtory application. Process data from the RevPi is then written to Modbus registers and read with a Modbus TCP Client.
This tutorial is suitable for applications in industrial automation, remote monitoring, and IoT communication.
This tutorial applies to all RevPi base modules.
Prerequisites #
Devices
✓ Client device or software, e.g., QModMaster on a Windows PC
✓ Cable with RJ45 connectors
Hardware Installation
✓ The RevPi base module is connected to the network.
✓ The RevPi base module is connected to the power supply.
✓ The client device is connected to the RevPi via the RJ45 connector.
Software Installation
✓ Web browser (e.g., Chrome, Firefox, or Edge)
✓ QModMaster from SourceForge is installed on your Windows PC.
✓ The RevPi and the client device are on the same network.
✓ IP addresses are correctly configured and the devices can communicate with each other.
1. Configuring the Modbus TCP Server in PiCtory #
❯ The Cockpit application is open.
▷ Open the PiCtory app.
▷ Drag the RevPi base module from the Device Catalog to the empty slot in the configuration area with position number 0.
▷ Drag a ModbusTCP Slave [1] from Virtual Modbus Devices in the Device Catalog to the base module in the configuration area.
❯ The virtual device is now displayed in the configuration area.
▷ Select the Modbus TCP Server in the configuration.
▷ Configure the following parameters at the very bottom of the list in the Value Editor:
-
TCP_port:
502(default value according to the Modbus specification) -
max._modbus_TCP:
10(or another suitable value)
See also Configuring Values.
▷ Select to save the configuration.
▷ Select to apply the configuration.
2. Querying the CPU Temperature #
▷ Open a terminal.
▷ Query the CPU temperature of the RevPi:
/usr/bin/vcgencmd measure_temp
❯ The output shows the temperature, e.g.:
temp = 48.7'C
▷ Scale the temperature by a factor of 10 to provide the value as an integer for Modbus communication:
/usr/bin/vcgencmd measure_temp | awk ' { print substr($0,6,2) substr($0,9,1) } '
487
❯ The temperature is displayed as an integer with one decimal place, e.g., 487 for 48.7 °C.
Writing Data to a Modbus Register
The Modbus TCP Server provides data from the process image as Modbus registers.
The process image variables Output_* and Input_* are automatically assigned to the Modbus registers.
▷ Write the converted temperature data to a Modbus register:
piTest -w Output_1,$(/usr/bin/vcgencmd measure_temp | awk ' { print substr($0,6,2) substr($0,9,1) } ')
▷ Run the process in a loop to update continuously:
while true; do piTest -w Output_1,$(/usr/bin/vcgencmd measure_temp | awk ' { print substr($0,6,2) substr($0,9,1) } '); sleep 1; done &
❯ Output:
Write value 492 dez (=01ec hex) to offset 11.
Write value 498 dez (=01f2 hex) to offset 11.
Write value 492 dez (=01ec hex) to offset 11.
3. Querying Data with QModMaster #
Values written to Output_* can be read by the Modbus TCP Client using the Read Input Registers (0x04) function.
Configuring QModMaster
▷ Open QModMaster.
▷ Set the following parameters:
-
Modbus Mode: TCP
-
Unit ID:
1 -
Scan Rate (ms):
1000 -
Function Code: Read Input Registers (0x04)
-
Start Address:
0 -
Number of Registers:
1 -
Data Format: Dec
|
Note
|
Register addressing may be displayed differently depending on the Modbus client. Some tools use register addresses starting at |
▷ Select .
▷ Enter the IP address of the RevPi in the Slave IP field.
▷ Set the TCP Port to 502 (default for Modbus TCP connections).
Connecting to the Modbus TCP Server
▷ Select to establish a connection with the Modbus Server.
Querying Data
▷ Select to retrieve data.
▷ The CPU temperature is displayed in decimal form, e.g., 487 for 48.7 °C.
Modbus Functions #
The Modbus server module supports the following Modbus functions:
-
Read Holding Registers (0x03)
-
Read Input Registers (0x04)
-
Write Single Register (0x06)
-
Write Multiple Registers (0x10)