The task is to establish data exchange between 2 PLCs.

There are 2 main ways to exchange data: NVL and Modbus TCP.

Below are tables of advantages and disadvantages of these two methods, however, the biggest difference lies in which data transmission protocol is used.

TCP vs UDP: Differences between the protocols. The main difference between TCP (transmission control protocol) and UDP (user datagram protocol) is that TCP is a connection-based protocol and UDP is connectionless. While TCP is more reliable, it transfers data more slowly. UDP is less reliable but works more quickly. 


NVL or Network Variables List


AdvantagesDisadvantages
Easy to useUses UDP protocol, UDP provides a simpler and less reliable form of data transmission
Data transmission efficiency: NVL sends data in packets

Delivery is not guaranteed

Absence of a main node: NVL does not have a binding to a main or subordinate node, making it more flexible in usage and managementOnly UDP protocol or it's limited protocol support

Optional data reading: Since data can be available to all nodes, there is no guarantee that all nodes will read or use this data


Modbus TCP

AdvantagesDisadvantages
Reliability: Modbus TCP protocol ensures reliable data transmission with acknowledgment of receiptUse of master and slave in data transmission
Wide supportLimited data transmission speed: More complex data transmission protocol.
Delivery is guaranteed


Since we are simulating the use of a bridge panel, we need to use TCP protocol for reliable data transmission.

Modbus operates according to the common client/server (master/slave) model. That is, the client (master) sends a request telegram (service request) to the server (slave), and the server replies with a response telegram. If the server cannot process a request, it will instead return a error function code (exception response) that is the original function code plus 80H (i.e. with its most significant bit set to 1). 

PLC1 is 158.38.140.56. It will be a master.

PLC2 is 158.38.140.57. It will be a slave.

According to the task we need to transmit data of INT and BOOL types.

Since Modbus only supports WORD data transfer, we still can transfer our data. 

For transmitting BOOL data, it's possible to use one bit from a 16-bit word register. As for INT data (integer numbers), they can also be transmitted via Modbus TCP by placing them in two consecutive 16-bit word registers.


The Modbus registers of a device are organized around the four basic data reference types noted above and this data type is further identified by the leading number of the reference address as follows: 


Modbus Addresses

Modbus devices have 4 types of addresses:

  • Coil
  • Discrete Input
  • Input Register
  • Holding Register

Coils are 1-bit (boolean) read/write devices. Each coil can be in either on or off state. Discrete inputs are similar to coils, but they are read-only - it’s impossible to set the value of a discrete input. You can think of Coils as outputs of a PLC and Discrete Inputs as input of a PLC.

Holding registers are like PLC memory. They are 16-bit words which you can both read and write via Modbus protocol. Input Registers are also 16-bit words, but they are read-only, like readings of a sensor.

A Modbus address is a 16-bit unsigned integer that is transmitted with every request to indicate which data should be read or written. Address occupies two characters in the Modbus message and the most significant byte is sent first (big-endian).


Supported function codes

Functions codeFunctionsSpesifics
FC01Read CoilsThis function code allows the master to query the state of slave’s coils.read coils request is always 8 bytes long. 
read coils response is at least 6 bytes long.
FC02Read Discrete InputsThis function code allows the master to query the state of slave’s discrete inputs.read discrete inputs request is always 8 bytes long.
read discrete inputs response is at least 6 bytes long.
FC03Read Holding RegistersThis function code allows the master to query the state of slave’s holding registers.read holding registers request is always 8 bytes long. 
read holding registers response is at least 7 bytes long.
FC04Read Input RegistersWith this function code, master queries the state of slave’s input registers.read input registers request is always 8 bytes long. 
read holding registers response is at least 7 bytes long.
FC05Write Single CoilSets the value of a single slave’s coil.write single coil request is always 8 bytes long.
response?
FC15Write Multiple CoilsSets the value of a single slave’s holding register.
FC06Write Single RegisterSets the value of a consecutive range of slave’s coils.
FC16Write Multiple RegistersSets the value of a consecutive range of slave’s holding registers.
FC23Read/Write Multiple RegistersIt combines reading and writing functions, allowing the master to read and write values of multiple holding registers in a single request


Start configuration with a client/master Modbus TCP Client/Master

Sending and receiving of data on the Client/Master side

Sending and receiving of data on the Server/Slave side



NB!

In the Modbus protocol, data is sent between registers, not directly between variables. Registers act as memory addresses in devices that use the Modbus protocol, and data is exchanged through these registers.










Source:/Helpful links:

Configuring a Network Variable Exchange:
https://help.codesys.com/api-content/2/codesys/3.5.13.0/en/_cds_configuring_network_variables_exchange/

https://forge.codesys.com/forum/en/124/genmed-Network_Functionality_V23.pdf

Modbus TCP:

https://www.prosoft-technology.com/kb/assets/intro_modbustcp.pdf

https://www.avast.com/c-tcp-vs-udp-difference#:~:text=TCP%20vs%20UDP%3A%20Differences%20between%20the%20protocols,reliable%20but%20works%20more%20quickly.

https://docs.factoryio.com/manual/drivers/modbus-server/#configuration

https://docs.factoryio.com/manual/drivers/modbus-client/#configuration



  • No labels