Skip to content

Commit cfea7d0

Browse files
authored
Merge pull request pyserial#141 from eliotb/list_ports_interfaces
linux: list_ports use interface path for multi location
2 parents b8dc572 + 6d3a7cb commit cfea7d0

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

serial/tools/list_ports_linux.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,28 @@ def __init__(self, device):
3434
self.subsystem = None
3535
# check device type
3636
if self.subsystem == 'usb-serial':
37-
self.usb_device_path = os.path.dirname(os.path.dirname(self.device_path))
37+
self.usb_interface_path = os.path.dirname(self.device_path)
3838
elif self.subsystem == 'usb':
39-
self.usb_device_path = os.path.dirname(self.device_path)
39+
self.usb_interface_path = self.device_path
4040
else:
41-
self.usb_device_path = None
41+
self.usb_interface_path = None
4242
# fill-in info for USB devices
43-
if self.usb_device_path is not None:
43+
if self.usb_interface_path is not None:
44+
self.usb_device_path = os.path.dirname(self.usb_interface_path)
45+
46+
try:
47+
num_if = int(self.read_line(self.usb_device_path, 'bNumInterfaces'))
48+
except ValueError:
49+
num_if = 1
50+
4451
self.vid = int(self.read_line(self.usb_device_path, 'idVendor'), 16)
4552
self.pid = int(self.read_line(self.usb_device_path, 'idProduct'), 16)
4653
self.serial_number = self.read_line(self.usb_device_path, 'serial')
47-
self.location = os.path.basename(self.usb_device_path)
54+
if num_if > 1: # multi interface devices like FT4232
55+
self.location = os.path.basename(self.usb_interface_path)
56+
else:
57+
self.location = os.path.basename(self.usb_device_path)
58+
4859
self.manufacturer = self.read_line(self.usb_device_path, 'manufacturer')
4960
self.product = self.read_line(self.usb_device_path, 'product')
5061
self.interface = self.read_line(self.device_path, 'interface')

0 commit comments

Comments
 (0)