You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nnet/connection/serial.go

44 lines
1017 B
Go

package connection
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
}