package conn import ( "git.noahlan.cn/noahlan/ntool/nlog" "github.com/goburrow/serial" "net" "time" ) // SerialConn serial connection wrapper type SerialConn struct { serial.Port config *serial.Config } // NewSerialConn 新建 SerialConn func NewSerialConn(port serial.Port, cfg *serial.Config) net.Conn { return &SerialConn{Port: port, config: cfg} } func (c *SerialConn) LocalAddr() net.Addr { cfg := c.config return NewSerialAddr(cfg.Address, cfg.BaudRate, cfg.DataBits, cfg.StopBits, cfg.Parity) } func (c *SerialConn) RemoteAddr() net.Addr { return c.LocalAddr() } func (c *SerialConn) SetDeadline(_ time.Time) error { nlog.Error("SetDeadline in serial connection was not supported.") return nil } func (c *SerialConn) SetReadDeadline(_ time.Time) error { nlog.Error("SetReadDeadline in serial connection was not supported.") return nil } func (c *SerialConn) SetWriteDeadline(_ time.Time) error { nlog.Error("SetWriteDeadline in serial connection was not supported.") return nil }