func writeToTelescope(s *serial.Port, channel chan []byte) { for { data := <-channel fmt.Println(data) s.Write(data) s.Flush() } }
func sendCommand(p *serial.Port, command string, waitForOk bool) string { log.Println("--- SendCommand: ", command) var status string = "" p.Flush() _, err := p.Write([]byte(command)) if err != nil { log.Fatal(err) } buf := make([]byte, 32) var loop int = 1 if waitForOk { loop = 10 } for i := 0; i < loop; i++ { // ignoring error as EOF raises error on Linux n, _ := p.Read(buf) if n > 0 { status = string(buf[:n]) log.Printf("SendCommand: rcvd %d bytes: %s\n", n, status) if strings.HasSuffix(status, "OK\r\n") || strings.HasSuffix(status, "ERROR\r\n") { break } } } return status }