summaryrefslogtreecommitdiff
path: root/software/communication/physical.go
blob: 853e4c4e9ff8a4380f6f19623c52a8e075c3ac05 (plain)
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
41
package communication

import (
	"go.bug.st/serial"
	"go.bug.st/serial/enumerator"
)

const (
	ST_VID = `0483`
)

func getStSerials() ([]string, error) {
	retval := make([]string, 0)

	ports, err := enumerator.GetDetailedPortsList()
	if err != nil {
		return retval, err
	}

	for _, port := range ports {
		if port.IsUSB {
			if port.VID == ST_VID {
				retval = append(retval, port.Name)
			}
		}
	}

	return retval, nil
}

func openSerial(device string) (serial.Port, error) {
	var port serial.Port
	mode := &serial.Mode{
		BaudRate: 115200,
	}
	port, err := serial.Open(device, mode)
	if err != nil {
		return port, err
	}
	return port, nil
}