The Swiss Army Knife in Modbus Debugging
In daily life Modbus Equipment debugging in progress, Not every time it needs to be opened Wireshark Capture or write packages Python script. Sometimes you just need to quickly verify a function——Decoding a string of hexadecimal messages, Scan the register range of an unknown device, Or test a read-write request on the command line. This article summarizes modbus.org The recommended lightest ones, The most practical Modbus Small tools.
Modbus RTU/TCP Online message parser
When you receive a string from the serial assistant Modbus Message, Or printed a section during debugging in the code Modbus Binary data, You need to quickly understand what this data means. on-line Modbus The message parser is the fastest solution——No need to install any software, You can use it by opening the browser.
on-line Modbus RTU Parser
Recommended tools: CAS Modbus RTU Parser (Chipkin Automation Systems Provide)
visit: store.chipkin.com/products/tools#modbus-rtu-parser
This is a pure web tool. You just need to paste a string of hexadecimal Modbus RTU Message:
01 03 00 00 00 0A C5 CDAfter clicking on 'parse', The tool will automatically display:
- Slave station address (Slave ID) = 1
- Function code = 03 (Read Holding Registers)
- Starting address = 0
- Request quantity = 10 A register
- CRC Verification = 0xCDC5 (And verify if it is correct ✓)
on-line Modbus TCP Parser
visit: store.chipkin.com/products/tools#modbus-tcp-parser
And with RTU Similar versions, But it has increased MBAP Analysis of the head: Transaction ID, Protocol ID, Length And Unit ID. Paste as follows: TCP Message is sufficient:
00 01 00 00 00 06 01 03 00 00 00 0AAnalysis results: Affairs ID=1, agreement=Modbus, From the station=1, Function code=03, Starting address=0, quantity Device address space scanning tool=10.
Modbus Download link
CAS Modbus Scanner
When you receive an incomplete register mapping manual: store.chipkin.com/products/tools/cas-modbus-scanner
Equipment time Modbus The most direct method is to 'scan', The most direct method is to 'scan'"——Use Modbus Scanner Traverse the address space of the device, Record which addresses returned valid data.
usage method:
- Set connection method (TCP Input IP:Port, RTU Select serial port)
- Select the address range to scan (Suggest starting with a small scope 0-100 Probing)
- Select the type of data to be scanned: Coil, Discrete input, Maintain registers, Input register
- Click Start Scan, Observation results
- Record the addresses that return valid data
- Combining physical equipment (Change physical quantities, Observe the corresponding register changes) Verify
Scanning skills:
- First scan and hold the register (4xxxx) , Because the configuration and measurement data of most devices are here
- If an address returns an exception code 02 (Illegal data address) , Indicates that the address is invalid
- If returned 0 But there are no abnormalities, Need to determine if the value is true=0 Or is the device not implementing the address (Scanning alone cannot distinguish)
- Change physical incentives (Like heating up, Rotary encoder) Follow up scan, Observe which address values have changed
Command line protocol testing: modbus-cli skill Except for specialized tools
Many common command-line tools can also be used, Testing Modbus Use:
Testing Netcat Connectivity TCP Use
# Test Modbus TCP Is the device online
nc -zv 192.168.1.100 502
# If output "Connection to 192.168.1.100 502 port [tcp/*] succeeded!" Explanation onlineOne line command test Python Use
# Install pymodbus after,One line test reads hold register
python3 -c "
from pymodbus.client import ModbusTcpClient
c = ModbusTcpClient('192.168.1.100')
c.connect()
rr = c.read_holding_registers(0, 5, slave=1)
print('Values:', rr.registers if not rr.isError() else rr)
c.close()
"Analyze binary xxd data Quick reference for protocol functions Modbus During debugging, it is often necessary to check the function code correspondence table
# If you have a paragraph Modbus Binary data file,It can be used. xxd Check
xxd modbus_dump.bin
# or use hexdump Format display
hexdump -C modbus_dump.bin | head -20Modbus The following is a quick search for commonly used function codes
Function code, name:
| Data type | Operation | Coil | Read |
|---|---|---|---|
| 01 (0x01) | Read Coils | coil (0xxxx) | Read 1-bit |
| 02 (0x02) | Read Discrete Inputs | Discrete input (1xxxx) | Read 1-bit |
| 03 (0x03) | Read Holding Registers | Maintain registers (4xxxx) | Read 16-bit |
| 04 (0x04) | Read Input Registers | Input register (3xxxx) | Read 16-bit |
| 05 (0x05) | Write Single Coil | Coil | Write 1-bit |
| 06 (0x06) | Write Single Register | Maintain registers | Write 16-bit |
| 15 (0x0F) | Write Multiple Coils | Coil | Write more 1-bit |
| 16 (0x10) | Write Multiple Registers | Maintain registers | Write more 16-bit |
| 23 (0x17) | Read/Write Multiple Registers | Maintain registers | Read write combination |
Modbus Quick search for abnormal codes
| Exception code | meaning | Common reasons |
|---|---|---|
| 01 | Illegal function code | The device does not support this function code |
| 02 | Illegal data address | The requested address range exceeds the available range of the device |
| 03 | Illegal data values | The value written exceeds the allowed range |
| 04 | Substation equipment malfunction | Internal device error, Unable to process request |
| 05 | Confirm (ACK) | The request has been accepted but will take a long time to process |
| 06 | The slave station equipment is busy | The device is busy, Try again later |
Summary
Modbus Debugging does not require the use of heavy tools every time. Online parsers are suitable for quickly decoding messages, Scanners are suitable for reverse register mapping of unknown devices, Command line tools are suitable for automated testing. Mastering these 'small tools' can help you Modbus Doubling debugging efficiency——When encountering problems, use the lightest tools to locate them first, Only use when in-depth analysis is needed Wireshark Waiting for heavy tools.
Leave a Reply