libmodbus icon indicating copy to clipboard operation
libmodbus copied to clipboard

Read single register of more than 2 bytes

Open sourabhburse opened this issue 2 years ago • 1 comments

Hi,

I am trying to read a modbus device but it doesn't follow modbus standard.

Request: 01 03 07 EE 00 02 A5 4A

Part of Data Package Description Value
01 Slave address 0x01 (1)
03 Function code 0x03 (3) - Read Holding Registers
07 EE Starting address Physical: 0x07EE (2030)Logical: 0x07EF (2031)
00 02 Quantity 0x0002 (2)
A5 4A CRC 0xA54A (42314)

Response: 01 03 0c 43 3f 00 00 20 4c 49 54 48 49 55 4d d0 05

Part of Data Package Description Value
01 Slave address 0x01 (1)
03 Function code 0x03 (3) - Read Holding Registers
0C Byte count 0x0C (12)
43 3F 00 00 20 4C 49 54 48 49 55 4D Register value 0x433F (17215), 0x0000 (0), 0x204C (8268), 0x4954 (18772), 0x4849 (18505), 0x554D (21837)
D0 05 CRC 0xD005 (53253)

Here I am reading only 2 registers but I am getting 12 byte count.

I know that register 2030 has 4 bytes of data and 2031 has 8 bytes of data.

How do I handle this situation? I know length of each register that I am going to read but libmodbus computes response length based on request ( request for 2 bytes -> response will be of 9 bytes) but in my case it is 17 bytes in total.

sourabhburse avatar Apr 15 '23 07:04 sourabhburse

I have a similar issue https://github.com/stephane/libmodbus/issues/648 - just a little easier as my device (Dossena MV3DL 3-phase electricity meter) has all readable registers of the same non-standard length (3 bytes instead of 2). Since such strange devices seem to be more widespread (I thought mine was the only one, now there are two!) it might be a good idea to support them in some way. I hope to test modbus_send_raw_request soon, to see if it can be made to work in my setup (with MikroTik KNOT used as Modbus TCP to RTU gateway, and a few other more standard-compliant devices on the shared RS485 bus).

marekm72 avatar Jul 19 '23 12:07 marekm72