From: Benjamin Braatz Date: Fri, 9 Apr 2021 08:57:46 +0000 (+0200) Subject: Set character timeout to 2 instead of 1.5 chars. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=f17ff6699f3734bd2086fd3b5282c8d560650198;p=graphit%2Fcontrolpi-modbus.git Set character timeout to 2 instead of 1.5 chars. --- diff --git a/controlpi_plugins/modbus.py b/controlpi_plugins/modbus.py index 3ea6c4a..75b9482 100644 --- a/controlpi_plugins/modbus.py +++ b/controlpi_plugins/modbus.py @@ -401,7 +401,7 @@ class ModbusMaster(BasePlugin): self._stopbits = serial.STOPBITS_TWO # 1.5 char and 3.5 char times for protocol timing # (according to Modbus specification): - self._t15 = 0.000750 + self._t15 = 0.001000 self._t35 = 0.001750 if self.conf['baudrate'] <= 19200: bit_per_char = 9 @@ -409,7 +409,7 @@ class ModbusMaster(BasePlugin): bit_per_char += 1 bit_per_char += self.conf['stopbits'] seconds_per_char = bit_per_char / self.conf['baudrate'] - self._t15 = 1.5 * seconds_per_char + self._t15 = 2.0 * seconds_per_char self._t35 = 3.5 * seconds_per_char # Queue for Modbus messages to be sent: self._queue: asyncio.Queue = asyncio.Queue() @@ -621,7 +621,6 @@ class ModbusMaster(BasePlugin): t35_task: asyncio.Task = asyncio.create_task( asyncio.sleep(self._t35)) try: - # First byte is awaited for response timeout: first_byte = await asyncio.wait_for( reader.read(1), self.conf['response timeout']) modbus_response += first_byte @@ -636,8 +635,6 @@ class ModbusMaster(BasePlugin): while True: t35_task = asyncio.create_task(asyncio.sleep(self._t35)) try: - # Subsequent bytes are only awaited for the time - # needed to transmit 1.5 characters: next_byte = await asyncio.wait_for( reader.read(1), self._t15) modbus_response += next_byte @@ -713,7 +710,7 @@ class ModbusSlave(BasePlugin): self._stopbits = serial.STOPBITS_TWO # 1.5 char and 3.5 char times for protocol timing # (according to Modbus specification): - self._t15 = 0.000750 + self._t15 = 0.001000 self._t35 = 0.001750 if self._baudrate <= 19200: bit_per_char = 11 @@ -721,7 +718,7 @@ class ModbusSlave(BasePlugin): self._stopbits == serial.STOPBITS_ONE): bit_per_char = 10 seconds_per_char = bit_per_char / self._baudrate - self._t15 = 1.5 * seconds_per_char + self._t15 = 2.0 * seconds_per_char self._t35 = 3.5 * seconds_per_char # Coils and registers: self._coils: Dict[int, bool] = {}