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.
ntool-biz/nmodbus/protocol/packet_rtu.go

50 lines
792 B
Go

package protocol
var _ Packet = (*RTUPacket)(nil)
type (
RTUPacket struct {
*ModbusHeader
Data []byte // 数据
CRC uint16 // CRC校验码
}
)
func (p *RTUPacket) Copy() Packet {
c := *p
return &c
}
func NewRTUPacket() *RTUPacket {
return &RTUPacket{ModbusHeader: &ModbusHeader{}}
}
func (p *RTUPacket) GetHeader() interface{} {
return p.ModbusHeader
}
func (p *RTUPacket) GetLen() uint64 {
return uint64(len(p.Data))
}
func (p *RTUPacket) GetBody() []byte {
return p.Data
}
func (p *RTUPacket) GetFunction() uint8 {
return p.Function
}
func (p *RTUPacket) GetAddress() uint8 {
return p.Address
}
func (p *RTUPacket) SetBody(data []byte) {
p.Data = data
}
func (p *RTUPacket) SetError(err *MError) {
p.Function = p.Function | 0x80
p.Data = []byte{byte(*err)}
}