@@ -22,6 +22,9 @@ import (
22
22
"strconv"
23
23
"strings"
24
24
"sync"
25
+
26
+ "github.com/sirupsen/logrus"
27
+ "go.bug.st/serial/enumerator"
25
28
)
26
29
27
30
type writeRequest struct {
@@ -150,43 +153,52 @@ func (sp *SerialPortList) Update() {
150
153
}
151
154
defer sp .enumerationLock .Unlock ()
152
155
153
- ports , err := enumerateSerialPorts ()
154
- if err != nil {
155
- // TODO: report error?
156
+ livePorts , _ := enumerator .GetDetailedPortsList ()
157
+ // TODO: report error?
156
158
157
- // Empty port list if they can not be detected
158
- ports = []* OsSerialPort {}
159
- }
159
+ var ports []SpPortItem
160
+ for _ , livePort := range livePorts {
161
+ if ! livePort .IsUSB {
162
+ continue
163
+ }
164
+ vid , pid := "0x" + livePort .VID , "0x" + livePort .PID
165
+ if vid == "0x0000" || pid == "0x0000" {
166
+ continue
167
+ }
168
+ if portsFilter != nil && ! portsFilter .MatchString (livePort .Name ) {
169
+ logrus .Debugf ("ignoring port not matching filter. port: %v\n " , livePort )
170
+ continue
171
+ }
160
172
161
- // we have a full clean list of ports now. iterate thru them
162
- // to append the open/close state, baud rates, etc to make
163
- // a super clean nice list to send back to browser
164
- list := []SpPortItem {}
165
- for _ , item := range ports {
166
173
port := SpPortItem {
167
- Name : item .Name ,
168
- SerialNumber : item .SerialNumber ,
174
+ Name : livePort .Name ,
175
+ SerialNumber : livePort .SerialNumber ,
176
+ VendorID : vid ,
177
+ ProductID : pid ,
178
+ Ver : version ,
169
179
IsOpen : false ,
170
180
IsPrimary : false ,
171
181
Baud : 0 ,
172
182
BufferAlgorithm : "" ,
173
- Ver : version ,
174
- VendorID : item .VID ,
175
- ProductID : item .PID ,
176
183
}
177
184
185
+ // we have a full clean list of ports now. iterate thru them
186
+ // to append the open/close state, baud rates, etc to make
187
+ // a super clean nice list to send back to browser
188
+
178
189
// figure out if port is open
179
- if myport , isFound := sh .FindPortByName (item .Name ); isFound {
190
+ if myport , isFound := sh .FindPortByName (port .Name ); isFound {
180
191
// and update data with the open port parameters
181
192
port .IsOpen = true
182
193
port .Baud = myport .portConf .Baud
183
194
port .BufferAlgorithm = myport .BufferType
184
195
}
185
- list = append (list , port )
196
+
197
+ ports = append (ports , port )
186
198
}
187
199
188
200
serialPorts .portsLock .Lock ()
189
- serialPorts .Ports = list
201
+ serialPorts .Ports = ports
190
202
serialPorts .portsLock .Unlock ()
191
203
}
192
204
0 commit comments