Skip to content

Commit

Permalink
fix: Serial changes the receiving interval by baudrate.(pymodbus-dev#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sunlinjie committed Jan 31, 2023
1 parent 66d9055 commit 059b14d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pymodbus/client/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,15 @@ def __init__(
self.socket = None

self.last_frame_end = None

self._t0 = float((1 + 8 + 2)) / self.params.baudrate
self.recv_interval = 100 * self._t0
self.recv_interval = round(self.recv_interval, 2) + 0.01
self.recv_interval = self.recv_interval if self.recv_interval < 0.05 else 0.05 # s
if isinstance(self.framer, ModbusRtuFramer):
if self.params.baudrate > 19200:
self.silent_interval = 1.75 / 1000 # ms
else:
self._t0 = float((1 + 8 + 2)) / self.params.baudrate
self.inter_char_timeout = 1.5 * self._t0
self.silent_interval = 3.5 * self._t0
self.silent_interval = round(self.silent_interval, 6)
Expand Down Expand Up @@ -304,7 +308,7 @@ def _wait_for_data(self):
if available and available != size:
more_data = True
size = available
time.sleep(0.01)
time.sleep(self.recv_interval)
return size

def recv(self, size):
Expand Down

0 comments on commit 059b14d

Please sign in to comment.