Windows: added SetSpeed

This commit is contained in:
Cristian Maglie
2014-12-13 20:17:40 +04:30
parent 5567c33301
commit fe9ccd37d9

View File

@@ -178,6 +178,23 @@ const (
TWOSTOPBITS = 2
)
func (port windowsSerialPort) SetSpeed(baudrate int) error {
params := DCB{}
if err := GetCommState(port.Handle, &params); err != nil {
port.Close()
return &SerialPortError{code: ERROR_INVALID_SERIAL_PORT}
}
params.BaudRate = uint32(baudrate)
params.ByteSize = 8
params.StopBits = ONESTOPBIT
params.Parity = NOPARITY
if err := SetCommState(port.Handle, &params); err != nil {
port.Close()
return &SerialPortError{code: ERROR_INVALID_SERIAL_PORT}
}
return nil
}
func OpenPort(portName string, useTIOCEXCL bool) (SerialPort, error) {
portName = "\\\\.\\" + portName