利来囯际W66

关注官方微信

中文.

Modbus Gateway of RTU as Master

Published Time:2019-09-17 Author:Shanghai ZLAN Views:7556
1. The problem of RTU as the main station

Generally speaking, Modbus gateway's interface is connected to the master station, Modbus TCP is used as the interface, serial port is connected to various RS485 instruments, and Modbus RTU is used as the serial port. However, in a few cases, serial port (RS485) as the master station needs to obtain the data of Modbus TCP slave station, as shown in the figure below:

RTU做主站的结构示意图

Because Modbus RTU and Modbus TCP address in different ways, the ordinary way can not achieve this function. RTU generally USES the first byte of Modbus RTU instruction as the station address, such as 01, 03, 00, 00, 01, 84, 0a's first byte 01 refers to the query station address 1, and all devices on RS485 bus that are not at 01 address will not answer. However, when Modbus TCP USES TCP connection as the binding link between master and slave stations, the concept of slave station address is no longer required. Modbus TCP will respond to any query sent to it. It ignores the byte of station address 01. In fact, Modbus TCP USES IP address as station number identification.

The common way to query RTU master station is as follows:

1. First, six Modbus gateways (two ZLAN5143×1 and one ZLAN5443D×4) are configured and connected to six Modbus TCP slave stations with addresses of 192.168.1.61, 192.168.1.62 and 192.168.1.63 ~ 192.168.1.66 respectively. RS485 of Modbus RTU master station and RS485 of 6 Modbus gateways are connected together.

2. Modbus RTU master STATION PLC sends instructions to RS485 bus 3D 03 00 00 01 81 36.

3. All 6-way Modbus gateways will receive 3D 03 00 00 01 81 36, and all data converted into Modbus TCP format 00 00 00 00 06 3D 03 00 00 00 00 01, respectively sent to 192.168.1.62, 192.168.1.63 ~ 192.168.1.66.

4. Although instruction 00, 00, 00, 00, 06, 3D, 03, 00, 00, 01 also has the ADDRESS field 3D (hexadecimal 3D is 61), each Modbus TCP slave station does not care about the address of this slave station, all slave stations will give a reply.

5. 6 Modbus gateway receives the response from Modbus TCP slave station almost at the same time and sends it to RS485 bus at the same time, resulting in bus conflict and data confusion.

The final result of the above scheme is due to data conflicts and unavailability.

2. Plan of RTU as the main station

According to the analysis in the previous section, the key problem lies in the different ways of station recognition between Modbus TCP and RTU. The former is IP address, while the latter is station address. We cannot modify the protocol of RTU master station PLC or Modbus TCP slave station. So this address translation needs to be done inside the Modbus gateway.

The implementation method is to take the last field of Modbus TCP slave station IP address as the Modbus RTU station address. Therefore, in order to access 192.168.1.62, 192.168.1.63 ~ 192.168.1.66, the instructions sent by the RTU master station should correspond to the station addresses 61, 62, 63 ~ 66, namely: 3D 03 00 00 00 01 81 36, 3E 03 00 00 00 01 81 05, etc.

Modbus gateway will recognize the station address after receiving the RS485 bus instruction. If the station address is the same as the last field of Modbus TCP IP address to which it is connected, it will forward; otherwise, it will not forward. That is, there needs to be a little customization.

With this custom function, when following the previous communication steps, only one Modbus gateway forwards the data, and only one return data is forwarded to the RS485 bus accordingly, thus avoiding conflicts.

3. Specific implementation steps

To do this little customization, you need to get the "RTU as host" configuration file from ZLAN, download it into the device, and power it back on.

4. Multi-purpose connectivity

In practical applications, there is a more effective method than figure 1, that is, each Modbus gateway can connect six destination IPs. Therefore, in Figure 1 above, only one ZLAN5143 is needed, but five additional destination IPs need to be configured to connect to 192.168.1.62 and 192.168.1.63 ~ 192.168.1.66 respectively.

The custom function of "RTU as the master station" will recognize the IP address of the connection, and the last byte of the destination IP address will not be forwarded if it is different from the RTU slave station address. Therefore, a single Modbus gateway can also be used to realize the query of six Modbus TCP slave stations.

利来囯际W66