-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.go
More file actions
40 lines (36 loc) · 764 Bytes
/
start.go
File metadata and controls
40 lines (36 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"errors"
"fmt"
"os"
"go.bug.st/serial"
"go.bug.st/serial/enumerator"
)
func start() (serial.Port, error) {
// Start serial port
serOptions := serial.Mode{
BaudRate: 9600,
DataBits: 8,
Parity: serial.NoParity,
StopBits: serial.OneStopBit,
}
portList, err := enumerator.GetDetailedPortsList()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
batVID := "10c4"
batPID := "ea60"
var serPort serial.Port
for i := 0; i < len(portList); i++ {
if portList[i].VID == batVID && portList[i].PID == batPID {
serPort, err = serial.Open(portList[i].Name, &serOptions)
if err != nil {
fmt.Println(err)
return serPort, err
}
return serPort, nil
}
}
return serPort, errors.New("serial port not found")
}