diff --git a/go/src/lsis/serial.go b/go/src/lsis/serial.go new file mode 100644 index 0000000..40d33fe --- /dev/null +++ b/go/src/lsis/serial.go @@ -0,0 +1,73 @@ +package main + +import ( + "log" + "os" + + "github.com/tarm/serial" +) + +func main() { + w() + r() +} + +func r() { + p, err := serial.OpenPort(&serial.Config{ + Name: "/dev/ttyUSB1", + Baud: 230400, + }) + if err != nil { + log.Fatal(err) + } + + b := make([]byte, 16) + t := 0 + for { + n, err := p.Read(b) + if err != nil { + log.Fatal(err) + } + + t += n + log.Print(t) + if t >= 1024*1024 { + break + } + } +} + +func w() { + f, err := os.OpenFile("/dev/zero", os.O_RDONLY, 666) + if err != nil { + log.Fatal(err) + } + + p, err := serial.OpenPort(&serial.Config{ + Name: "/dev/ttyUSB1", + Baud: 230400, + }) + if err != nil { + log.Fatal(err) + } + + b := make([]byte, 16) + t := 0 + for { + n, err := f.Read(b) + if err != nil { + log.Fatal(err) + } + + _, err = p.Write(b[:n]) + if err != nil { + log.Fatal(err) + } + + t += n + log.Print(t) + if t >= 1024*1024+1024 { + break + } + } +}