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

Response timeout of RTU master #86

Open
ondrej1024 opened this issue Jan 29, 2024 · 4 comments
Open

Response timeout of RTU master #86

ondrej1024 opened this issue Jan 29, 2024 · 4 comments

Comments

@ondrej1024
Copy link

Description

I just need an information which I couldn't find in the docs.
What is the default response timeout of the RTU master and how can it be changed ?

Thanks, Ondrej

Reproduction steps

None

MicroPython version

v.1.20

MicroPython board

Raspberry Pico

MicroPython Modbus version

None

Relevant log output

No response

User code

No response

Additional informations

No response

@beyonlo
Copy link

beyonlo commented Jan 29, 2024

Hello @ondrej1024

Here an example https://github.com/GimmickNG/pycopy-modbus/blob/ad38bb74d2da0a4b22c518567bbee44647da7afd/examples/rtu_host_example.py#L34 where show that the default is 120 ms, and you can to change the timeout just changing the read_timeout for a new value (in ms). It works, I'm using it, changing to 200ms, 300ms, 1000 ms in my tests.

Ps1: I don't know if that works in the last version of ModBus lib because I'm using the async version #56 that will be merged soon!

Ps2: that example that I linked still is not in the official examples because the PR #56 is not finished yet.

But I agree, it is important to put in the docs what is the default timeout for the Master RTU and how to change it. Maybe @brainelectronics can to put that information in the docs when the asyncio version is merged!

@ondrej1024
Copy link
Author

Thanks for your answer.
I had a look in serial.py of the latest release 2.3.7 and found that class Serial() has no parameter read_timeout. So I guess it is not yet available and I have to wait for the merge that you mentioned to be completed.

@ondrej1024
Copy link
Author

Do you know where the default timeout is defined? I checked the source code but couldn't find it.

@ondrej1024
Copy link
Author

After some more digging, eventually I found the code which is responsible for the timeout.

It is in file serial.py function _uart_read() and it is determined by this loop:


        # TODO: use some kind of hint or user-configurable delay
        #       to determine this loop counter
        for x in range(1, 120):

However, the value of 120 here is not the number of ms but the number of _inter_frame_delay which depends on the baudrate. So the default timeout actually is not 120ms but depends on the baudrate. At 9600 baud it is about 500ms.

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

2 participants