Skip to content

Commit a76d549

Browse files
author
Mattia Bertorello
committed
Improve compatibility with different system
http://www.ni.com/product-documentation/54548/en/
1 parent 0a04417 commit a76d549

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

utils/flasher.go

+31-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,40 @@ package utils
22

33
import (
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+
724
func 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
}

0 commit comments

Comments
 (0)