From ea1812b44c415c113e9d68638d200e2bedf39095 Mon Sep 17 00:00:00 2001 From: Joerg Hofrichter Date: Fri, 1 Mar 2024 08:35:09 +0100 Subject: [PATCH 1/2] resource: udev: also suggest ID_USB_INTERFACE_NUM for USBResource A USB serial device often provides multiple interfaces for the same serial number. In these cases it is not possible to distinguish the interfaces solely based on the serial number (ID_SERIAL_SHORT). However, if additionally the interface number (ID_USB_INTERFACE_NUM) is provided, it is possible to distinguish all interfaces without the need of using the full device path (ID_PATH). Example: (...) === suggested matches === (...) USBSerialPort: match: ID_SERIAL_SHORT: ABCDEF00001 ID_USB_INTERFACE_NUM: '00' (...) === suggested matches === (...) USBSerialPort: match: ID_SERIAL_SHORT: ABCDEF00001 ID_USB_INTERFACE_NUM: '01' Signed-off-by: Joerg Hofrichter --- labgrid/resource/udev.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/labgrid/resource/udev.py b/labgrid/resource/udev.py index f66a0ed21..0b4354bca 100644 --- a/labgrid/resource/udev.py +++ b/labgrid/resource/udev.py @@ -91,12 +91,22 @@ def suggest_match(self, device): suggestions.append({'@ID_PATH': path}) serial = self.device.properties.get('ID_SERIAL_SHORT') + interface_num = self.device.properties.get('ID_USB_INTERFACE_NUM') if serial: - suggestions.append({'ID_SERIAL_SHORT': serial}) + if interface_num is not None: + suggestions.append({'ID_SERIAL_SHORT': serial, + 'ID_USB_INTERFACE_NUM': interface_num}) + else: + suggestions.append({'ID_SERIAL_SHORT': serial}) elif self.match.get('@SUBSYSTEM', None) == 'usb': serial = self._get_usb_device().properties.get('ID_SERIAL_SHORT') + interface_num = self._get_usb_device().properties.get('ID_USB_INTERFACE_NUM') if serial: - suggestions.append({'@ID_SERIAL_SHORT': serial}) + if interface_num is not None: + suggestions.append({'@ID_SERIAL_SHORT': serial, + '@ID_USB_INTERFACE_NUM': interface_num}) + else: + suggestions.append({'@ID_SERIAL_SHORT': serial}) return meta, suggestions From c7b634b806b344aca4ff925f6ff621d0b3ecce9c Mon Sep 17 00:00:00 2001 From: Joerg Hofrichter Date: Fri, 1 Mar 2024 08:53:33 +0100 Subject: [PATCH 2/2] resource: udev: also suggest ID_USB_INTERFACE_NUM - docu update Signed-off-by: Joerg Hofrichter --- doc/configuration.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index 4a81d70cf..d3cb73dc9 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -109,12 +109,15 @@ This allows identification through hot-plugging or rebooting. USBSerialPort: match: ID_SERIAL_SHORT: 'P-00-00682' + ID_USB_INTERFACE_NUM: '00' speed: 115200 -The example would search for a USB serial converter with the key -``ID_SERIAL_SHORT`` and the value ``P-00-00682`` and use it with a baud rate -of ``115200``. -The ``ID_SERIAL_SHORT`` property is set by the ``usb_id`` builtin helper program. +The example would search for a USB serial converter with a given serial number +(``ID_SERIAL_SHORT`` = ``P-00-00682``) and use first interface +(``ID_USB_INTERFACE_NUM`` = ``00``) with a baud rate of 115200. + +The ``ID_SERIAL_SHORT`` and ``ID_USB_INTERFACE_NUM`` properties are set by the +``usb_id`` builtin helper program. Arguments: - match (dict): key and value pairs for a udev match, see `udev Matching`_