Golang package for serial port
A Go package that allow you to read and write from the serial port.
This is a forked repo written by @tarm.
package main
import (
"time"
"github.com/argandas/serial"
)
func main() {
sp := serial.New()
err := sp.Open("COM1", 9600)
if err != nil {
panic(err)
}
defer sp.Close()
sp.Println("AT")
sp.WaitForRegexTimeout("OK.*", time.Second * 10)
}
By default the returned serial port reads in blocking mode. Which means Read()
will block until at least one byte is returned. If that's not what you want, specify a positive ReadTimeout and the Read() will timeout returning 0 bytes if no bytes are read. Please note that this is the total timeout the read operation will wait and not the interval timeout between two bytes.
sp := serial.New()
err := sp.Open("COM1", 9600, time.Second * 5)