Skip to content

Commit

Permalink
For Windows if mode.BaudRate < 0 then fill mode from getCommState.
Browse files Browse the repository at this point in the history
  • Loading branch information
abakum committed Jan 30, 2025
1 parent 0996f84 commit 1c8cda0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions serial_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ func (port *unixPort) SetMode(mode *Mode) error {
return err
}
requireSpecialBaudrate := false
if mode.BaudRate < 0 {
mode.BaudRate = 0
}
if err, special := setTermSettingsBaudrate(mode.BaudRate, settings); err != nil {
return err
} else if special {
Expand Down
14 changes: 11 additions & 3 deletions serial_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,17 @@ func (port *windowsPort) SetMode(mode *Mode) error {
}

func (port *windowsPort) setModeParams(mode *Mode, params *windows.DCB) {
if mode.BaudRate == 0 {
if mode.BaudRate < 0 {
// from getCommState to mode
mode.BaudRate = int(params.BaudRate)
mode.DataBits = int(params.ByteSize)
mode.StopBits = StopBits(params.StopBits)
mode.Parity = Parity(params.Parity)
} else {
params.StopBits = stopBitsMap[mode.StopBits]
params.Parity = parityMap[mode.Parity]
}
if mode.BaudRate <= 0 {
params.BaudRate = windows.CBR_9600 // Default to 9600
} else {
params.BaudRate = uint32(mode.BaudRate)
Expand All @@ -181,8 +191,6 @@ func (port *windowsPort) setModeParams(mode *Mode, params *windows.DCB) {
} else {
params.ByteSize = byte(mode.DataBits)
}
params.StopBits = stopBitsMap[mode.StopBits]
params.Parity = parityMap[mode.Parity]
}

func (port *windowsPort) SetDTR(dtr bool) error {
Expand Down

0 comments on commit 1c8cda0

Please sign in to comment.