In this example, we want to run a Modbus TCP slave and a Modbus RTU slave on the RevPi Connect+ CODESYS with CODESYS Control for Raspberry Pi MC SL.
In this case, the application should copy the first 10 Holding registers to the 10 input registers of both slaves.
The following figure shows the CODESYS device tree overview of the example.
If you have a license for Single Core, you can change the target like this:
- Right-click on the “Root Device” CODESYS Control for Raspberry Pi MC SL in the CODESYS device tree.
- Click on update device.
- Select CODESYS Control for Raspberry Pi SL.
The CODESYS Control device target for the example will then be changed from multi core to single core.
Configuring MODBUS RTU Serial Port
For RevPi Connect or Core:
- Add the following line in /etc/CODESYSControl.cfg
Modbus RTU Slave Configuration
- Map Holding Registers and Input Registers to the application POU named “POU_Modbus” in order to make the data available to the application.
- For Modbus TCP Slave, the configuration is similar to the one done for Modbus RTU slave.
Simulating Modbus TCP and RTU Master
- For the simulation of Modbus TCP and RTU master we use the application QModMaster. You can download the application here: https://sourceforge.net/projects/qmodmaster/.
Write Multiple Registers writes to Holding Registers of the slave and Read Holding Registers gives back input register data of the Modbus TCP/RTU Slave running on RevPi.
Modbus TCP Unit ID: It has the same functionality as the slave ID. However, there is still the 255. In practice, it depends on the connected device which value has to be set. Then either a Modbus TCP Slave will be clearly identified in the network by means of its IP address. But when this slave is a gateway of ModbusTCP on Modbus RTU, it can address several Modbus RTU Slaves. The Unit ID 255 is recommended to address the gateway itself. QModMaster uses unit ID 0 instead of 255 for this purpose.