uc_sensor_node_zmq forwarder
[svn42.git] / go / door_daemon_zmq / serial_tty.go
index 4ec786a..a5528d5 100644 (file)
@@ -11,6 +11,7 @@ import (
     "log"
 )
 
+
 // ---------- Serial TTY Code -------------
 
 func openTTY(name string) (*os.File, error) {
@@ -24,14 +25,15 @@ 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() {
@@ -43,18 +45,17 @@ func SerialReader(out chan <- [][]byte, topub chan <- [][]byte, serial * os.File
             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
 }