Skip to content

Commit ea1812b

Browse files
committed
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 <joerg.hofrichter@ni.com>
1 parent be28ac1 commit ea1812b

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

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)