Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getRegisters() always adds 25ms delay #27

Open
SushiRemover opened this issue Mar 5, 2024 · 0 comments
Open

getRegisters() always adds 25ms delay #27

SushiRemover opened this issue Mar 5, 2024 · 0 comments

Comments

@SushiRemover
Copy link

SushiRemover commented Mar 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant