发表于:2003-04-17 13:22:00
7楼
在 Modbus 的組織網站上,你可以找到更多的資料
www.modbus.org
用搜尋引擎找一下,或許有人提供免費的 DLL 或是 OCX 可以用
如果沒有找到,在 VC 中,你就要自己把 Modbus/RTU 的字串組合起來,丟給 5510,把得到的回應字串拆開,有用的資料取出來即可。
這個協定,只要知道8個基本的Function 就可以了。Modbus/RTU 是要計算 CRC16 的。下面的資料是沒有加上 CRC 的兩個 Byte,命令和回應的最後面,還要再加上兩個byte 的CRC資料。
它的 8 個基本 Function 如下
============================================================
FC1 Read multiple coils status (0xxxx)
[命令]
Byte 0: Net ID (Station number)
Byte 1: FC=01
Byte 2-3: Reference number
Byte 4-5: Bit count
[回應]
Byte 0: Net ID (Station number)
Byte 1: FC=01
Byte 2: Byte count of response (B=(bit count + 7)/8)
Byte 3-(B+2):Bit values (least significant is first coil!)
FC2 Read multiple input discretes (1xxxx)
[命令]
Byte 0: Net ID (Station number)
Byte 1: FC=02
Byte 2-3: Reference number
Byte 4-5: Bit count
[回應]
Byte 0: Net ID (Station number)
Byte 1: FC=02
Byte 2: Byte count of response (B=(bit count + 7)/8)
Byte 3-(B+2):Bit values (least significant is first coil!)
FC3 Read multiple registers (4xxxx)
[命令]
Byte 0: Net ID (Station number)
Byte 1: FC=03
Byte 2-3: Reference number
Byte 4-5: Word count
[回應]
Byte 0: Net ID (Station number)
Byte 1: FC=03
Byte 2: Byte count of response (B=2 x word count)
Byte 3-(B+2):Register values
FC4 Read multiple input registers (3xxxx)
[命令]
Byte 0: Net ID (Station number)
Byte 1: FC=04
Byte 2-3: Reference number
Byte 4-5: Word count
[回應]
Byte 0: Net ID (Station number)
Byte 1: FC=04
Byte 2: Byte count of response (B=2 x word count)
Byte 3-(B+2): Register values
FC5 Write single coil (0xxxx)
[命令]
Byte 0: Net ID (Station number)
Byte 1: FC=05
Byte 2-3: Reference number
Byte 4: =FF to trun ON coil, =00 to trun OFF coil
Byte 5: =00
[回應]
Byte 0: Net ID (Station number)
Byte 1: FC=05
Byte 2-3: Reference number
Byte 4: =FF to trun ON coil, =00 to trun OFF coil
Byte 5: =00
FC6 Write single register (4xxxx)
[命令]
Byte 0: Net ID (Station number)
Byte 1: FC=06
Byte 2-3: Reference number
Byte 4-5: Register value
[回應]
Byte 0: Net ID (Station number)
Byte 1: FC=01
Byte 2-3: Reference number
Byte 4-5: Register value
FC15 Force multiple coils (0xxxx)
[命令]
Byte 0: Net ID (Station number)
Byte 1: FC=0F (hex)
Byte 2-3: Reference number
Byte 4-5: Bit count
Byte 6: Byte count (B=(bit count + 7)/8)
Byte 7-(B+6):Data to be written (least significant is first coil!)
[回應]
Byte 0: Net ID (Station number)
Byte 1: FC=0F (hex)
Byte 2-3: Reference number
Byte 4-5: Bit count
FC16 Write multiple registers (4xxxx)
[命令]
Byte 0: Net ID (Station number)
Byte 1: FC=10 (hex)
Byte 2-3: Reference number
Byte 4-5: Word count
Byte 6: Byte count (B=2 x word count)
Byte 7-(B+6): Register values
[回應]
Byte 0: Net ID (Station number)
Byte 1: FC=10 (hex)
Byte 2-3: Reference number
Byte 4-5: Word count