serial.write should have a blocking wait if the serial port is busy

This commit is contained in:
Fabio Manganiello 2018-09-05 01:59:55 +02:00
parent 938526d521
commit 0537d1fcac

View file

@ -131,9 +131,7 @@ class SerialPlugin(GpioSensorPlugin):
if isinstance(data, str):
data = data.encode('utf-8')
try:
serial_available = self.serial_lock.acquire(timeout=2)
if serial_available:
with self.serial_lock:
try:
ser = self._get_serial()
except:
@ -142,8 +140,6 @@ class SerialPlugin(GpioSensorPlugin):
self.logger.info('Writing {} to {}'.format(data, self.device))
ser.write(data)
finally:
self.serial_lock.release()
# vim:sw=4:ts=4:et: