Skip to content

getRegisters() always adds 25ms delay #27

@SushiRemover

Description

@SushiRemover

i noticed that any getXXXFromRegister call takes ~31ms, so i dug deeper and found that in getRegisters() it adds a Delay of 25ms presumably for when the message fails and then wants to retry (correct me if im wrong).

Long story short: i changed

while (respSize != (numRegisters*2 + 5) && tries < 10)
    {
        // Send out the command (this adds the CRC)
        respSize = sendCommand(command, 8);
        tries++;

        delay(25);
    }

to

while (respSize != (numRegisters*2 + 5) && tries < 10)
    {
        // Send out the command (this adds the CRC)
        respSize = sendCommand(command, 8);
        tries++;

        if(respSize != (numRegisters*2 + 5)) {
            delay(25);
        }
    }

So it only adds the Delay if the response size is wrong, works for me, and now i have times of ~7ms per call.

You could argue that modbus needs these delays, but as for now i dont see anything where its needed, and the sendCommand() actively waits for a response with a delay of 1ms until it gets an answer anyways, so i see this as a worthy performance improvement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions