+func handleCmdController(tokens []string, remainStr string, client * bufio.ReadWriter) {
+ cmd:=tokens[0]
+ s_r:=strings.NewReader(cmd)
+ char := make([]byte,1)
+ s_r.Read(char)
+ fmt.Println(string(char))
+}
+
+
+func openTTY(name string) *os.File {
+ file, err := os.OpenFile(name,os.O_RDWR ,0600) // For read access.
+ if err != nil {
+ fmt.Println(err.Error())
+ }
+ termios.Ttyfd(file.Fd())
+ termios.SetRaw()
+ return file
+}
+func usage() {
+ fmt.Fprintf(os.Stderr, "usage: myprog [inputfile]\n")
+ flag.PrintDefaults()
+ os.Exit(2)
+}
+
+func SerialWriter(c chan string, serial * os.File ) {
+ for {
+ serial.WriteString(<-c)
+ serial.Sync()
+ }
+}
+
+func SerialReader(c chan string , serial * bufio.Reader) {
+ for {
+ s,err := readLineSafe(serial)
+ if (s=="") {
+ continue
+ }
+ if (err!=nil) {
+ fmt.Printf("Error in read from serial: %v\n",err.Error())
+ os.Exit(1)
+ }
+ fmt.Printf("Serial: Read %v\n",s);
+ c<-s
+ }
+}
+
+func openSerial(filename string) (chan string,chan string) {
+ serial:=openTTY(filename)
+ in:=make(chan string)
+ out:=make(chan string)
+ //go SerialWriter(out,serial)
+ go SerialReader(in,bufio.NewReaderSize(serial,128))
+ return in,out
+}
+
+func SerialHandler(serial_i chan string) {
+ for {
+ fmt.Printf("Serial said: %v\n",<-serial_i);
+ }
+}