区域
整数型
起始字
结束标志
结束标志
校验位
校验位
*:加*不参与crc32运算。
crc32的计算方法:vb代码如下:
function calccrc(data(), arraylen) as long
dim i, j, k, h as integer
for i = 0 to arraylen
j = j xor data(i)
for k = 1 to 8
h = j mod 2 'test if bit will be shifted out
j = int(j / 2) 'shift right
if h then
j = j xor &h1000a001 'xor with constant
j = j - &h10000000 'clear top word
end if
next k
next i
calccrc = j
end function
private sub command1_click()
dim i, j as long
length = (len(text3.text)) / 2 - 1
redim init(length)
for i = 0 to length
init(i) = val("&h" + mid(text3.text, 2 * i + 1, 2))
next i
j = calccrc(init(), length)
text2.text = hex(j mod 256)
text1.text = hex(int(j / 256))
end sub
发送这串字符将会能得到得到n7的数据返回,返回的数据以字为单位,开始字与字个数决定返回的内容。
三、 接收到的数据
如上接收到的数据,以 10 06 10 02开始,00 01 4f 00 27 04为目的址与id号,现再接着是返回的数据,每两个字节是一组数据:如我的plc中的定义如下: