Improved error reporting on setting stop bits

This commit is contained in:
Cristian Maglie
2016-10-22 15:52:27 +02:00
parent f78e270591
commit cb166b5b85
2 changed files with 9 additions and 1 deletions

View File

@@ -96,6 +96,8 @@ const (
InvalidDataBits
// InvalidParity the selected parity is not valid or not supported
InvalidParity
// InvalidStopBits the selected number of stop bits is not valid or not supported
InvalidStopBits
// ErrorEnumeratingPorts an error occurred while listing serial port
ErrorEnumeratingPorts
)
@@ -117,6 +119,8 @@ func (e PortError) EncodedErrorString() string {
return "Port data bits invalid or not supported"
case InvalidParity:
return "Port parity invalid or not supported"
case InvalidStopBits:
return "Port stop bits invalid or not supported"
case ErrorEnumeratingPorts:
return "Could not enumerate serial ports"
default:

View File

@@ -213,8 +213,12 @@ func setTermSettingsStopBits(bits StopBits, settings *syscall.Termios) error {
switch bits {
case OneStopBit:
settings.Cflag &^= syscall.CSTOPB
case OnePointFiveStopBits, TwoStopBits:
case OnePointFiveStopBits:
return &PortError{code: InvalidStopBits}
case TwoStopBits:
settings.Cflag |= syscall.CSTOPB
default:
return &PortError{code: InvalidStopBits}
}
return nil
}