From cb166b5b850dee60bc5f9929301cf6e180399868 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 22 Oct 2016 15:52:27 +0200 Subject: [PATCH] Improved error reporting on setting stop bits --- serial.go | 4 ++++ serial_unix.go | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/serial.go b/serial.go index 7b82518..6b932d0 100644 --- a/serial.go +++ b/serial.go @@ -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: diff --git a/serial_unix.go b/serial_unix.go index 5c20b68..2368cdc 100644 --- a/serial_unix.go +++ b/serial_unix.go @@ -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 }