Modbus gateway is a device capable of transforming Modbus TCP into Modbus RTU. Modbus is widely used in the field of instruments and sensors, and data of instruments and sensors can be obtained. However, the traditional Modbus RTU (or ASCII) based on RS485 has poor speed and expansibility, so Modbus TCP, a network based protocol, later appeared. So Modbus gateway this kind of converter arises at the historic moment.
Four Modbus gateways range from simple protocol conversion to multi-host gateways, to storage gateways, to configurable gateways such as ZLMB. From simple to complex is also a reflection of their development process, and understanding their strengths and weaknesses helps engineers better understand how they are used.
In particular, the ZLMB configurable gateway can preconfigure multiple register lists of multiple slave stations to be read, and then the network port can read all the registers with one instruction at a time, which is very efficient. And it reads very fast. For details, please refer to Configurable Modbus Gateway ZLMB.
The original Modbus gateway was nothing more than a data format conversion solution. For example, in the function code 03 in Modbus RTU (RS485 terminal), the instruction to read one register at the beginning of 00 is: 01 03 00 00 00 01 84 0a, among which 84 0A is a CRC check. And a Modbus TCP instruction (network side) is 00 00 00 00 00 06 01 03 00 00 00 01. We know that the ordinary serial server is "pass-through", that is to send serial port to send 01 03 00 00 00 01 84 0A, network port is also 01 03 00 00 00 01 84 0A. In order to achieve this RTU to Modbus TCP function, we found that as long as the CRC check 84 0A and the beginning of 00 00 00 00 00 06 can be removed.
This simple format transformation does meet the requirements initially. But the disadvantages are:
1. No multi-host access: Multiple Modbus TCP hosts cannot be implemented to access the gateway, because the data sent by host A and Host B will preempt the bus conflict and cause data disorder on the RS485 bus.
2. Return data interference: The response of the device to host A will be returned not only to Host A but also to host B, so there will be interference data in the return data of host B.
Although simple protocol conversion has been obsolete, here is a brief introduction to its setup: in the device Edit interface of ZLVircom configuration tool, select the conversion protocol as "Modbus TCP to RTU", and remove the checkboxes of "multi-host" and "RS485 conflict Prevention" from the advanced options.
The Modbus gateway of multi-host mode is designed to solve the shortcoming of "simple protocol transformation" mode. As shown in the figure above, when host A and Host B are accessed at the same time, Modbus gateway will perform bus occupation scheduling, thus solving the bus conflict problem. In addition, the data accessed by host A will not be sent to Host B again, thus solving the problem of returned data interference.
The data communication steps are as follows:
1. When the gateway receives the query request from Host A, check whether the bus is in use; if it is idle, send it to RS485 bus; otherwise, wait for the bus to be idle.
2. The gateway records the host of the current query. Here is host A.
3. When the data is returned from RS485 bus, the gateway converts it into Modbus TCP format and forwards it to the corresponding host (in this case, Host A).
The advantage of multi-host mode is that it realizes simultaneous access of multiple hosts and solves the problems of bus conflict and return data interference. However, there are still some shortcomings:
1. Slow data return: It can be seen from the above data communication steps that a host machine needs a data line to forward data from the network to the RS485 bus, and waits for the device to return and then forwards data from the RS485 to the network. As the RS485 bus itself is a slow communication mode, the host generally needs to wait 50 ~ 100ms to get a data.
2. Waiting is easy to time out when there are many hosts: this is another problem caused by slow data return.
The default for early ZLAN5142 was "multi-host mode"; "Multi-host mode" is not supported for ZLAN5143 (version 1.565 before), only "storage mode" is supported; For the support of "multi-host mode" in ZLAN5143 (1.565 and later versions), the setting method is as follows: select the conversion protocol as "Modbus TCP to RTU" in the "Device Edit" interface of ZLVircom configuration tool, and change the RS485 bus collision waiting time to 2 seconds at most in the advanced option.
Storage type gateway is in order to solve the shortcoming of "multi-master model", due to the slow "multi-master model" problem is mainly caused by RS485 bus data returned is too slow, the thinking of "storage" is through certain need data obtained in advance, stored up in advance, such as network end need data can provide immediately, thus reducing the data query time.
Storage gateway has two characteristics:
1. Self-learning: The storage gateway does not need to be configured, because it can save the record together when the host asks for a query data. The internal gateway will automatically learn the data needed by the current network port.
2. Query beforehand: When the gateway learns of all the registers requested by all the hosts, it will query one by one beforehand and store the results inside the gateway.
In this way, when host A wants the data previously requested, the gateway will retrieve the data from its own memory and immediately return it to host A. Since there is no process of forwarding to the RS485 bus, the time is about 1 ~ 2ms, which is greatly improved compared with the previous 50-100ms.
Advantages of storage gateway:
1. Fast return speed: The return time of host A query is greatly improved.
2. No configuration: Because of the self-learning approach, no configuration is required and the operation is not different from the "multi-host mode".
Storage gateway issues:
1. Slow return of the first instruction: since the gateway learns to obtain the register number requested by the host, it is impossible to inquire in advance before obtaining this information. So the first instruction sent by the host still needs to get data by going to the RS485 bus. The first instruction returns as slowly as in multi-host mode.
2. Too fast RS485 bus query may affect the work of the device: since by default RS485 bus will query the register content inside the slave station device at the fastest speed, and some instruments may not be able to adapt to such a fast query, resulting in abnormal operation of the device. For this point can actually increase the "RS485 bus free time" parameter to solve the problem of too fast query, in fact can be solved.
3. Not up to date data: Since the data is obtained and stored in advance, the searched data may not be up to date, although the time is only a few hundred milliseconds. In some special cases, this delay should be taken into account.
4. Timing problem: Some Modbus TCP reads and stores according to write, read and other timing operations. Such pre-storage of "storage" will disrupt the timing and cause incompatible problems with some devices.
Disadvantages 2, 3, and 4 can all be addressed by retracting to the "multi-host mode" gateway. Note that retracting to the "multi-host mode" will slow the data return. Note that the new firmware for ZLAN5143 supports both "multi-host mode" and "storage mode." The above drawback 1 (the first instruction returns slowly) will be addressed later in the "configurable" gateway.
ZLAN5142 does not support "storage". The way to set ZLAN5143 as "storage" is to select "Modbus TCP to RTU" from the "Device Edit" interface of ZLVircom configuration tool.
A configurable gateway can be used to solve the problem of slow return of the first instruction of a "storage" gateway. Configurable gateway also adopts the method of "storage" gateway to obtain the RS485 bus slave station register contents in advance. However, it does not take a self-learning approach, in order to solve the problem of slow return of the first instruction, the required register list must be configured inside the gateway beforehand. It can preconfigure the address, function code and register list of devices on Modbus RTU and store them in the gateway. The gateway automatically collects the data of these configured RTU devices, which are then mapped to successive Modbus TCP register addresses, allowing the Modbus TCP side to read the data of different registers of all devices at once.
ZLAN configurable gateway also known as ZLMB gateway, has the following advantages:
1. Fast return of all instructions: even the first instruction is also fast.
2. Instruction combination improves efficiency: different station addresses and registers can be mapped to the same register. In this way, Modbus TCP can use one instruction to collect all the data, including the data of devices with different station addresses, instead of collecting the data separately in several instructions, which improves the transmission efficiency of Modbus TCP.
3. Address remapping: In some cases, the ZLMB gateway can achieve the requirement of remapping different discrete registers to an entire contiguous region.
Disadvantages of configurable gateways:
1. Manual configuration is required: If the "storage" gateway can meet the requirements, the "storage" gateway can be selected first, because "storage" does not require any configuration. The ZLMB mode requires manual configuration of the required registers using ZLVircom.
2. Pre-read problems: "not up to date" and "timing issues" are common with storage.
ZLAN5143, ZLAN7144, ZLAN7146 and ZLAN8303 all support configurable Modbus gateway function. ZLAN5143 requires firmware version 1.579 or above, and ZLVircom5.15 or above for use. Firmware version 1.491 or above is required for 7144. The configuration method is as follows: click the button of "Firmware and Configuration" in the "Device Edit" interface of ZLVircom configuration tool, then select "Web directory download" in the pop-up dialog box of "Web Program Download Tool", then click the button of "ZLMB", and click the button of "Download" to download the device content after the design is completed. Please refer to "Configurable Modbus Gateway ZLMB" for details.
Gateway type | Simple protocol conversion | multi-host mode | Storage Gateway | Configurable gateway |
---|---|---|---|---|
Support multi-host | ╳ | √ | √ | √ |
Returns instruction fast | ╳ | ╳ | √ | √ |
First instruction return fast | ╳ | ╳ | ╳ | √ |
No pre-read problem | √ | √ | ╳ | ╳ |
No need to configure | √ | √ | √ | ╳ |
Support for directives and merge and remap the address | ╳ | ╳ | ╳ | √ |
In general, configurable gateway is the Modbus gateway with the highest reading efficiency and the most advanced, but the configuration is relatively complicated. The storage gateway is the default mode and the easiest mode to use. Meanwhile, it has the characteristics of multi-host and fast reading speed. And in some RS485 devices do not adapt to "read in advance" this case, can fall back to the "multi-host" mode this slow mode. However, "simple protocol conversion" mode is generally not adopted due to bus error and loss when there are multiple hosts.
The four Modbus gateway modes and their corresponding models are listed in the following table:
Name | Model | Simple protocol conversion | multi-host mode | Storage Gateway | Configurable gateway |
---|---|---|---|---|---|
Multi-port Modbus gateway | ZLAN5240、ZLAN5443A、ZLAN5843A、ZLAN5G40A | √ | √ | ╳ | ╳ |
Single port Modbus gateway | ZLAN5142、ZLAN5142-3 | √ | √ | ╳ | ╳ |
New generation multi-port Modbus gateway | ZLAN5443D、ZLAN5443-232 | √ | √ | √ | √ |
Ethernet Modus gateway | ZLAN5143 | √ | √ | √ | √ |
Wifi+ Ethernet Modus gateway | ZLAN7144 | √ | √ | √ | √ |
Wifi Modus gateway | ZLAN7146 | √ | √ | √ | √ |
4G+ Ethernet Modbus gateway | ZLAN8303-7 | √ | √ | √ | √ |
Zigbee Modbus Gateway | ZLAN9543 | √ | √ | √ | √ |
Lora Modbus gateway | ZLAN9743 | √ | √ | √ | √ |