diff options
Diffstat (limited to 'software/communication/physical.go')
-rw-r--r-- | software/communication/physical.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/software/communication/physical.go b/software/communication/physical.go index 25d5299..f79d382 100644 --- a/software/communication/physical.go +++ b/software/communication/physical.go @@ -1,6 +1,9 @@ package communication import ( + "fmt" + + "go.bug.st/serial" "go.bug.st/serial/enumerator" ) @@ -8,6 +11,10 @@ const ( ST_VID = `0483` ) +type Phy struct { + port serial.Port +} + func GetStSerials() ([]string, error) { retval := make([]string, 0) @@ -26,3 +33,27 @@ func GetStSerials() ([]string, error) { return retval, nil } + +func NewPhy(device string) (Phy, error) { + p := Phy{} + mode := &serial.Mode{ + BaudRate: 115200, + } + port, err := serial.Open(device, mode) + if err != nil { + return p, err + } + p.port = port + return p, nil +} + +func (phy *Phy) Cat() error { + buff := make([]byte, 100) + for { + n, err := phy.port.Read(buff) + if err != nil { + return err + } + fmt.Printf("%s", string(buff[:n])) + } +} |