From 680801120af1dd55e59ae8e0ef87bb3c84369312 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 5 Nov 2020 17:43:41 +0900 Subject: [PATCH] =?UTF-8?q?LS=EC=82=B0=EC=A0=84=20=EC=8B=9C=EB=A6=AC?= =?UTF-8?q?=EC=96=BC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EB=9E=A8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/src/lsis/serial.go | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 go/src/lsis/serial.go 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 + } + } +} -- 2.1.4