Example #1
0
func (mb *serialPort) Connect() (err error) {
	if mb.isConnected {
		return
	}
	if mb.port == nil {
		mb.port, err = serial.Open(&mb.Config)
	} else {
		err = mb.port.Open(&mb.Config)
	}
	if err == nil {
		mb.isConnected = true
	}
	return
}
Example #2
0
func main() {
	if len(os.Args) > 1 {
		address = os.Args[1]
	}
	port, err := serial.Open(&serial.Config{
		Address: address,
		Timeout: 30 * time.Second,
	})
	if err != nil {
		log.Fatal(err)
	}
	defer port.Close()

	if _, err = port.Write([]byte("serial")); err != nil {
		log.Fatal(err)
	}
	if _, err = io.Copy(os.Stdout, port); err != nil {
		log.Fatal(err)
	}
}
Example #3
0
func main() {
	addr, err := homedir.Expand("~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty")
	if err != nil {
		log.Fatal(err)
	}

	c := &serial.Config{
		Address:  addr,
		BaudRate: 9600,
	}
	s, err := serial.Open(c)
	if err != nil {
		log.Fatal(err)
	}
	defer s.Close()

	go read(s)
	go write(s)
	go sigh(s)
	detach()
}