forked from platypush/platypush
serial.write should have a blocking wait if the serial port is busy
This commit is contained in:
parent
938526d521
commit
0537d1fcac
1 changed files with 8 additions and 12 deletions
|
@ -131,19 +131,15 @@ class SerialPlugin(GpioSensorPlugin):
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = data.encode('utf-8')
|
data = data.encode('utf-8')
|
||||||
|
|
||||||
try:
|
with self.serial_lock:
|
||||||
serial_available = self.serial_lock.acquire(timeout=2)
|
try:
|
||||||
if serial_available:
|
ser = self._get_serial()
|
||||||
try:
|
except:
|
||||||
ser = self._get_serial()
|
time.sleep(1)
|
||||||
except:
|
ser = self._get_serial(reset=True)
|
||||||
time.sleep(1)
|
|
||||||
ser = self._get_serial(reset=True)
|
|
||||||
|
|
||||||
self.logger.info('Writing {} to {}'.format(data, self.device))
|
self.logger.info('Writing {} to {}'.format(data, self.device))
|
||||||
ser.write(data)
|
ser.write(data)
|
||||||
finally:
|
|
||||||
self.serial_lock.release()
|
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue