发布于 2006-11-29 12:15:19
0楼
LD SM0.0
BMB *AC3, VB3340, 8 //COPY输入或输出到可擦写区(VB3340-VB3347)
MOVB 0, VB3348 //把可擦写区的下面字节(VB3348)置0
MOVD &VB3340, AC3 //源指针=可擦写区地址
MOVW VW3304, VW3562 //取start_bit值
DIV +8, VD3560 //start_bit/8
+I VW3562, AC3 //源指针加上偏置值
MOVW VW3306, AC1 //取bit_count存入AC1
+I +7, AC1 //AC1+7
SRW AC1, 3 //除以8(位/字节)
MOVW AC1, VW3300 //取byte_count
+I +3, VW3300 //加头部3个字节
MOVB AC1, VB3304 //装入字节计数器
以上是自由口modbus主站例子中SBR_52中功能为1的程序,可是我不明白加头部3个字节是怎么回事,加的是哪3个字节,作什么用的呢?还有我看了自由口从站的例子其中在SBR_57功能16中Determine Byte Count Received中 Compare the number of bytes received to the word_count from the message
to be sure that you received enough data bytes. The receive byte_count
should equal the (word_count * 2) + 9 overhead bytes此处为什么要加9呢???不明白这9个字节是什么呀???. Also verify that the
word count is no greater than 60 (120 bytes), the maximum allowed by
the function.
Also verify that the word_count * 2 is equal to the byte_count. It
is a little redundant to double check all of these fields, but you
should be complete.
LD Always_On:SM0.0 // Every scan cycle,
MOVW VW3306, AC0 // get the word_count,
SLW AC0, 1 // multiply the word_count by 2,
-I +9, VW3300 // and Receive byte_count - 9.
大家能不能帮忙解释一下呀?谢了!