Modbus TCP Slave

Topics about the Software of Revolution Pi
Post Reply
asherjackson
Posts: 1
Joined: 29 Aug 2024, 10:32

Modbus TCP Slave

Post by asherjackson »

Does RevolutionPI already come with a server that listens to say port 502 that will reply to modbus TCP protocol?

For instance, using the webinterface, I have enabled "Enable/Disable Modbus Slave".

But after this enable and reboot, the PC still does not accept incoming connections on 502.

Specifically, I would like to read DigitalIn and DigitalOut of the RevolutionPi via ModbusTCP.

Thank you
u.biakoup
Posts: 212
Joined: 14 Apr 2022, 13:04

Re: Modbus TCP Slave

Post by u.biakoup »

Hello asherjackson ,

The RevolutionPi does come with the ability to act as a Modbus TCP slave, but it doesn't automatically start a Modbus TCP server on port 502 just by enabling the "Modbus Slave" option in the web interface.

Verify that the port 502 is open and not blocked by any firewall or security settings on the RevolutionPi. You can check this by running:

Code: Select all

sudo iptables -L
If needed, you can open the port with:

Code: Select all

sudo iptables -A INPUT -p tcp --dport 502 -j ACCEPT
The Modbus server should be running after the configuration. You can check if the service is listening on port 502 using

Code: Select all

sudo netstat -tuln | grep 502
If there’s no output, it means the server isn’t running. You might need to restart the Modbus service or the entire device.

Once the server is running, you should be able to read DigitalIn and DigitalOut using Modbus TCP. Make sure to do the mapping for these inputs and outputs. You can a python script with the library revpimodio

see the following code as example:

Code: Select all

import revpimodio2
import time

# Initialisierung des RevPiModIO Objekts
rpi = revpimodio2.RevPiModIO(autorefresh=True)

while True:
  
    rpi.io.ModbusOutput_1.value = int(rpi.io.I_1.value)
    
    rpi.io.O_1.value = int(rpi.io.ModbusInput_1.value)
    
    print(rpi.io.ModbusOutput_1.value, rpi.io.O_1.value)
    time.sleep(0.02)

Best Regards

Ulrich Kouatang Biakoup | field application engineer
Post Reply