Made mode bits enumeration explicit in Windows implementation
This commit is contained in:
@@ -157,19 +157,33 @@ type commTimeouts struct {
|
|||||||
//sys setCommTimeouts(handle syscall.Handle, timeouts *commTimeouts) (err error) = SetCommTimeouts
|
//sys setCommTimeouts(handle syscall.Handle, timeouts *commTimeouts) (err error) = SetCommTimeouts
|
||||||
|
|
||||||
const (
|
const (
|
||||||
noParity = 0 // Default
|
noParity = 0
|
||||||
oddParity = 1
|
oddParity = 1
|
||||||
evenParity = 2
|
evenParity = 2
|
||||||
markParity = 3
|
markParity = 3
|
||||||
spaceParity = 4
|
spaceParity = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var parityMap = map[Parity]byte{
|
||||||
|
NoParity: noParity,
|
||||||
|
OddParity: oddParity,
|
||||||
|
EvenParity: evenParity,
|
||||||
|
MarkParity: markParity,
|
||||||
|
SpaceParity: spaceParity,
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
oneStopBit = 0 // Default
|
oneStopBit = 0
|
||||||
one5StopBits = 1
|
one5StopBits = 1
|
||||||
twoStopBits = 2
|
twoStopBits = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var stopBitsMap = map[StopBits]byte{
|
||||||
|
OneStopBit: oneStopBit,
|
||||||
|
OnePointFiveStopBits: one5StopBits,
|
||||||
|
TwoStopBits: twoStopBits,
|
||||||
|
}
|
||||||
|
|
||||||
func (port *windowsPort) SetMode(mode *Mode) error {
|
func (port *windowsPort) SetMode(mode *Mode) error {
|
||||||
params := dcb{}
|
params := dcb{}
|
||||||
if getCommState(port.handle, ¶ms) != nil {
|
if getCommState(port.handle, ¶ms) != nil {
|
||||||
@@ -186,8 +200,8 @@ func (port *windowsPort) SetMode(mode *Mode) error {
|
|||||||
} else {
|
} else {
|
||||||
params.ByteSize = byte(mode.DataBits)
|
params.ByteSize = byte(mode.DataBits)
|
||||||
}
|
}
|
||||||
params.StopBits = byte(mode.StopBits)
|
params.StopBits = stopBitsMap[mode.StopBits]
|
||||||
params.Parity = byte(mode.Parity)
|
params.Parity = parityMap[mode.Parity]
|
||||||
if setCommState(port.handle, ¶ms) != nil {
|
if setCommState(port.handle, ¶ms) != nil {
|
||||||
port.Close()
|
port.Close()
|
||||||
return &PortError{code: InvalidSerialPort}
|
return &PortError{code: InvalidSerialPort}
|
||||||
|
|||||||
Reference in New Issue
Block a user