Documentation ¶
Index ¶
- func TCPClient(address string) modbus.Client
- type TCPClientHandler
- func (mb *TCPClientHandler) Close() error
- func (mb *TCPClientHandler) Connect() error
- func (mb *TCPClientHandler) Decode(adu []byte) (pdu *modbus.ProtocolDataUnit, err error)
- func (mb *TCPClientHandler) Encode(pdu *modbus.ProtocolDataUnit) (adu []byte, err error)
- func (mb *TCPClientHandler) Received(handler func(data []byte))
- func (mb *TCPClientHandler) Send(aduRequest []byte) (aduResponse []byte, err error)
- func (mb *TCPClientHandler) Verify(aduRequest []byte, aduResponse []byte) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type TCPClientHandler ¶
type TCPClientHandler struct {
// contains filtered or unexported fields
}
TCPClientHandler implements Packager and Transporter interface.
func NewTCPClientHandler ¶
func NewTCPClientHandler(address string) *TCPClientHandler
NewTCPClientHandler allocates a new TCPClientHandler.
func (*TCPClientHandler) Close ¶
func (mb *TCPClientHandler) Close() error
Close closes current connection.
func (*TCPClientHandler) Connect ¶
func (mb *TCPClientHandler) Connect() error
Connect establishes a new connection to the address in Address. Connect and Close are exported so that multiple requests can be done with one session
func (*TCPClientHandler) Decode ¶
func (mb *TCPClientHandler) Decode(adu []byte) (pdu *modbus.ProtocolDataUnit, err error)
Decode extracts PDU from TCP frame:
Transaction identifier: 2 bytes Protocol identifier: 2 bytes Length: 2 bytes Unit identifier: 1 byte
func (*TCPClientHandler) Encode ¶
func (mb *TCPClientHandler) Encode(pdu *modbus.ProtocolDataUnit) (adu []byte, err error)
Encode adds modbus application protocol header:
Transaction identifier: 2 bytes Protocol identifier: 2 bytes Length: 2 bytes Unit identifier: 1 byte Function code: 1 byte Data: n bytes
func (*TCPClientHandler) Received ¶
func (mb *TCPClientHandler) Received(handler func(data []byte))
处理服务端响应
Click to show internal directories.
Click to hide internal directories.