From b334f1953d3d7f71487073ea0815983df1610a5b Mon Sep 17 00:00:00 2001 From: Adam S Levy Date: Thu, 30 Aug 2018 09:57:51 -0800 Subject: [PATCH] Return error on unrecognized baud rate (#86) This fixes Issue #85 --- serial_linux.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/serial_linux.go b/serial_linux.go index 6469583..65420f3 100644 --- a/serial_linux.go +++ b/serial_linux.go @@ -3,6 +3,7 @@ package serial import ( + "fmt" "os" "time" "unsafe" @@ -44,10 +45,10 @@ func openPort(name string, baud int, databits byte, parity Parity, stopbits Stop 4000000: unix.B4000000, } - rate := bauds[baud] + rate, ok := bauds[baud] - if rate == 0 { - return + if !ok { + return nil, fmt.Errorf("Unrecognized baud rate") } f, err := os.OpenFile(name, unix.O_RDWR|unix.O_NOCTTY|unix.O_NONBLOCK, 0666)