Home
Product Catalog
News
Contact Us

News 

News

How to determine whether Modbus TCP connection is established?

Publish Date 2020-12-02
How to determine whether Modbus TCP connection is established?
common problem

1. How to determine whether Modbus TCP connection is established?



A: for Modbus TCP communication, a connection needs to be established,



S7-200 smart CPU as Modbus TCP client: command MBus through Modbus TCP client_ The mconnected parameter in the symbol table of client, as shown in Figure 1



Mconnected = 1 indicates that the connection has been established, and mconnected = 0 indicates that the connection has not been established





Figure 1. Mconnected judging connection status



When S7-200 smart CPU is used as Modbus TCP server: command MBus through Modbus TCP server_ The mconnected parameter in the symbol table of server is used to judge, as shown in Figure 2



Mconnected = 1 indicates that the connection has been established, and mconnected = 0 indicates that the connection has not been established





Figure 2. Mconnected judging connection status



Note: when there are multiple clients or multiple servers in PLC, it is not recommended to refer to this status point.



2. How to view error codes?



A: when an error occurs, MBus_ The output parameter done of the client instruction will be 1. However, when the connection is established, the connection is disconnected, and the response is completed, the setting of done will be set to 1.



When an error occurs, there are also error bytes that display the error code, and only one cycle time is reserved.



To sum up, you can view the error code as shown in Figure 3.





Figure 3. View the error code



3. Modbus TCP communication register type data, the amount of data more than 120 words how to deal with?



A: if the amount of data exceeds 120 words, the following two methods can be used:



A. When multiple connections are established, different connections can operate in parallel, because the communication resources occupied are different;



B. A connection is established to perform multiple operations. Polling is required between different operations. Only one operation is in progress at the same time.



4. In Modbus TCP communication, how to access the holding register whose address range is greater than 49999?



The Modbus hold register address is in the range of 40001 to 49999. This range is sufficient for most applications, but some MODBUS slave devices map data to a holding register with a larger address range. MBUS_ The client instruction allows an additional range of the parameter addr to support the extension of holding register addresses from 400001 to 465536



Exhibition scope. For example, to access holding register 16768, set MBus_ The addr parameter of client is set to 416768. All the possible address extensions of Modbus are supported. This extended addressing is only available for holding registers.



5. S7-200 smart is the Modbus TCP client and the server is the gateway module. How to distinguish the slave address of Modbus RTU when connecting multiple MODBUS rut devices?



A: as a Modbus TCP client, the S7-200 smart CPU communicates with the Modbus TCP server. When it attempts to access the device in the serial subnet lower than the Modbus TCP server, an error "unable to establish a connection" will be reported. If Modbus TCP server is used as gateway of Modbus RTU protocol, MB_ UNIT_ ID can be used to identify the serial network



The slave device connected on the network. MB_ UNIT_ The ID is used to forward the request to the correct Modbus RTU slave address. Some Modbus TCP devices may require MB_ UNIT_ The ID parameter is within limits. The location of this parameter is shown in Figure 4



The default value of mmodbusunitid is 255 (16 ා FF). If there are multiple slave devices, a connection can be established between S7-200 smart and gateway module. On this connection, the unitid can be polled by modifying the value of unitid.





Figure 4. Mmodbusunitid



6. For some servers that do not support writing single digit output bit (function code 5) / single holding register (function code 6), how to write single bit / word in S7-200 smart.



A: some MODBUS server devices do not support MODBUS function writing to a single discrete output bit (Modbus function 5) or writing to a single holding register (Modbus function 6). In contrast, these devices only support multi bit write (Modbus function 15) or multiple register write (Modbus function 16). If the server device does not support single bit / word MODBUS



Function, then MBus_ The client instruction returns error code 1. Modbus client protocol allows mandatory MBus_ The client instruction uses multiple bit / word MODBUS functions instead of a single bit / word MODBUS function. You can find the symbol mmodbusforcemulti in the Modbus client symbol table and execute MBus in the program_ Before client



Change this value to force multiple bit / word instructions. Setting mmodbusforcemulti to true forces the use of multiple bit / word functions when writing a single bit or register. As shown in Figure 5.





Figure 5. Mmodbus forcemulti






Home  |  Product Catalog  |  News  |  Contact Us  |  Sitemap  |  Mobile Version
  简体版     繁體版     English

Powered by DIYTrade.com  Build your FREE website !
Find Best Price For China Products !