Skip to content

Commit d8835d5

Browse files
authored
Merge pull request #1334 from joergho/usbserial-suggest-interface-num
resource: udev: also suggest ID_USB_INTERFACE_NUM for USBResource
2 parents be28ac1 + c7b634b commit d8835d5

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

doc/configuration.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,15 @@ This allows identification through hot-plugging or rebooting.
109109
USBSerialPort:
110110
match:
111111
ID_SERIAL_SHORT: 'P-00-00682'
112+
ID_USB_INTERFACE_NUM: '00'
112113
speed: 115200
113114
114-
The example would search for a USB serial converter with the key
115-
``ID_SERIAL_SHORT`` and the value ``P-00-00682`` and use it with a baud rate
116-
of ``115200``.
117-
The ``ID_SERIAL_SHORT`` property is set by the ``usb_id`` builtin helper program.
115+
The example would search for a USB serial converter with a given serial number
116+
(``ID_SERIAL_SHORT`` = ``P-00-00682``) and use first interface
117+
(``ID_USB_INTERFACE_NUM`` = ``00``) with a baud rate of 115200.
118+
119+
The ``ID_SERIAL_SHORT`` and ``ID_USB_INTERFACE_NUM`` properties are set by the
120+
``usb_id`` builtin helper program.
118121

119122
Arguments:
120123
- match (dict): key and value pairs for a udev match, see `udev Matching`_

labgrid/resource/udev.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,22 @@ def suggest_match(self, device):
9191
suggestions.append({'@ID_PATH': path})
9292

9393
serial = self.device.properties.get('ID_SERIAL_SHORT')
94+
interface_num = self.device.properties.get('ID_USB_INTERFACE_NUM')
9495
if serial:
95-
suggestions.append({'ID_SERIAL_SHORT': serial})
96+
if interface_num is not None:
97+
suggestions.append({'ID_SERIAL_SHORT': serial,
98+
'ID_USB_INTERFACE_NUM': interface_num})
99+
else:
100+
suggestions.append({'ID_SERIAL_SHORT': serial})
96101
elif self.match.get('@SUBSYSTEM', None) == 'usb':
97102
serial = self._get_usb_device().properties.get('ID_SERIAL_SHORT')
103+
interface_num = self._get_usb_device().properties.get('ID_USB_INTERFACE_NUM')
98104
if serial:
99-
suggestions.append({'@ID_SERIAL_SHORT': serial})
105+
if interface_num is not None:
106+
suggestions.append({'@ID_SERIAL_SHORT': serial,
107+
'@ID_USB_INTERFACE_NUM': interface_num})
108+
else:
109+
suggestions.append({'@ID_SERIAL_SHORT': serial})
100110

101111
return meta, suggestions
102112

0 commit comments

Comments
 (0)