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.
36 lines
679 B
Go
36 lines
679 B
Go
1 year ago
|
package connection
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net"
|
||
|
)
|
||
|
|
||
1 year ago
|
const SerialNetwork = "serial"
|
||
1 year ago
|
|
||
1 year ago
|
type SerialAddr struct {
|
||
1 year ago
|
Address string
|
||
|
BaudRate int
|
||
|
DataBits int
|
||
|
StopBits int
|
||
|
Parity string
|
||
|
}
|
||
|
|
||
1 year ago
|
func NewSerialAddr(addr string, rate int, dataBits int, stopBits int, parity string) net.Addr {
|
||
|
return &SerialAddr{
|
||
1 year ago
|
Address: addr,
|
||
|
BaudRate: rate,
|
||
|
DataBits: dataBits,
|
||
|
StopBits: stopBits,
|
||
|
Parity: parity,
|
||
|
}
|
||
|
}
|
||
|
|
||
1 year ago
|
func (r *SerialAddr) Network() string {
|
||
|
return SerialNetwork
|
||
1 year ago
|
}
|
||
|
|
||
|
// String form of address (for example, "/dev/ttyS0|19200|8|1|N", "com1|19200|8|1|N")
|
||
1 year ago
|
func (r *SerialAddr) String() string {
|
||
1 year ago
|
return fmt.Sprintf("%s|%d|%d|%d", r.Address, r.BaudRate, r.DataBits, r.StopBits)
|
||
|
}
|