Small fix to win API

This commit is contained in:
Cristian Maglie
2014-12-30 20:36:21 +01:00
parent 4eaa3b67d0
commit bf454eae31

View File

@@ -190,7 +190,7 @@ type COMMTIMEOUTS struct {
//sys SetCommTimeouts(handle syscall.Handle, timeouts *COMMTIMEOUTS) (err error) //sys SetCommTimeouts(handle syscall.Handle, timeouts *COMMTIMEOUTS) (err error)
const ( const (
NOPARITY = 0 NOPARITY = 0 // Default
ODDPARITY = 1 ODDPARITY = 1
EVENPARITY = 2 EVENPARITY = 2
MARKPARITY = 3 MARKPARITY = 3
@@ -198,7 +198,7 @@ const (
) )
const ( const (
ONESTOPBIT = 0 ONESTOPBIT = 0 // Default
ONE5STOPBITS = 1 ONE5STOPBITS = 1
TWOSTOPBITS = 2 TWOSTOPBITS = 2
) )
@@ -209,7 +209,7 @@ func (port windowsSerialPort) SetMode(mode *Mode) error {
port.Close() port.Close()
return &SerialPortError{code: ERROR_INVALID_SERIAL_PORT} return &SerialPortError{code: ERROR_INVALID_SERIAL_PORT}
} }
if mode.Baudrate == 0 { if mode.BaudRate == 0 {
params.BaudRate = 9600 // Default to 9600 params.BaudRate = 9600 // Default to 9600
} else { } else {
params.BaudRate = uint32(mode.BaudRate) params.BaudRate = uint32(mode.BaudRate)
@@ -217,10 +217,10 @@ func (port windowsSerialPort) SetMode(mode *Mode) error {
if mode.DataBits == 0 { if mode.DataBits == 0 {
params.ByteSize = 8 // Default to 8 bits params.ByteSize = 8 // Default to 8 bits
} else { } else {
params.ByteSize = mode.DataBits params.ByteSize = byte(mode.DataBits)
} }
params.StopBits = mode.StopBits params.StopBits = byte(mode.StopBits)
params.Parity = mode.Parity params.Parity = byte(mode.Parity)
if err := SetCommState(port.Handle, &params); err != nil { if err := SetCommState(port.Handle, &params); err != nil {
port.Close() port.Close()
return &SerialPortError{code: ERROR_INVALID_SERIAL_PORT} return &SerialPortError{code: ERROR_INVALID_SERIAL_PORT}
@@ -228,7 +228,7 @@ func (port windowsSerialPort) SetMode(mode *Mode) error {
return nil return nil
} }
func OpenPort(portName string, mode Mode) (SerialPort, error) { func OpenPort(portName string, mode *Mode) (SerialPort, error) {
portName = "\\\\.\\" + portName portName = "\\\\.\\" + portName
path, err := syscall.UTF16PtrFromString(portName) path, err := syscall.UTF16PtrFromString(portName)
if err != nil { if err != nil {