From 28c2e642cbf02d65e0f50ec45c590cd0eba0dcfb Mon Sep 17 00:00:00 2001 From: pha-odoo Date: Tue, 30 Jul 2019 12:38:00 +0000 Subject: [PATCH] [FIX] iot: bluetooth work with serial Using path such as '/dev/ttyUSB0' to connect to a serial port makes it impossible to use the bluetooth. We now use the locations in '/dev/serial/by-path' to connect to serial port, which does not affect bluetooth connections closes odoo/odoo#35302 Signed-off-by: Quentin Lejeune (qle) --- addons/hw_drivers/controllers/driver.py | 10 ++++------ addons/hw_drivers/drivers/SerialBaseDriver.py | 8 ++++++-- addons/hw_drivers/drivers/SerialScaleDriver.py | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/addons/hw_drivers/controllers/driver.py b/addons/hw_drivers/controllers/driver.py index 901d5ed2479..9a6764b7b23 100755 --- a/addons/hw_drivers/controllers/driver.py +++ b/addons/hw_drivers/controllers/driver.py @@ -18,7 +18,6 @@ from cups import Connection as cups_connection from glob import glob from base64 import b64decode from pathlib import Path -from serial.tools.list_ports import comports import socket from odoo import http, _ @@ -158,7 +157,7 @@ class Driver(Thread, metaclass=DriverMetaClass): """ On specific driver override this method to give connection type of device return string - possible value : direct - network - bluetooth + possible value : direct - network - bluetooth - serial """ return self._device_connection @@ -309,10 +308,9 @@ class Manager(Thread): def serial_loop(self): serial_devices = {} - for dev in comports(): - dev.identifier = dev.location - iot_device = IoTDevice(dev, 'serial') - serial_devices[dev.identifier] = iot_device + for identifier in glob('/dev/serial/by-path/*'): + iot_device = IoTDevice({'identifier': identifier, }, 'serial') + serial_devices[identifier] = iot_device return serial_devices def usb_loop(self): diff --git a/addons/hw_drivers/drivers/SerialBaseDriver.py b/addons/hw_drivers/drivers/SerialBaseDriver.py index 6253241e420..481a11d1309 100644 --- a/addons/hw_drivers/drivers/SerialBaseDriver.py +++ b/addons/hw_drivers/drivers/SerialBaseDriver.py @@ -74,6 +74,10 @@ class SerialDriver(Driver): self._status = {'status': self.STATUS_CONNECTING, 'message_title': '', 'message_body': ''} self._set_name() + @property + def device_identifier(self): + return self.dev['identifier'] + def _get_raw_response(connection): pass @@ -122,7 +126,7 @@ class SerialDriver(Driver): if self._connection and self._connection.isOpen(): self._do_action(data) else: - with serial_connection(self.dev.device, self._protocol) as connection: + with serial_connection(self.dev['identifier'], self._protocol) as connection: self._connection = connection self._do_action(data) @@ -130,7 +134,7 @@ class SerialDriver(Driver): """Continuously gets new measures from the device.""" try: - with serial_connection(self.dev.device, self._protocol) as connection: + with serial_connection(self.dev['identifier'], self._protocol) as connection: self._connection = connection self._status['status'] = self.STATUS_CONNECTED self._push_status() diff --git a/addons/hw_drivers/drivers/SerialScaleDriver.py b/addons/hw_drivers/drivers/SerialScaleDriver.py index c6673656c42..be04ce06384 100644 --- a/addons/hw_drivers/drivers/SerialScaleDriver.py +++ b/addons/hw_drivers/drivers/SerialScaleDriver.py @@ -221,7 +221,7 @@ class Toledo8217Driver(ScaleDriver): protocol = cls._protocol try: - with serial_connection(device.device, protocol, is_probing=True) as connection: + with serial_connection(device['identifier'], protocol, is_probing=True) as connection: connection.write(b'Ehello' + protocol.commandTerminator) time.sleep(protocol.commandDelay) answer = connection.read(8) @@ -297,7 +297,7 @@ class AdamEquipmentDriver(ScaleDriver): protocol = cls._protocol try: - with serial_connection(device.device, protocol, is_probing=True) as connection: + with serial_connection(device['identifier'], protocol, is_probing=True) as connection: connection.write(protocol.measureCommand + protocol.commandTerminator) # Checking whether writing to the serial port using the Adam protocol raises a timeout exception is about the only thing we can do. return True