serhmarch / ModbusTools

ModbusTools are cross-platform (Windows, Linux) Modbus simulator tools (client and server) with GUI to work with Modbus protocol (TCP,RTU,ASCII)
GNU General Public License v3.0
42 stars 4 forks source link

Error in CRC calc #10

Open ogry opened 1 week ago

ogry commented 1 week ago

Hello, I'm trying to communicate with a Voltronic clone hybrid inverter. PIP protocol does no seems to get fine, so I'm now in the modbus route.

I'm trying to use your wonderful software to exploring the possibilities. I found that I can read registers directly from inverter without the PIP parser, much fast and secure than using simply serial commands. This way, when I send via USB/RS232 (as ModBus RTU), using CRC-16/MODBUS as seeing here

05 03 11 97 00 01 4C 5C (read 1 registry from 4503, query AC input main frequency)

and I get back in response (from inverter)

05 03 02 F4 01 CE 84

A 2 byte response where 01f4 is exactly what I expected, 500 (50.0 Hz)

But, If I try this in your (awesome, really awesome!) package setting the scanner to get only one result I get this:

11.10.2024 02:07:10.746 'Scanner': Start scanning
11.10.2024 02:07:10.746 'Scanner': Begin scanning 'Scanner RTU:/dev/ttyUSB2:2400:8N1'
11.10.2024 02:07:10.749 'Scanner Scanner RTU:/dev/ttyUSB2:2400:8N1': Tx: 05 03 11 97 00 01 31 5E 
11.10.2024 02:07:11.067 'Scanner Scanner RTU:/dev/ttyUSB2:2400:8N1': Rx: B4 03 11 97 00 01 31 
11.10.2024 02:07:11.068 'Scanner RTU:/dev/ttyUSB2:2400:8N1': Unit=5, Error (1000401): RTU. Wrong CRC
11.10.2024 02:07:11.068 'Scanner': End scanning 'Scanner RTU:/dev/ttyUSB2:2400:8N1'
11.10.2024 02:07:11.069 'Scanner': Finish scanning

As you can see, the CRC is not the same, and thus, the response is invalid.

It is possible to change the CRC algorithm to make this work?

May be a good enhancement, IMHO, to let the user to choose the CRC algorithm

Many thanks!!

serhmarch commented 1 week ago

Hello. I have identified the same problem and it is not in the CRC-16 Modbus checksum at all, but in operation with serial port. It will take some time to find and fix it. But I tried the previous v0.1.5 version of the program and it worked well without this problem (I was working on Windows, I did not check Linux). For your convenience, I added a release for the v0.1.5 version so you can try it out as well (temporarily).

serhmarch commented 1 week ago

Thank you for bug report. Bug was found and fixed. v0.3.2 release was renewed. Bug was within ModbusLib sub-project.