Modbus – First Steps

For the “Modbus” fieldbus, note that for the Modbus master and slave device, an “Ethernet” element has to be created first. The Modbus master and slave are inserted under it. A representative of the slave is inserted under the Modbus master and establishes a connection between the master and slave via the slave IP address.

  1. You need to have inserted two devices in your project. One of the devices will play the role of the Modbus master and the other that of the Modbus slave.
  1. First create an “Ethernet” fieldbus element for both devices in the device tree. To do so, right-click on the respective device and select Insert Device ....
  2. Select the “Ethernet” fieldbus under “Ethernet Adapter.”
  3. Inserting an “Ethernet” Fieldbus
  4. Click [Insert Device] and leave the dialog open.
  5. A new “Ethernet (Ethernet)” element is created in the device tree.
  6. Click on the new “Ethernet (Ethernet)” element.
  7. Under “Modbus,” select the “Modbus TCP Slave” for the slave device in the dialog that is still open, confirm with [Insert Device] and leave the dialog open.
  8. Under “Modbus,” select the “Modbus TCP master” for the master device in the dialog that is still open, confirm with [Insert Device] and leave the dialog open.
  9. Inserting Devices
  10. Click the “Modbus_TCP_Master (Modbus TCP Master)” element in the device tree and insert the “Modbus TCP Slave Device” element from the dialog that is still open.
  11. You have now inserted a slave element under the master in the device tree, through which the connection between the master and the physical slave is established.
  12. Modbus Master and Slave Created
  13. To link the master and slave, now enter the IP address of the slave device for the “Modbus_TCP_Slave (Modbus TCP Slave)” slave element below the master. To do so, double-click “Modbus_TCP_Slave (Modbus TCP Slave)” to open the configuration and enter the IP address of the slave device on the “General” tab.

You can find a complete example project in Example Project: Creating a New Modbus Project in CODESYS.