Skip to content

Commit

Permalink
Return error on unrecognized baud rate (tarm#86)
Browse files Browse the repository at this point in the history
This fixes Issue tarm#85
  • Loading branch information
AdamSLevy authored and tarm committed Aug 30, 2018
1 parent eaafced commit b334f19
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions serial_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package serial

import (
"fmt"
"os"
"time"
"unsafe"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b334f19

Please sign in to comment.