[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) <qle@odoo.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user