Skip to content

Commit 6cc7a9e

Browse files
committed
Removed seriallist.go and inlined function calls
1 parent d7a9991 commit 6cc7a9e

File tree

2 files changed

+31
-81
lines changed

2 files changed

+31
-81
lines changed

serial.go

+31-19
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
"strconv"
2323
"strings"
2424
"sync"
25+
26+
"github.com/sirupsen/logrus"
27+
"go.bug.st/serial/enumerator"
2528
)
2629

2730
type writeRequest struct {
@@ -150,43 +153,52 @@ func (sp *SerialPortList) Update() {
150153
}
151154
defer sp.enumerationLock.Unlock()
152155

153-
ports, err := enumerateSerialPorts()
154-
if err != nil {
155-
// TODO: report error?
156+
livePorts, _ := enumerator.GetDetailedPortsList()
157+
// TODO: report error?
156158

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+
}
160172

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 {
166173
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,
169179
IsOpen: false,
170180
IsPrimary: false,
171181
Baud: 0,
172182
BufferAlgorithm: "",
173-
Ver: version,
174-
VendorID: item.VID,
175-
ProductID: item.PID,
176183
}
177184

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+
178189
// figure out if port is open
179-
if myport, isFound := sh.FindPortByName(item.Name); isFound {
190+
if myport, isFound := sh.FindPortByName(port.Name); isFound {
180191
// and update data with the open port parameters
181192
port.IsOpen = true
182193
port.Baud = myport.portConf.Baud
183194
port.BufferAlgorithm = myport.BufferType
184195
}
185-
list = append(list, port)
196+
197+
ports = append(ports, port)
186198
}
187199

188200
serialPorts.portsLock.Lock()
189-
serialPorts.Ports = list
201+
serialPorts.Ports = ports
190202
serialPorts.portsLock.Unlock()
191203
}
192204

seriallist.go

-62
This file was deleted.

0 commit comments

Comments
 (0)