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/rtu_addr.go

36 lines
655 B
Go

package connection
import (
"fmt"
"net"
)
const RTUNetwork = "rtu"
type RTUAddr struct {
Address string
BaudRate int
DataBits int
StopBits int
Parity string
}
func NewRTUAddr(addr string, rate int, dataBits int, stopBits int, parity string) net.Addr {
return &RTUAddr{
Address: addr,
BaudRate: rate,
DataBits: dataBits,
StopBits: stopBits,
Parity: parity,
}
}
func (r *RTUAddr) Network() string {
return RTUNetwork
}
// String form of address (for example, "/dev/ttyS0|19200|8|1|N", "com1|19200|8|1|N")
func (r *RTUAddr) String() string {
return fmt.Sprintf("%s|%d|%d|%d", r.Address, r.BaudRate, r.DataBits, r.StopBits)
}