Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Modbus TCP/IP

Modbus TCP/IP protocol is a TCP/IP based communication. One device operates as client and requests data from another device which operates as server. When the client requests, it uses a function code to specify the function which the server should execute. The client can write and read data from/to the memory of the server. Modbus TCP/IP uses port 502 as default. The Modbus devices can be linked via Ethernet or serial port. In our case we are using Ethernet port.

Modbus TCP/IP provides two data types: 

  1. Coils(Digital signals) - 1 bit
  2. Registers(Analog signals) - 16 bits


                                        

                               Fig: Client - Server Rule

Client(Wago)

In our project we use Wago PLC as Client(master). Codesys software is used to setup Modbus configuration .

The following steps will show you how to setup the client device. 

Step 1: Add Ethernet in the device tree


Step 2: Add Modbus Client under Ethernet


Step 3: Add Modbus Server under the Client


Step 4: Assign the IP address of Modbus Client(Wago IP address)


Step 5: Assign the IP address of the Server(Beckhoff IP address)


Step 6: Add the function code you want to use.

N.B. Be careful when you choose offset. Read the document of the server and you will find it which offset you are going to read from server. In our case all inputs and outputs start at 32768(16#8000) and end at 33023(16#80FF).


Source: https://www.hilscher.com








Server(Beckhoff)

We use Beckhoff as a server(slave). Twincat 3 software is used to setup up Modbus configuration.

To access the sever, you have to use a function TF6250 Modbus TCP/IP. First check if the file available in the default directory of Twincat 3:  \TwinCAT3\Functions\TF6250-Modbus-TCP. If it is not available you have to install it from beckhoff website. To configure the server, a configurator is installed to the default directory \TwinCAT3\Functions\TF6250-Modbus-TCP. Run it as administrator an d the tool will allow you to read and change the actual configuration of the Modbus TCP server. You can find more information in the PDF documentation we added in the Document page.

The following steps will show you how to setup the server device:

Step 1:


Step 2: To access the specific Modbus areas, you have to add these global variables to your PLC project.


N.B. Check the .xml-file in the configurator tool to see the variables and offsets you want to assign. The .xml-file we use:

View file
nameModbusSrv.xml
height150


Sourcehttps://infosys.beckhoff.com



Communication Established: Finally we are able to establish Modbus TCP/IP communication. In the figure below you see both Wago PLC(Client) and Beckhoff PLC(Server) are starting to send data among each other.