File tree Expand file tree Collapse file tree 1 file changed +31
-6
lines changed Expand file tree Collapse file tree 1 file changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -2,15 +2,40 @@ package utils
22
33import (
44 "github.com/facchinm/go-serial"
5+ "log"
56)
67
8+ // http://www.ni.com/product-documentation/54548/en/
9+ var baudRates = []int {
10+ // Standard baud rates supported by some serial ports
11+ 921600 ,
12+ 460800 ,
13+ 256000 ,
14+ 230400 ,
15+ 153600 ,
16+ 128000 ,
17+ // Standard baud rates supported by most serial ports
18+ 115200 ,
19+ 57600 ,
20+ 56000 ,
21+ 38400 ,
22+ }
23+
724func OpenSerial (portName string ) (serial.Port , error ) {
8- mode := & serial.Mode {
9- // This bound rate works on osx 10.14
10- BaudRate : 115200 ,
11- Vtimeout : 255 ,
12- Vmin : 0 ,
25+ var port serial.Port
26+ var err error
27+ for _ , baudRate := range baudRates {
28+ mode := & serial.Mode {
29+ BaudRate : baudRate ,
30+ Vtimeout : 255 ,
31+ Vmin : 0 ,
32+ }
33+ port , err := serial .Open (portName , mode )
34+ if err == nil {
35+ log .Printf ("Open the serial port with baud rate %d" , baudRate )
36+ return port , nil
37+ }
1338 }
39+ return port , err
1440
15- return serial .Open (portName , mode )
1641}
You can’t perform that action at this time.
0 commit comments