Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource: udev: also suggest ID_USB_INTERFACE_NUM for USBResource #1334

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`_
Expand Down
14 changes: 12 additions & 2 deletions labgrid/resource/udev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading