'maximum': 2,
'default': 1},
'retries': {'type': 'integer',
- 'default': 2},
- 'response timeout': {'type': 'number',
- 'default': 0.2},
- 'turnaround delay': {'type': 'number',
- 'default': 0.1}},
+ 'default': 2}},
'required': ['device']}
def process_conf(self) -> None:
self.conf['stopbits'] = 1
if 'retries' not in self.conf:
self.conf['retries'] = 2
- if 'response timeout' not in self.conf:
- self.conf['response timeout'] = 0.2
- if 'turnaround delay' not in self.conf:
- self.conf['turnaround delay'] = 0.1
# Constants from serial for parity and stop bits:
self._parity = serial.PARITY_EVEN
if self.conf['parity'] == 'odd':
writer.write(request)
if slave == 0:
# Broadcast => just wait for delay and finish:
- await asyncio.sleep(self.conf['turnaround delay'])
+ await asyncio.sleep(0.1)
break
# Read response:
response = b''
while True:
try:
response += await asyncio.wait_for(
- reader.read(1), self.conf['response timeout'])
+ reader.read(1), 0.2)
crc.update(response[length])
+ length += 1
except asyncio.TimeoutError:
break
- length += 1
# Update expected length based on function:
if (length == 2 and
(response[1] == 0x05 or response[1] == 0x06 or
expected_length = 8
length = 0
while True:
- request += await reader.read(1)
- crc.update(request[length])
- length += 1
+ try:
+ request += await asyncio.wait_for(
+ reader.read(1), 0.2)
+ crc.update(request[length])
+ length += 1
+ except asyncio.TimeoutError:
+ break
# Update expected length based on function:
if length == 2:
if request[1] == 0x0F or request[1] == 0x10: