Skip to content
New issue

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

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

Already on GitHub? # to your account

Debug output shows roundtrip time in wrong unit #134

Open
HTKB-ZUC opened this issue Jan 10, 2025 · 0 comments
Open

Debug output shows roundtrip time in wrong unit #134

HTKB-ZUC opened this issue Jan 10, 2025 · 0 comments

Comments

@HTKB-ZUC
Copy link

When enabling debug mode and letting a write command run into a timeout, the displayed roundtrip time is displayed in ms but is not converted from the internal value stored in s. So the shown roundtrip time is 1000 times smaller as it actually was.

Code:

ser = serial.Serial(
    PORT, BAUDRATE, BYTESIZE, PARITY, stopbits=STOPBITS
)
dev = minimalmodbus.Instrument(ser, ADDRESS, debug=True)
dev.serial.timeout = X
dev.write_register(..., ...)

Output:

MinimalModbus debug mode. Will write to instrument (expecting 8 bytes back): ... (x bytes)
MinimalModbus debug mode. Clearing serial buffers for port ...
MinimalModbus debug mode. Sleeping 0.87 ms before sending. Minimum silent period: 1.75 ms, time since read: 0.88 ms.
MinimalModbus debug mode. Response from instrument: 10 90 04 1D C6 (5 bytes), roundtrip time: X ms. Timeout for reading: 200.0 ms.

Solution:

minimalmodbus/minimalmodbus.py

Lines 1510 to 1517 in 785262d

text = (
"Response from instrument: {}, roundtrip time: {:.1f} ms."
" Timeout for reading: {:.1f} ms.\n"
).format(
_describe_bytes(answer),
roundtrip_time,
timeout_time,
)

Change roundtrip_time to: roundtrip_time * _SECONDS_TO_MILLISECONDS

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

No branches or pull requests

1 participant