CMB27 / ModbusRTUSlave

This is an Arduino library that implements the slave/server logic of the Modbus RTU protocol.
MIT License
58 stars 14 forks source link

Parity isn't working #8

Closed Max89D closed 1 year ago

Max89D commented 1 year ago

Hello,

Nice lib you've made, I really like it. I had some issues trying to communicate in 8E1. I constantly had CRC errors on my debug Modbus RTU console. I've figure out that the config was in fact not 8E1 but 8N1 (as by default). I've had a look at the code and couldn't find where the parity check is done or written. Is it done somewhere else ? I only had a look in the begin method. Could you resolve this ?

I'm sorry I couldn't get directly into your code and try resolve.

Regards, Maxim

CMB27 commented 1 year ago

Parity is handled by the Stream object handed to the library in the [constructor](https://github.com/CMB27/ModbusRTUSlave/wiki/ModbusRTUSlave()). The library itself does not check parity. The examples use SoftwareSerial as the stream object, which only supports 8N1. However, if you use a HardwareSerial (Serial) object, 8E1 is supported.

The library needs to know the configuration being used in order to properly handle timing when receiving messages.

Max89D commented 1 year ago

Thank you very much, it"s very interesting. I'll try with Serial.

Max89D commented 1 year ago

I confirm it works with the Serial library but you have to set it in the begin method as following: Serial.begin(baud, SERIAL_8E1);

CMB27 commented 1 year ago

That is how it works.