Fixed a bunch of golint warnings (this needs an API change)

This commit is contained in:
Cristian Maglie
2016-01-01 23:23:20 +01:00
parent e90aca32c8
commit 485b2f86a8
9 changed files with 104 additions and 88 deletions

6
doc.go
View File

@@ -5,7 +5,7 @@
// //
/* /*
A cross-platform serial library for the go language. Package serial is a cross-platform serial library for the go language.
The canonical import for this library is go.bug.st/serial so the import line The canonical import for this library is go.bug.st/serial so the import line
is the following: is the following:
@@ -43,9 +43,9 @@ The following snippets shows how to declare a configuration for 57600_E71:
mode := &serial.Mode{ mode := &serial.Mode{
BaudRate: 57600, BaudRate: 57600,
Parity: serial.PARITY_EVEN, Parity: serial.EvenParity,
DataBits: 7, DataBits: 7,
StopBits: serial.STOPBITS_ONE, StopBits: serial.OneStopBit,
} }
The configuration can be changed at any time with the SetMode function: The configuration can be changed at any time with the SetMode function:

View File

@@ -23,4 +23,3 @@ func ExampleGetPortsList() {
} }
} }
} }

View File

@@ -17,13 +17,12 @@ func ExampleSerialPort_SetMode() {
} }
mode := &serial.Mode{ mode := &serial.Mode{
BaudRate: 9600, BaudRate: 9600,
Parity: serial.PARITY_NONE, Parity: serial.NoParity,
DataBits: 8, DataBits: 8,
StopBits: serial.STOPBITS_ONE, StopBits: serial.OneStopBit,
} }
if err := port.SetMode(mode); err != nil { if err := port.SetMode(mode); err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Println("Port set to 9600 N81") fmt.Println("Port set to 9600 N81")
} }

View File

@@ -31,9 +31,9 @@ func Example_sendAndReceive() {
// Open the first serial port detected at 9600bps N81 // Open the first serial port detected at 9600bps N81
mode := &serial.Mode{ mode := &serial.Mode{
BaudRate: 9600, BaudRate: 9600,
Parity: serial.PARITY_NONE, Parity: serial.NoParity,
DataBits: 8, DataBits: 8,
StopBits: serial.STOPBITS_ONE, StopBits: serial.OneStopBit,
} }
port, err := serial.OpenPort(ports[0], mode) port, err := serial.OpenPort(ports[0], mode)
if err != nil { if err != nil {
@@ -63,4 +63,3 @@ func Example_sendAndReceive() {
fmt.Printf("%v", string(buff[:n])) fmt.Printf("%v", string(buff[:n]))
} }
} }

View File

@@ -6,7 +6,7 @@
package serial // import "go.bug.st/serial" package serial // import "go.bug.st/serial"
// This structure describes a serial port configuration. // Mode describes a serial port configuration.
type Mode struct { type Mode struct {
BaudRate int // The serial port bitrate (aka Baudrate) BaudRate int // The serial port bitrate (aka Baudrate)
DataBits int // Size of the character (must be 5, 6, 7 or 8) DataBits int // Size of the character (must be 5, 6, 7 or 8)
@@ -14,62 +14,82 @@ type Mode struct {
StopBits StopBits // Stop bits (see StopBits type for more info) StopBits StopBits // Stop bits (see StopBits type for more info)
} }
// Parity describes a serial port parity setting
type Parity int type Parity int
const ( const (
PARITY_NONE Parity = iota // No parity (default) // NoParity disable parity control (default)
PARITY_ODD // Odd parity NoParity Parity = iota
PARITY_EVEN // Even parity // OddParity enable odd-parity check
PARITY_MARK // Mark parity (always 1) OddParity
PARITY_SPACE // Space parity (always 0) // EvenParity enable even-parity check
EvenParity
// MarkParity enable mark-parity (always 1) check
MarkParity
// SpaceParity enable space-parity (always 0) check
SpaceParity
) )
// StopBits describe a serial port stop bits setting
type StopBits int type StopBits int
const ( const (
STOPBITS_ONE StopBits = iota // 1 Stop bit // OneStopBit sets 1 stop bit (default)
STOPBITS_ONEPOINTFIVE // 1.5 Stop bits OneStopBit StopBits = iota
STOPBITS_TWO // 2 Stop bits // OnePointFiveStopBits sets 1.5 stop bits
OnePointFiveStopBits
// TwoStopBits sets 2 stop bits
TwoStopBits
) )
// Platform independent error type for serial ports // PortError is a platform independent error type for serial ports
type SerialPortError struct { type PortError struct {
err string err string
code int code PortErrorCode
} }
// PortErrorCode is a code to easily identify the type of error
type PortErrorCode int
const ( const (
ERROR_PORT_BUSY = iota // PortBusy the serial port is already in used by another process
ERROR_PORT_NOT_FOUND PortBusy PortErrorCode = iota
ERROR_INVALID_SERIAL_PORT // PortNotFound the requested port doesn't exist
ERROR_PERMISSION_DENIED PortNotFound
ERROR_INVALID_PORT_SPEED // InvalidSerialPort the requested port is not a serial port
ERROR_INVALID_PORT_DATA_BITS InvalidSerialPort
ERROR_ENUMERATING_PORTS // PermissionDenied the user doesn't have enough priviledges
ERROR_OTHER PermissionDenied
// InvalidSpeed the requested speed is not valid or not supported
InvalidSpeed
// InvalidDataBits the number of data bits is not valid or not supported
InvalidDataBits
// ErrorEnumeratingPorts an error occurred while listing serial port
ErrorEnumeratingPorts
) )
func (e SerialPortError) Error() string { // Error returns a string explaining the error occurred
func (e PortError) Error() string {
switch e.code { switch e.code {
case ERROR_PORT_BUSY: case PortBusy:
return "Serial port busy" return "Serial port busy"
case ERROR_PORT_NOT_FOUND: case PortNotFound:
return "Serial port not found" return "Serial port not found"
case ERROR_INVALID_SERIAL_PORT: case InvalidSerialPort:
return "Invalid serial port" return "Invalid serial port"
case ERROR_PERMISSION_DENIED: case PermissionDenied:
return "Permission denied" return "Permission denied"
case ERROR_INVALID_PORT_SPEED: case InvalidSpeed:
return "Invalid port speed" return "Invalid port speed"
case ERROR_INVALID_PORT_DATA_BITS: case InvalidDataBits:
return "Invalid port data bits" return "Invalid port data bits"
case ERROR_ENUMERATING_PORTS: case ErrorEnumeratingPorts:
return "Could not enumerate serial ports" return "Could not enumerate serial ports"
} }
return e.err return e.err
} }
func (e SerialPortError) Code() int { // Code returns an identifier for the kind of error occurred
func (e PortError) Code() PortErrorCode {
return e.code return e.code
} }

View File

@@ -43,12 +43,12 @@ var databitsMap = map[int]int{
8: syscall.CS8, 8: syscall.CS8,
} }
const tc_CMSPAR int = 0 // may be CMSPAR or PAREXT const tcCMSPAR int = 0 // may be CMSPAR or PAREXT
const tc_IUCLC int = 0 const tcIUCLC int = 0
// syscall wrappers // syscall wrappers
//sys ioctl(fd int, req uint64, data uintptr) (err error) //sys ioctl(fd int, req uint64, data uintptr) (err error)
const ioctl_tcgetattr = syscall.TIOCGETA const ioctlTcgetattr = syscall.TIOCGETA
const ioctl_tcsetattr = syscall.TIOCSETA const ioctlTcsetattr = syscall.TIOCSETA

View File

@@ -55,8 +55,8 @@ var databitsMap = map[int]int{
8: syscall.CS8, 8: syscall.CS8,
} }
const tc_CMSPAR int = 0 // may be CMSPAR or PAREXT const tcCMSPAR int = 0 // may be CMSPAR or PAREXT
const tc_IUCLC = syscall.IUCLC const tcIUCLC = syscall.IUCLC
func termiosMask(data int) uint32 { func termiosMask(data int) uint32 {
return uint32(data) return uint32(data)
@@ -66,5 +66,5 @@ func termiosMask(data int) uint32 {
//sys ioctl(fd int, req uint64, data uintptr) (err error) //sys ioctl(fd int, req uint64, data uintptr) (err error)
const ioctl_tcgetattr = syscall.TCGETS const ioctlTcgetattr = syscall.TCGETS
const ioctl_tcsetattr = syscall.TCSETS const ioctlTcsetattr = syscall.TCSETS

View File

@@ -40,8 +40,7 @@ func (port *SerialPort) Write(p []byte) (n int, err error) {
return syscall.Write(port.handle, p) return syscall.Write(port.handle, p)
} }
// Set all parameters of the serial port. See the Mode structure for more // SetMode sets all parameters of the serial port
// info.
func (port *SerialPort) SetMode(mode *Mode) error { func (port *SerialPort) SetMode(mode *Mode) error {
settings, err := port.getTermSettings() settings, err := port.getTermSettings()
if err != nil { if err != nil {
@@ -62,15 +61,15 @@ func (port *SerialPort) SetMode(mode *Mode) error {
return port.setTermSettings(settings) return port.setTermSettings(settings)
} }
// Open the serial port using the specified modes // OpenPort opens the serial port using the specified modes
func OpenPort(portName string, mode *Mode) (*SerialPort, error) { func OpenPort(portName string, mode *Mode) (*SerialPort, error) {
h, err := syscall.Open(portName, syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_NDELAY, 0) h, err := syscall.Open(portName, syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_NDELAY, 0)
if err != nil { if err != nil {
switch err { switch err {
case syscall.EBUSY: case syscall.EBUSY:
return nil, &SerialPortError{code: ERROR_PORT_BUSY} return nil, &PortError{code: PortBusy}
case syscall.EACCES: case syscall.EACCES:
return nil, &SerialPortError{code: ERROR_PERMISSION_DENIED} return nil, &PortError{code: PermissionDenied}
} }
return nil, err return nil, err
} }
@@ -81,19 +80,19 @@ func OpenPort(portName string, mode *Mode) (*SerialPort, error) {
// Setup serial port // Setup serial port
if port.SetMode(mode) != nil { if port.SetMode(mode) != nil {
port.Close() port.Close()
return nil, &SerialPortError{code: ERROR_INVALID_SERIAL_PORT} return nil, &PortError{code: InvalidSerialPort}
} }
// Set raw mode // Set raw mode
settings, err := port.getTermSettings() settings, err := port.getTermSettings()
if err != nil { if err != nil {
port.Close() port.Close()
return nil, &SerialPortError{code: ERROR_INVALID_SERIAL_PORT} return nil, &PortError{code: InvalidSerialPort}
} }
setRawMode(settings) setRawMode(settings)
if port.setTermSettings(settings) != nil { if port.setTermSettings(settings) != nil {
port.Close() port.Close()
return nil, &SerialPortError{code: ERROR_INVALID_SERIAL_PORT} return nil, &PortError{code: InvalidSerialPort}
} }
syscall.SetNonblock(h, false) syscall.SetNonblock(h, false)
@@ -103,6 +102,7 @@ func OpenPort(portName string, mode *Mode) (*SerialPort, error) {
return port, nil return port, nil
} }
// GetPortsList retrieve the list of available serial ports
func GetPortsList() ([]string, error) { func GetPortsList() ([]string, error) {
files, err := ioutil.ReadDir(devFolder) files, err := ioutil.ReadDir(devFolder)
if err != nil { if err != nil {
@@ -131,8 +131,8 @@ func GetPortsList() ([]string, error) {
if strings.HasPrefix(f.Name(), "ttyS") { if strings.HasPrefix(f.Name(), "ttyS") {
port, err := OpenPort(portName, &Mode{}) port, err := OpenPort(portName, &Mode{})
if err != nil { if err != nil {
serr, ok := err.(*SerialPortError) serr, ok := err.(*PortError)
if ok && serr.Code() == ERROR_INVALID_SERIAL_PORT { if ok && serr.Code() == InvalidSerialPort {
continue continue
} }
} else { } else {
@@ -152,7 +152,7 @@ func GetPortsList() ([]string, error) {
func setTermSettingsBaudrate(speed int, settings *syscall.Termios) error { func setTermSettingsBaudrate(speed int, settings *syscall.Termios) error {
baudrate, ok := baudrateMap[speed] baudrate, ok := baudrateMap[speed]
if !ok { if !ok {
return &SerialPortError{code: ERROR_INVALID_PORT_SPEED} return &PortError{code: InvalidSpeed}
} }
// revert old baudrate // revert old baudrate
BAUDMASK := 0 BAUDMASK := 0
@@ -169,23 +169,23 @@ func setTermSettingsBaudrate(speed int, settings *syscall.Termios) error {
func setTermSettingsParity(parity Parity, settings *syscall.Termios) error { func setTermSettingsParity(parity Parity, settings *syscall.Termios) error {
switch parity { switch parity {
case PARITY_NONE: case NoParity:
settings.Cflag &= ^termiosMask(syscall.PARENB | syscall.PARODD | tc_CMSPAR) settings.Cflag &= ^termiosMask(syscall.PARENB | syscall.PARODD | tcCMSPAR)
settings.Iflag &= ^termiosMask(syscall.INPCK) settings.Iflag &= ^termiosMask(syscall.INPCK)
case PARITY_ODD: case OddParity:
settings.Cflag |= termiosMask(syscall.PARENB | syscall.PARODD) settings.Cflag |= termiosMask(syscall.PARENB | syscall.PARODD)
settings.Cflag &= ^termiosMask(tc_CMSPAR) settings.Cflag &= ^termiosMask(tcCMSPAR)
settings.Iflag |= termiosMask(syscall.INPCK) settings.Iflag |= termiosMask(syscall.INPCK)
case PARITY_EVEN: case EvenParity:
settings.Cflag &= ^termiosMask(syscall.PARODD | tc_CMSPAR) settings.Cflag &= ^termiosMask(syscall.PARODD | tcCMSPAR)
settings.Cflag |= termiosMask(syscall.PARENB) settings.Cflag |= termiosMask(syscall.PARENB)
settings.Iflag |= termiosMask(syscall.INPCK) settings.Iflag |= termiosMask(syscall.INPCK)
case PARITY_MARK: case MarkParity:
settings.Cflag |= termiosMask(syscall.PARENB | syscall.PARODD | tc_CMSPAR) settings.Cflag |= termiosMask(syscall.PARENB | syscall.PARODD | tcCMSPAR)
settings.Iflag |= termiosMask(syscall.INPCK) settings.Iflag |= termiosMask(syscall.INPCK)
case PARITY_SPACE: case SpaceParity:
settings.Cflag &= ^termiosMask(syscall.PARODD) settings.Cflag &= ^termiosMask(syscall.PARODD)
settings.Cflag |= termiosMask(syscall.PARENB | tc_CMSPAR) settings.Cflag |= termiosMask(syscall.PARENB | tcCMSPAR)
settings.Iflag |= termiosMask(syscall.INPCK) settings.Iflag |= termiosMask(syscall.INPCK)
} }
return nil return nil
@@ -194,7 +194,7 @@ func setTermSettingsParity(parity Parity, settings *syscall.Termios) error {
func setTermSettingsDataBits(bits int, settings *syscall.Termios) error { func setTermSettingsDataBits(bits int, settings *syscall.Termios) error {
databits, ok := databitsMap[bits] databits, ok := databitsMap[bits]
if !ok { if !ok {
return &SerialPortError{code: ERROR_INVALID_PORT_DATA_BITS} return &PortError{code: InvalidDataBits}
} }
settings.Cflag &= ^termiosMask(syscall.CSIZE) settings.Cflag &= ^termiosMask(syscall.CSIZE)
settings.Cflag |= termiosMask(databits) settings.Cflag |= termiosMask(databits)
@@ -203,9 +203,9 @@ func setTermSettingsDataBits(bits int, settings *syscall.Termios) error {
func setTermSettingsStopBits(bits StopBits, settings *syscall.Termios) error { func setTermSettingsStopBits(bits StopBits, settings *syscall.Termios) error {
switch bits { switch bits {
case STOPBITS_ONE: case OneStopBit:
settings.Cflag &= ^termiosMask(syscall.CSTOPB) settings.Cflag &= ^termiosMask(syscall.CSTOPB)
case STOPBITS_ONEPOINTFIVE, STOPBITS_TWO: case OnePointFiveStopBits, TwoStopBits:
settings.Cflag |= termiosMask(syscall.CSTOPB) settings.Cflag |= termiosMask(syscall.CSTOPB)
} }
return nil return nil
@@ -220,7 +220,7 @@ func setRawMode(settings *syscall.Termios) {
syscall.ECHONL | syscall.ECHOCTL | syscall.ECHOPRT | syscall.ECHOKE | syscall.ISIG | syscall.IEXTEN) syscall.ECHONL | syscall.ECHOCTL | syscall.ECHOPRT | syscall.ECHOKE | syscall.ISIG | syscall.IEXTEN)
settings.Iflag &= ^termiosMask(syscall.IXON | syscall.IXOFF | syscall.IXANY | syscall.INPCK | settings.Iflag &= ^termiosMask(syscall.IXON | syscall.IXOFF | syscall.IXANY | syscall.INPCK |
syscall.IGNPAR | syscall.PARMRK | syscall.ISTRIP | syscall.IGNBRK | syscall.BRKINT | syscall.INLCR | syscall.IGNPAR | syscall.PARMRK | syscall.ISTRIP | syscall.IGNBRK | syscall.BRKINT | syscall.INLCR |
syscall.IGNCR | syscall.ICRNL | tc_IUCLC) syscall.IGNCR | syscall.ICRNL | tcIUCLC)
settings.Oflag &= ^termiosMask(syscall.OPOST) settings.Oflag &= ^termiosMask(syscall.OPOST)
// Block reads until at least one char is available (no timeout) // Block reads until at least one char is available (no timeout)
@@ -232,12 +232,12 @@ func setRawMode(settings *syscall.Termios) {
func (port *SerialPort) getTermSettings() (*syscall.Termios, error) { func (port *SerialPort) getTermSettings() (*syscall.Termios, error) {
settings := &syscall.Termios{} settings := &syscall.Termios{}
err := ioctl(port.handle, ioctl_tcgetattr, uintptr(unsafe.Pointer(settings))) err := ioctl(port.handle, ioctlTcgetattr, uintptr(unsafe.Pointer(settings)))
return settings, err return settings, err
} }
func (port *SerialPort) setTermSettings(settings *syscall.Termios) error { func (port *SerialPort) setTermSettings(settings *syscall.Termios) error {
return ioctl(port.handle, ioctl_tcsetattr, uintptr(unsafe.Pointer(settings))) return ioctl(port.handle, ioctlTcsetattr, uintptr(unsafe.Pointer(settings)))
} }
func (port *SerialPort) acquireExclusiveAccess() error { func (port *SerialPort) acquireExclusiveAccess() error {

View File

@@ -28,18 +28,18 @@ type SerialPort struct {
func GetPortsList() ([]string, error) { func GetPortsList() ([]string, error) {
subKey, err := syscall.UTF16PtrFromString("HARDWARE\\DEVICEMAP\\SERIALCOMM\\") subKey, err := syscall.UTF16PtrFromString("HARDWARE\\DEVICEMAP\\SERIALCOMM\\")
if err != nil { if err != nil {
return nil, &SerialPortError{code: ERROR_ENUMERATING_PORTS} return nil, &PortError{code: ErrorEnumeratingPorts}
} }
var h syscall.Handle var h syscall.Handle
if syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, subKey, 0, syscall.KEY_READ, &h) != nil { if syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, subKey, 0, syscall.KEY_READ, &h) != nil {
return nil, &SerialPortError{code: ERROR_ENUMERATING_PORTS} return nil, &PortError{code: ErrorEnumeratingPorts}
} }
defer syscall.RegCloseKey(h) defer syscall.RegCloseKey(h)
var valuesCount uint32 var valuesCount uint32
if syscall.RegQueryInfoKey(h, nil, nil, nil, nil, nil, nil, &valuesCount, nil, nil, nil, nil) != nil { if syscall.RegQueryInfoKey(h, nil, nil, nil, nil, nil, nil, &valuesCount, nil, nil, nil, nil) != nil {
return nil, &SerialPortError{code: ERROR_ENUMERATING_PORTS} return nil, &PortError{code: ErrorEnumeratingPorts}
} }
list := make([]string, valuesCount) list := make([]string, valuesCount)
@@ -49,7 +49,7 @@ func GetPortsList() ([]string, error) {
var name [1024]uint16 var name [1024]uint16
nameSize := uint32(len(name)) nameSize := uint32(len(name))
if RegEnumValue(h, uint32(i), &name[0], &nameSize, nil, nil, &data[0], &dataSize) != nil { if RegEnumValue(h, uint32(i), &name[0], &nameSize, nil, nil, &data[0], &dataSize) != nil {
return nil, &SerialPortError{code: ERROR_ENUMERATING_PORTS} return nil, &PortError{code: ErrorEnumeratingPorts}
} }
list[i] = syscall.UTF16ToString(data[:]) list[i] = syscall.UTF16ToString(data[:])
} }
@@ -175,7 +175,7 @@ func (port *SerialPort) SetMode(mode *Mode) error {
params := DCB{} params := DCB{}
if GetCommState(port.handle, &params) != nil { if GetCommState(port.handle, &params) != nil {
port.Close() port.Close()
return &SerialPortError{code: ERROR_INVALID_SERIAL_PORT} return &PortError{code: InvalidSerialPort}
} }
if mode.BaudRate == 0 { if mode.BaudRate == 0 {
params.BaudRate = 9600 // Default to 9600 params.BaudRate = 9600 // Default to 9600
@@ -191,7 +191,7 @@ func (port *SerialPort) SetMode(mode *Mode) error {
params.Parity = byte(mode.Parity) params.Parity = byte(mode.Parity)
if SetCommState(port.handle, &params) != nil { if SetCommState(port.handle, &params) != nil {
port.Close() port.Close()
return &SerialPortError{code: ERROR_INVALID_SERIAL_PORT} return &PortError{code: InvalidSerialPort}
} }
return nil return nil
} }
@@ -212,9 +212,9 @@ func OpenPort(portName string, mode *Mode) (*SerialPort, error) {
if err != nil { if err != nil {
switch err { switch err {
case syscall.ERROR_ACCESS_DENIED: case syscall.ERROR_ACCESS_DENIED:
return nil, &SerialPortError{code: ERROR_PORT_BUSY} return nil, &PortError{code: PortBusy}
case syscall.ERROR_FILE_NOT_FOUND: case syscall.ERROR_FILE_NOT_FOUND:
return nil, &SerialPortError{code: ERROR_PORT_NOT_FOUND} return nil, &PortError{code: PortNotFound}
} }
return nil, err return nil, err
} }
@@ -226,13 +226,13 @@ func OpenPort(portName string, mode *Mode) (*SerialPort, error) {
// Set port parameters // Set port parameters
if port.SetMode(mode) != nil { if port.SetMode(mode) != nil {
port.Close() port.Close()
return nil, &SerialPortError{code: ERROR_INVALID_SERIAL_PORT} return nil, &PortError{code: InvalidSerialPort}
} }
params := &DCB{} params := &DCB{}
if GetCommState(port.handle, params) != nil { if GetCommState(port.handle, params) != nil {
port.Close() port.Close()
return nil, &SerialPortError{code: ERROR_INVALID_SERIAL_PORT} return nil, &PortError{code: InvalidSerialPort}
} }
params.Flags |= DCB_RTS_CONTROL_ENABLE | DCB_DTR_CONTROL_ENABLE params.Flags |= DCB_RTS_CONTROL_ENABLE | DCB_DTR_CONTROL_ENABLE
params.Flags &= ^uint32(DCB_OUT_X_CTS_FLOW) params.Flags &= ^uint32(DCB_OUT_X_CTS_FLOW)
@@ -249,7 +249,7 @@ func OpenPort(portName string, mode *Mode) (*SerialPort, error) {
params.XoffChar = 19 // C3 params.XoffChar = 19 // C3
if SetCommState(port.handle, params) != nil { if SetCommState(port.handle, params) != nil {
port.Close() port.Close()
return nil, &SerialPortError{code: ERROR_INVALID_SERIAL_PORT} return nil, &PortError{code: InvalidSerialPort}
} }
// Set timeouts to 1 second // Set timeouts to 1 second
@@ -262,9 +262,8 @@ func OpenPort(portName string, mode *Mode) (*SerialPort, error) {
} }
if SetCommTimeouts(port.handle, timeouts) != nil { if SetCommTimeouts(port.handle, timeouts) != nil {
port.Close() port.Close()
return nil, &SerialPortError{code: ERROR_INVALID_SERIAL_PORT} return nil, &PortError{code: InvalidSerialPort}
} }
return port, nil return port, nil
} }