已解决 采集脚本贴上
!ArrayResize(SendByteArr,6)
SendByteArr[1] = &H01
SendByteArr[2] = &H03
SendByteArr[3] = &H00
SendByteArr[4] = &H6B
nReturn = !SvrByteArrayModbusCRC(SendByteArr,1,4)
SendByteArr[5] = !BitAnd(nReturn,&H000000FF)
nTmp = !BitAnd(nReturn,&H0000FF00)
SendByteArr[6] = !BitRShift(nTmp ,8)
‘发送和接收数据按如下方式:
!ArrayResize(RecByteArr,9)
nReturn = !DevWriteAndReadByteArr(SendByteArr, 6, RecByteArr, 9, 通讯延时)
if nReturn <> 9 then
!SetSingleChannelValueByName("通讯状态", 1)
exit
endif
nIndex = 0
!ArrayResize(DataByteArr,1)
while nIndex < 7
DataByteArr[1] = RecByteArr[nIndex*1+1]
nReturn = !SvrGetByteFromByteArr(DataByteArr,1,开关数据,0)
数值数据 = 开关数据
!SetSingleChannelValueByNum(nIndex+nChlIndex+2,数值数据)
nIndex = nIndex + 1
endwhile
nChlIndex = nChlIndex + nIndex‘设置通讯标志,解析都正确
!SetSingleChannelValueByName("通讯状态", 0)
!SetSingleChannelValueByName("AI01",RecByteArr[1] )
!SetSingleChannelValueByName("AI02",RecByteArr[2] )
!SetSingleChannelValueByName("AI03",RecByteArr[3] )
!SetSingleChannelValueByName("AI04",RecByteArr[4] )
!SetSingleChannelValueByName("AI05",RecByteArr[5] )
!SetSingleChannelValueByName("AI06",RecByteArr[6] )
!SetSingleChannelValueByName("AI07",RecByteArr[7] )
百度一下就可以解决的事情,工作了要学会自己解决问题哈,不是在学校了
他那个协议是不标准
但我确实是通过上面那个协议做的,现在也成功采集到了数据。
不过还是谢谢你
ArrayResize(SendByteArr,6)
SendByteArr[1] = &H01
SendByteArr[2] = &H03
SendByteArr[3] = &H00
SendByteArr[4] = &H6B
nReturn = !SvrByteArrayModbusCRC(SendByteArr,1,4)
SendByteArr[5] = !BitAnd(nReturn,&H000000FF)
nTmp = !BitAnd(nReturn,&H0000FF00)
SendByteArr[6] = !BitRShift(nTmp ,8)
‘发送和接收数据按如下方式:
!ArrayResize(RecByteArr,9)
nReturn = !DevWriteAndReadByteArr(SendByteArr, 6, RecByteArr, 9, 通讯延时)
if nReturn <> 9 then
!SetSingleChannelValueByName("通讯状态", 1)
exit
endif