Merge pull request #202 from ctarsjp/win-port-enum
Fix (non-detailed) port enumeration on Windows
This commit is contained in:
@@ -19,6 +19,7 @@ package serial
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -45,12 +46,22 @@ func nativeGetPortsList() ([]string, error) {
|
||||
}
|
||||
defer key.Close()
|
||||
|
||||
list, err := key.ReadValueNames(0)
|
||||
names, err := key.ReadValueNames(0)
|
||||
if err != nil {
|
||||
return nil, &PortError{code: ErrorEnumeratingPorts, causedBy: err}
|
||||
}
|
||||
|
||||
return list, nil
|
||||
var values []string
|
||||
for _, n := range names {
|
||||
v, _, err := key.GetStringValue(n)
|
||||
if err != nil || v == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
values = append(values, v)
|
||||
}
|
||||
|
||||
return values, nil
|
||||
}
|
||||
|
||||
func (port *windowsPort) Close() error {
|
||||
@@ -342,7 +353,9 @@ func createOverlappedEvent() (*windows.Overlapped, error) {
|
||||
}
|
||||
|
||||
func nativeOpen(portName string, mode *Mode) (*windowsPort, error) {
|
||||
portName = "\\\\.\\" + portName
|
||||
if !strings.HasPrefix(portName, `\\.\`) {
|
||||
portName = `\\.\` + portName
|
||||
}
|
||||
path, err := windows.UTF16PtrFromString(portName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user