Skip to content

Commit 64723a5

Browse files
authored
Merge pull request #1928 from aparcar/labgrid-suggest-wch-ch34x
labgrid-suggest: add support for WCH CH34x
2 parents 14e6ec8 + cdab2e8 commit 64723a5

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

labgrid/resource/udev.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ def suggest_match(self, device):
107107
else:
108108
suggestions.append({'@ID_SERIAL_SHORT': serial})
109109

110+
# Multi-port USB serial adapters (e.g. WCH CH34x, FTDI multi) expose
111+
# several ports under one USB interface, so ID_PATH / ID_SERIAL_SHORT /
112+
# ID_USB_INTERFACE_NUM are identical for every port and the suggestions
113+
# above are ambiguous. The kernel's per-port `port_number` sysfs attr on
114+
# an ancestor is stable across re-enumeration; fold it into each
115+
# suggestion (as an `@` ancestor match) so every port is unique.
116+
for ancestor in self.device.ancestors:
117+
if ancestor.attributes.get('port_number') is not None:
118+
port_number = ancestor.attributes.asstring('port_number')
119+
for suggestion in suggestions:
120+
suggestion['@port_number'] = port_number
121+
meta['port_number'] = port_number
122+
break
123+
110124
return meta, suggestions
111125

112126
def try_match(self, device):

0 commit comments

Comments
 (0)