emelianov / modbus-esp8266

Most complete Modbus library for Arduino. A library that allows your Arduino board to communicate via Modbus protocol, acting as a master, slave or both. Supports network transport (Modbus TCP) and Serial line/RS-485 (Modbus RTU). Supports Modbus TCP Security for ESP8266/ESP32.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CRC validation

elockman opened this issue · comments

Thanks for the great library.

I am using Modbus RTU (Master) to read a slave device. It appears some of my data is corrupted. I suspect the CRC is incorrect also. I do not see CRC checked in any of the examples. Is there an easy way to validate CRCs?

For example, readcoil and readHreg return u16, if they checked CRC internally, they could return a bool indicating success.

How are others implementing the CRC validation with this library?

CRC check is part of ModbusRTU standard. So each frame is transferred with CRC in two last bytes. For sure the library and any ModbusRTU device implements CRC checking. The library just drops frames with invalid CRC.
The library calls are async. read* \ write* methods just sends request. Returned value is result of sent operation. That is on exit the final transaction result is undetermined yet. Response from slave device processed by task().
Another note that if there is CRC error on source or destination happens the transaction will got just timeout error. It's by ModbusRTU nature.