原来刚用golang的时候,觉得python的twisted库挺好,模仿写了一个,里面有一段监听串口的:
func (p *_reactor) ListenSerial(dev string, client SerialClient, baud int) (rw io.ReadWriteCloser, err error) {
p.initReactor()
p.serial_listeners[dev] = client
fmt.Printf("listening on %s with (%d) Bund\n", dev, baud)
var s *serial.SerialPort
s, err = serial.OpenPort(dev, &serial.Mode{
BaudRate: baud,
DataBits: 8,
Parity: serial.PARITY_NONE,
StopBits: serial.STOPBITS_ONE,
})
if err == nil {
p.serial_conn[dev] = s
}
return s, err
}