Skip to content

Character silent interval issue and Buffer overrun #99

@mgmidura

Description

@mgmidura

Running on SAMD21G18. I was encountering CRC errors randomly. After over a week of testing I convinced my self that it was not hardware and began noticing the bit timing on the modbus serial stream was violating the required quiet time. I began to look at the library. I believe that the _halfCharTimeInMicroSecond should be set to 50,000 for baud rates less than 19200. Once I made this change I have not seen any erros with over 116000 master slave transactions(16hrs running)

line 226 _halfCharTimeInMicroSecond = 5000000 / baudrate; // 0.5T.
Causes a truncation because value is too large for a uint16_t also I believe it is a typo because for 9600 baud it should be minimum of 3msec quiet time. Based on calculation on
line 230 _lastCommunicationTime = micros() + (_halfCharTimeInMicroSecond * MODBUS_FULL_SILENCE_MULTIPLIER);
the correct value should be 50000.

I also encountered random buffer overruns that would cause my program to lock up. I discovered that before transmit there was no check for this. I eliminated the lockups by adding check for transmission length greater than MODBUS_MAX_BUFFER
line 955 from if (length > 0) change to if ((length > 0) && (length < MODBUS_MAX_BUFFER))
line 981 from if (length > 0) change to if ((length > 0) && (length < MODBUS_MAX_BUFFER))

this eliminated any of my transmission overruns. I realize that the message response is lost in this case but it did not cause a issue for my application,

Thanks for your consideration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions