Improved error reporting on setting stop bits
This commit is contained in:
@@ -96,6 +96,8 @@ const (
|
|||||||
InvalidDataBits
|
InvalidDataBits
|
||||||
// InvalidParity the selected parity is not valid or not supported
|
// InvalidParity the selected parity is not valid or not supported
|
||||||
InvalidParity
|
InvalidParity
|
||||||
|
// InvalidStopBits the selected number of stop bits is not valid or not supported
|
||||||
|
InvalidStopBits
|
||||||
// ErrorEnumeratingPorts an error occurred while listing serial port
|
// ErrorEnumeratingPorts an error occurred while listing serial port
|
||||||
ErrorEnumeratingPorts
|
ErrorEnumeratingPorts
|
||||||
)
|
)
|
||||||
@@ -117,6 +119,8 @@ func (e PortError) EncodedErrorString() string {
|
|||||||
return "Port data bits invalid or not supported"
|
return "Port data bits invalid or not supported"
|
||||||
case InvalidParity:
|
case InvalidParity:
|
||||||
return "Port parity invalid or not supported"
|
return "Port parity invalid or not supported"
|
||||||
|
case InvalidStopBits:
|
||||||
|
return "Port stop bits invalid or not supported"
|
||||||
case ErrorEnumeratingPorts:
|
case ErrorEnumeratingPorts:
|
||||||
return "Could not enumerate serial ports"
|
return "Could not enumerate serial ports"
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -213,8 +213,12 @@ func setTermSettingsStopBits(bits StopBits, settings *syscall.Termios) error {
|
|||||||
switch bits {
|
switch bits {
|
||||||
case OneStopBit:
|
case OneStopBit:
|
||||||
settings.Cflag &^= syscall.CSTOPB
|
settings.Cflag &^= syscall.CSTOPB
|
||||||
case OnePointFiveStopBits, TwoStopBits:
|
case OnePointFiveStopBits:
|
||||||
|
return &PortError{code: InvalidStopBits}
|
||||||
|
case TwoStopBits:
|
||||||
settings.Cflag |= syscall.CSTOPB
|
settings.Cflag |= syscall.CSTOPB
|
||||||
|
default:
|
||||||
|
return &PortError{code: InvalidStopBits}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user