Skip to content

Commit 6d3a7cb

Browse files
committed
linux: list_ports use interface path for multi location
On devices with multiple serial interfaces, like FT4232, the usb_device path is the same for all interfaces, so hwid does not uniquely identify the interface. So in this case use the basename of the interface directory. Single interface: hwid: USB VID:PID=0403:6015 SER=DN00RHW0 LOCATION=3-1.1 Multiple interface: hwid: USB VID:PID=0403:6011 SER=FT97WK0I LOCATION=3-1.2:1.1 Signed-off-by: Eliot Blennerhassett <[email protected]>
1 parent d389f8a commit 6d3a7cb

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
@@ -28,17 +28,28 @@ def __init__(self, device):
2828
self.subsystem = None
2929
# check device type
3030
if self.subsystem == 'usb-serial':
31-
self.usb_device_path = os.path.dirname(os.path.dirname(self.device_path))
31+
self.usb_interface_path = os.path.dirname(self.device_path)
3232
elif self.subsystem == 'usb':
33-
self.usb_device_path = os.path.dirname(self.device_path)
33+
self.usb_interface_path = self.device_path
3434
else:
35-
self.usb_device_path = None
35+
self.usb_interface_path = None
3636
# fill-in info for USB devices
37-
if self.usb_device_path is not None:
37+
if self.usb_interface_path is not None:
38+
self.usb_device_path = os.path.dirname(self.usb_interface_path)
39+
40+
try:
41+
num_if = int(self.read_line(self.usb_device_path, 'bNumInterfaces'))
42+
except ValueError:
43+
num_if = 1
44+
3845
self.vid = int(self.read_line(self.usb_device_path, 'idVendor'), 16)
3946
self.pid = int(self.read_line(self.usb_device_path, 'idProduct'), 16)
4047
self.serial_number = self.read_line(self.usb_device_path, 'serial')
41-
self.location = os.path.basename(self.usb_device_path)
48+
if num_if > 1: # multi interface devices like FT4232
49+
self.location = os.path.basename(self.usb_interface_path)
50+
else:
51+
self.location = os.path.basename(self.usb_device_path)
52+
4253
self.manufacturer = self.read_line(self.usb_device_path, 'manufacturer')
4354
self.product = self.read_line(self.usb_device_path, 'product')
4455
self.interface = self.read_line(self.device_path, 'interface')

0 commit comments

Comments
 (0)