// handle the serial port communication. When data comes in through // the serial port write it to the channel for the socket to see. When // data comes in from the socket over the channel translate the message // and write to serial port func handlePort(p *serial.Port, ch chan []byte) { readCh := make(chan []byte) go serialRead(p, readCh) for { select { case s := <-ch: { // map gui -> micro trans := mapGui.ItemTranslate(string(s)) _, err := p.Write([]byte(trans)) if err != nil { fmt.Println(err) } } case r := <-readCh: { ch <- r } case <-time.After(timeout): continue } } }