-
Notifications
You must be signed in to change notification settings - Fork 0
/
idx.html
230 lines (208 loc) · 10.6 KB
/
idx.html
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="pragma" content="no-cache; charset=utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>lscom - list of available serial ports</title>
<style type="text/css">
body {background-color:#FFFFDD}
//td {vertical-align:top;padding:0px;margin:0px}
p {text-align:justify;margin-bottom:0px}
td.gchord {font-size:75%;font-weight:bold;padding:0px;margin:0px;padding-top:0px;padding-right:3px;text-align:left;font-family:verdana,arial;color:#888888;position:relative;top:3px}
td.gtxt {text-align:left}
.dettitle {border-bottom:1px lightgray dashed}
.dettitle2 {border-bottom:1px lightgray dashed}
h2 {margin-top:20px; background-color:xgray}
h3 {background-color:xyellow;margin-top:30px;text-decoration:underline}
h4 {padding-left:0px;margin-left:0px;text-decoration:underline;color:#333333}
ul {margin-top:0px;padding-top:0px}
.ref {color:gray}
.gr {color:gray}
.grsm {color:gray;font-size:80%}
.err {color:red;font-weight:bold}
a {text-color:blue;text-decoration:underline}
a:HOVER {border-bottom:1px blue;color:red}
a.index {text-decoration:none}
a.index:HOVER {text-decoration:underline;color:red}
.preFile {background-color:lightgray;padding:0.5em}
td.imgthumb {vertical-align:top;padding:5px;font-size:80%}
img.ico {width:12px;height:12px;overflow:visible;position:relative;margin-top:-5px}
.imginc {max-width:100%;max-height:80vh}
.imginccap {text-align:left;padding-bottom:0.5em}
div.code {margin:0px;padding:0px;padding-left:30px;}
.code {font-family:courier,fixed;color:green;}
.cmd {font-family:courier,fixed;color:red;background-color:#FFEEDD;font-weight:bold;white-space:pre-wrap;padding-left:0.5em;;padding-right:0.5em;padding-top:0.5em;padding-bottom:0.5em}
.cmd::first-line {color:darkred;}
.cmd::before {content:'> ';}
.cmdresp {font-family:courier,fixed;color:blue;background-color:#EEEEFF;white-space:pre-wrap;padding-left:0.5em;;padding-right:0.5em;}
.cmdresp::first-line {color:darkblue;}
.cmdresp::before {content:' ';}
.comm {font-family:courier,fixed;color:red;background-color:#FFEEDD;font-weight:bold;white-space:pre-wrap;padding-left:0.5em;;padding-right:0.5em;}
.comm::first-line {color:darkred;}
.comm::before {content:'> ';}
.commresp {font-family:courier,fixed;color:blue;background-color:#EEEEFF;white-space:pre-wrap;padding-left:0.5em;;padding-right:0.5em;}
.commresp::first-line {color:darkblue;}
.commresp::before {content:'< ';}
.bang {font-weight:bold;color:red}
// unsupported by everything except apple, so far
//@media screen and (inverted-colors: inverted) {
//.cmd {background-color:#0000CC;color:lightblue;}
//.cmd::first-line: {color:blue}
//.cmdresp {background-color:#CC0000;color:lightred}
//.cmdresp::first-line: {color:red}
//}
@media print{
body {font-size:80%}
.noprint {display:none;visibility:hidden}
.xnopbr {page-break-inside:avoid}
td.gchord: {color:black}
.nopbr {}
.preFile {background-color:white;border:1px dotted black}
}
</style>
<meta property="og:title" content="lscom - list of available serial ports" />
<meta property="og:type" content="website" />
<meta property="og:x-url" content="http://:" />
<meta property="og:description" content="list of available serial ports, in python" />
</head>
<body>
<h1>lscom - list of available serial ports</h1><hr class="noprint" /><div class="noprint"><a class="index indexlev2" href="#Why" title="">Why</a><br /><a class="index indexlev2" href="#How" title="How">How</a><br /> <small><a class="index indexlev3" href="#usage" title="How.usage">usage</a></small><br /> <small><a class="index indexlev3" href="#Windowsspecifics" title="How.Windows specifics">Windows specifics</a></small><br /><a class="index indexlev2" href="#Files" title="Files">Files</a><br /><a class="index indexlev2" href="#Todo" title="Todo">Todo</a><br /></div><hr /><a name="Why"></a><h2>Why
</h2>
<p>
To see the serial ports present in the system.
</p>
<hr /><a name="How"></a><h2>How
</h2>
<p>
A script in python, using <span class="code">serial.tools.list_ports</span> to enumerate the ports, checking <span class="code">/dev</span>, <span class="code">/dev/serial/by-id</span>, and <span class="code">/dev/serial/by-path</span> for symlinks
(some symlinks were not present in the list_ports call), optionally calling <span class="code">fuser</span> to check if the port is opened.
</p>
<a name="usage"></a><h3> usage
</h3>
<pre class="preFile">List serial ports available on the machine.
Uses python serial.tools.list_ports.comports() scan, augmented with other lookups
Usage: /usr/bin/lscom [-l] [-h]
Where:
-l list format, one port per line
-L list by alternative scan
-LD list by alternative scan, with device paths
-N skip alternative scan
-a show all port properties, alphabetically, no filtering
-o show process that has the port opened (call fuser -v)
-noexec do not execute any commands as helpers (rfcomm, bluetoothctl)
-d debug, trace the operations performed
-h help
</pre><p>
In normal use, for each port the output is:
<ul><li> the main device
</li><li> the aliases/symlinks if they exist
</li><li> with <span class="code">-o</span> option, the OPENED BY: shows the process that has the device opened
</li><li> various properties (name, subsystem, hardware id, device paths...)
</li><li> for rfcomm ports (serial over bluetooth), the address and channel are attempted to get from /sys, then the <span class="code">rfcomm</span> and <span class="code">bluetoothctl</span> commands are called to get details (unless forbidden by <span class="code">-noexec</span> option)
</li><li> duplicate values are trimmed from the list for better readability (can be disabled by <span class="code">-a</span>)
</li></ul></p>
<div class="cmd">lscom -o</div><pre class=""> name: rfcomm0
BLUETOOTH
BT_address: 00:15:a3:15:32:1c
BT_channel: 1
rfcomm: rfcomm0: B8:27:EB:BC:D8:03 -> 00:15:A3:15:32:1C channel 1 closed
bluetoothctl: Device 00:15:A3:15:32:1C UM34C
/dev/ttyAMA0
= /dev/serial1
OPENED BY: hciattach flags=F.... PID=715 USER=root PORT=/dev/ttyAMA0:
name: ttyAMA0
subsystem: amba
hwid: 3f201000.serial
device_path: /sys/devices/platform/soc/3f201000.serial
/dev/ttyUSB0
= /dev/ttyMarlin
= /dev/ttyUSB.3
= /dev/serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0
= /dev/serial/by-id/usb-Silicon_Labs_CP2102_Marlin_250000n8_0001-if00-port0
OPENED BY: octoprint flags=F.... PID=905 USER=pi PORT=/dev/ttyUSB0:
name: ttyUSB0
subsystem: usb-serial
product: CP2102 Marlin 250000n8
manufacturer: Silicon Labs
serial_number: 0001
VID:PID: 10c4:ea60
location: 1-1.3
hwid: USB VID:PID=10C4:EA60 SER=0001 LOCATION=1-1.3
device_path: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0
usb_device_path: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3
usb_interface_path: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0
/dev/ttyUSB1
= /dev/ttyUSB.5
= /dev/ttyLoadcell
= /dev/serial/by-path/platform-3f980000.usb-usb-0:1.5:1.0-port0
= /dev/serial/by-id/usb-Silicon_Labs_CP2102_filament_load_cell_interface_57600_0001-if00-port0
name: ttyUSB1
subsystem: usb-serial
product: CP2102 filament load cell interface 57600
manufacturer: Silicon Labs
serial_number: 0001
VID:PID: 10c4:ea60
location: 1-1.5
hwid: USB VID:PID=10C4:EA60 SER=0001 LOCATION=1-1.5
device_path: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0/ttyUSB1
usb_device_path: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5
usb_interface_path: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5:1.0
</pre><div class="cmd">lscom -l</div><pre class=""> /dev/rfcomm0|rfcomm0|None|n/a
/dev/ttyAMA0|ttyAMA0|amba|3f201000.serial
/dev/ttyUSB0|ttyUSB0|usb-serial|USB VID:PID=10C4:EA60 SER=0001 LOCATION=1-1.3
/dev/ttyUSB1|ttyUSB1|usb-serial|USB VID:PID=10C4:EA60 SER=0001 LOCATION=1-1.5
/dev/ttyUSB.3|ttyUSB.3|None|LINK=/dev/ttyUSB0 LINK=/dev/ttyUSB0
/dev/ttyUSB.5|ttyUSB.5|None|LINK=/dev/ttyUSB1 LINK=/dev/ttyUSB1
</pre><a name="Windowsspecifics"></a><h3> Windows specifics
</h3>
<p>
The code is written primarily for linux, however it works also for Windows.
Under Windows, the product string is generic, from the driver instead from the device.
</p>
<p>
The same device that looks under linux as
<pre class=""> /dev/ttyUSB0
= /dev/ttyUSB.2.3.1
= /dev/ttyArdu
= /dev/serial/by-path/platform-3f980000.usb-usb-0:1.2.3.1:1.0-port0
= /dev/serial/by-id/usb-Silicon_Labs_CP2102_Arduino_USB-serial_interface_0001-if00-port0
name: ttyUSB0
subsystem: usb-serial
product: CP2102 Arduino USB-serial interface
manufacturer: Silicon Labs
serial_number: 0001
VID:PID: 10c4:ea60
location: 1-1.2.3.1
hwid: USB VID:PID=10C4:EA60 SER=0001 LOCATION=1-1.2.3.1
device_path: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2.3/1-1.2.3.1/1-1.2.3.1:1.0/ttyUSB0
usb_device_path: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2.3/1-1.2.3.1
usb_interface_path: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2.3/1-1.2.3.1/1-1.2.3.1:1.0
</pre>looks under windows as
<pre class="">COM4
name: COM4
description: Silicon Labs CP210x USB to UART Bridge (COM4)
manufacturer: Silicon Labs
serial_number: 0001
VID:PID: 10c4:ea60
location: 1-3
hwid: USB VID:PID=10C4:EA60 SER=0001 LOCATION=1-3
</pre></p>
<p>
The product string is handy to customize for devices, so different hardware using the same interface chip
still looks different. (The annoyingly common CH317 has no EEPROM and no way to customize the strings.)
Same situation happens when the OS or library doesn't provide the string, and gives just a bland generic.
The location then can come to rescue for identifying the chips, by the sequence of port-(hub-hub...)-port. It is of course handy
to know the numbering on the ports on the machine and hubs. Measure once, write on the ports for later.
</p>
<hr /><a name="Files"></a><h2>Files
</h2>
<ul><li> <a class="F" href="lscom.py" title="local file">lscom.py</a>
</li></ul><hr /><a name="Todo"></a><h2>Todo
</h2>
<ul><li> maybe different -l format, with names
</li><li> maybe get it run better in windows?
</li></ul><!-- feedback -->
<!-- /feedback -->
</body>
</html>