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.
44 lines
1.5 KiB
Go
44 lines
1.5 KiB
Go
package serialize
|
|
|
|
import (
|
|
"encoding/binary"
|
|
)
|
|
|
|
var serializer = NewSerializer(binary.BigEndian)
|
|
|
|
func defaultSerializer() *Serializer {
|
|
return serializer
|
|
}
|
|
|
|
func SetByteOrder(order binary.ByteOrder) {
|
|
if order == nil {
|
|
return
|
|
}
|
|
defaultSerializer().byteOrder = order
|
|
}
|
|
|
|
// RegisterAddressAndNumber 返回数据帧中的 寄存器起始地址 数量 计算后的结束地址
|
|
func RegisterAddressAndNumber(data []byte) (register int, numRegs int, endRegister int) {
|
|
return defaultSerializer().RegisterAddressAndNumber(data)
|
|
}
|
|
|
|
// RegisterAddressAndValue 获取数据帧中的 寄存器起始地址 数据
|
|
func RegisterAddressAndValue(data []byte) (register int, value uint16) {
|
|
return defaultSerializer().RegisterAddressAndValue(data)
|
|
}
|
|
|
|
// WriteWithRegisterAndNumber 生成 寄存器起始地址 和 数量
|
|
func WriteWithRegisterAndNumber(register uint16, number uint16) []byte {
|
|
return defaultSerializer().WriteWithRegisterAndNumber(register, number)
|
|
}
|
|
|
|
// WriteWithRegisterAndNumberAndValue 写入 寄存器起始地址 数量 数据
|
|
func WriteWithRegisterAndNumberAndValue(register uint16, number uint16, values []uint16) []byte {
|
|
return defaultSerializer().WriteWithRegisterAndNumberAndValue(register, number, values)
|
|
}
|
|
|
|
// WriteWithRegisterAndNumberAndBytes 写入 寄存器起始地址 数量 数据
|
|
func WriteWithRegisterAndNumberAndBytes(register uint16, number uint16, bytes []byte) []byte {
|
|
return defaultSerializer().WriteWithRegisterAndNumberAndBytes(register, number, bytes)
|
|
}
|