humodbus

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DataTypeBool = 0 // 开关类型

	DataTypeInt  = 10 // 16整型
	DataTypeUint = 11 // 16无符号整型

	DataTypeLong  = 20 // 32长整型
	DataTypeUlong = 21 // 32无符号整型
	DataTypeFloat = 22 // 32浮点型

	DataTypeDouble = 30 // 64浮点型
)

数据类型 [0, 10) 少于16位, [10, 20) 16位, [20, 30) 32位, [30, 40) 64位. 通过 / 10 得到 商 [0,1,2,3] >> [<16, 16, 32, 46]

View Source
const (
	ABCD = 0
	DCBA = 1
	CDAB = 2
	BADC = 3
)

Variables

This section is empty.

Functions

func AddMBAPHead added in v1.0.4

func AddMBAPHead(cmdbody []byte, args ...byte) []byte

添加MBAP头

func ByteToFloat32

func ByteToFloat32(bytes []byte) float32

func ByteToFloat64

func ByteToFloat64(bytes []byte) float64

func ByteToInt16 added in v1.0.4

func ByteToInt16(bytes []byte) int

大小端模式需要验证

func ByteToLong added in v1.0.4

func ByteToLong(bytes []byte) int

大小端模式需要验证

func ByteToUint16 added in v1.0.4

func ByteToUint16(bytes []byte) uint16

func ByteToUint32 added in v1.0.4

func ByteToUint32(bytes []byte) uint32

func Bytes2Data added in v1.0.4

func Bytes2Data(databyte []byte, datatype int) interface{}

字节数组转数值

func Bytes2Uint16

func Bytes2Uint16(buf []byte) []uint16

bytes2Uint16 bytes convert to uint16 for register.

func CRC16

func CRC16(bs []byte) uint16

CRC16 Calculate Cyclical Redundancy Checking.

func CRC16Byte

func CRC16Byte(bs []byte) []byte

CRC16Byte 得到CRC16 byte[]

func Data2bytes added in v1.0.4

func Data2bytes(datastr string, datatype int) (databytes []byte)

数值转字节数组

func Float32ToByte

func Float32ToByte(float float32) []byte

func Float32ToStr

func Float32ToStr(f float32) string

Float32ToStr float32 convent to hexstr

func Float64ToByte

func Float64ToByte(float float64) []byte

func GetDCBA

func GetDCBA(in []byte, types int) (out []byte)

大端模式用DCBA 测试用Modbus slave ABCD的数据要用DCBA才能正确获取

func ModbusCRC added in v1.0.4

func ModbusCRC(bs []byte) uint16

CRC16直接法

func ModbusCRCCheck added in v1.0.4

func ModbusCRCCheck(resp []byte) bool

CRC校验

func StrToFloat32

func StrToFloat32(i string) float32

StrToFloat32 hexstr convent to float32

func Uint162Bytes

func Uint162Bytes(value ...uint16) []byte

uint162Bytes creates a sequence of uint16 data.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL