Skip to content

New Modbus requests are sent before all are read  #69

@felipepardo87587

Description

@felipepardo87587

Great library! Many thanks to the author.

Just spent a lot of time debugging a strange problem, I am using a heavily modified version of this library to read about 300 registers from a PLC. Leaving this here in case it saves somebody the time.

BUG:
When the uC is busy and does not read the Serial buffer, a new Query may be sent before the buffer is emptied, this causes an offset, after which, the data is stored in the incorrect au16reg, because it's the response to a previous query. I modified the Modbus::query function as follows:

int8_t Modbus::query( modbus_t telegram ) {
port->flush(); //Waits for the transmission of outgoing serial data to complete.
while ( port->available() ) port->read(); //Clears RX buffer before sending a new query

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