better go, but still needs alternative to go-zmq
[svn42.git] / go / door_daemon_zmq / serial_tty.go
index 4ec786a..d7fd7a9 100644 (file)
@@ -24,14 +24,14 @@ 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()
     }
 }
 
-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 +43,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)
+       rd := make(chan [][]byte, 10)
+    go serialWriter(wr, serial)
+    go serialReader(rd, serial)
     return wr, rd, nil
 }