1 // (c) Bernhard Tittelbach, 2013
9 "svn.spreadspace.org/realraum/go.svn/termios"
13 // ---------- Serial TTY Code -------------
15 func openTTY(name string) (*os.File, error) {
16 file, err := os.OpenFile(name,os.O_RDWR, 0600) // For read access.
18 Syslog_.Println(err.Error())
21 termios.Ttyfd(file.Fd())
26 func serialWriter(in <- chan string, serial * os.File) {
27 for totty := range(in) {
28 serial.WriteString(totty)
34 func serialReader(out chan <- [][]byte, serial * os.File) {
35 linescanner := bufio.NewScanner(serial)
36 linescanner.Split(bufio.ScanLines)
37 for linescanner.Scan() {
38 if err := linescanner.Err(); err != nil {
41 text := bytes.Fields([]byte(linescanner.Text()))
49 func OpenAndHandleSerial(filename string) (chan string, chan [][]byte, error) {
50 serial, err :=openTTY(filename)
54 wr := make(chan string, 1)
55 rd := make(chan [][]byte, 20)
56 go serialWriter(wr, serial)
57 go serialReader(rd, serial)