1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#
# GitHub Pull Request: https://github.com/pyserial/pyserial/pull/778
# From cc99655f0969486eab63c80add5911c246ded0f8 Mon Sep 17 00:00:00 2001
# From: Poul-Henning Kamp <phk@FreeBSD.org>
# Date: Mon, 21 Oct 2024 09:50:28 +0000
# Subject: [PATCH 1/2] Implement FreeBSD list_ports using devinfo(8)
#
--- serial/tools/list_ports_freebsd.py.orig 2025-09-29 15:56:08 UTC
+++ serial/tools/list_ports_freebsd.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+#
+# This is a module that gathers a list of serial ports including details on
+# GNU/Linux systems.
+#
+# This file is part of pySerial. https://github.com/pyserial/pyserial
+# (C) 2011-2015 Chris Liechti <cliechti@gmx.net>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+from __future__ import absolute_import
+
+import glob
+import os
+
+import subprocess
+
+from serial.tools import list_ports_common
+
+class DevInfo(list_ports_common.ListPortInfo):
+ def __init__(self, line):
+ self.props = {}
+ for n, i in enumerate(line.split()):
+ if n == 0:
+ self.description = i
+ continue
+ f = i.split('=', maxsplit=1)
+ if len(f) == 2:
+ self.props[f[0]] = f[1]
+ else:
+ self.props[f[0]] = True
+ self.device = "/dev/cua" + self.props["ttyname"]
+ if "vendor" in self.props:
+ self.vid = int(self.props["vendor"], 16)
+ self.manufacturer = self.vid
+ if "product" in self.props:
+ self.pid = int(self.props["product"], 16)
+ if "sernum" in self.props:
+ self.serial_number = self.props["sernum"]
+ if "ugen" in self.props:
+ self.location = self.props["ugen"]
+ self.subsystem = "usb"
+ self.apply_usb_info()
+ else:
+ self.subsystem = "uart"
+ self.hwid = self.description
+
+ def usb_description(self):
+ return self.props["ugen"]
+
+def comports(include_links=False):
+ x = subprocess.run(["/usr/sbin/devinfo", "-rv"], capture_output=True)
+ seen = set()
+ for line in x.stdout.decode('utf-8').split('\n'):
+ if "ttyname" in line:
+ d = DevInfo(line)
+ seen.add(d.device)
+ yield d
+ for fn in sorted(glob.glob("/dev/cua*[!.init][!.lock]")):
+ if fn not in seen:
+ d = DevInfo(fn[5:] + " ttyname=" + fn[8:])
+ seen.add(d.device)
+ yield d
+
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# test
+if __name__ == '__main__':
+ for info in sorted(comports()):
+ print("{0}: {0.subsystem}".format(info))
# From 119cfbe54dcdbd6b4ffa87e7f4cc8d9163cc10b6 Mon Sep 17 00:00:00 2001
# From: Poul-Henning Kamp <phk@FreeBSD.org>
# Date: Tue, 22 Oct 2024 19:08:10 +0000
# Subject: [PATCH 2/2] Use absolute path to devinfo(8)
--- serial/tools/list_ports_posix.py.orig 2025-09-29 15:59:42 UTC
+++ serial/tools/list_ports_posix.py
@@ -50,11 +50,7 @@ elif plat[:3] == 'bsd' or plat[:7] == 'freebsd':
return [list_ports_common.ListPortInfo(d) for d in devices]
elif plat[:3] == 'bsd' or plat[:7] == 'freebsd':
- def comports(include_links=False):
- devices = glob.glob('/dev/cua*[!.init][!.lock]')
- if include_links:
- devices.extend(list_ports_common.list_links(devices))
- return [list_ports_common.ListPortInfo(d) for d in devices]
+ from serial.tools.list_ports_freebsd import comports
elif plat[:6] == 'netbsd': # NetBSD
def comports(include_links=False):
|