"log"
)
+
// ---------- Serial TTY Code -------------
func openTTY(name string) (*os.File, error) {
return file, nil
}
-func SerialWriter(in <- chan string, serial * os.File) {
+func serialWriter(in <- chan string, serial * os.File) {
for totty := range(in) {
serial.WriteString(totty)
serial.Sync()
}
+ close(serial)
}
-func SerialReader(out chan <- [][]byte, topub chan <- [][]byte, serial * os.File) {
+func serialReader(out chan <- [][]byte, serial * os.File) {
linescanner := bufio.NewScanner(serial)
linescanner.Split(bufio.ScanLines)
for linescanner.Scan() {
continue
}
out <- text
- topub <- text
}
}
-func OpenAndHandleSerial(filename string, topub chan <- [][]byte) (chan string, chan [][]byte, error) {
+func OpenAndHandleSerial(filename string) (chan string, chan [][]byte, error) {
serial, err :=openTTY(filename)
if err != nil {
return nil, nil, err
}
- var wr chan string
- var rd chan [][]byte
- go SerialWriter(wr, serial)
- go SerialReader(rd, topub, serial)
+ wr := make(chan string, 1)
+ rd := make(chan [][]byte, 20)
+ go serialWriter(wr, serial)
+ go serialReader(rd, serial)
return wr, rd, nil
}