描述
向 Slave 节点发送读取 Coils 暂存器的封包指令。
语法
node1.readCoils(read_address, read_size)
参数
node1
: ModbusMasterNode
物件。
read_address
:欲读取的 Coils 暂存器之起始位址。
read_size
:欲读取的 Coils 暂存器之大小。
回传
int
:如果成功回传 MODBUS_SUCCESS
,反之回传 EXCEPTION_CODE 。
范例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include <Modbus86.h>
ModbusMaster bus1;
ModbusMasterNode node1;
uint8_t result;
void setup()
{
while (!Serial);
Serial1.begin(115200);
bus1.begin(MODBUS_RTU, Serial1);
node1.attach(16, bus1);
result = node1.readCoils(5, 2);
if (result != MODBUS_SUCCESS) {
Serial.print( "readCoils => ErrorCode: " );
Serial.println(result);
} else {
Serial.print( "From Coil Status receiveData: " );
Serial.print(node1.getResponseBuffer(0, MODBUS_DATAMODE_BIT));
Serial.print( ", " );
Serial.println(node1.getResponseBuffer(1, MODBUS_DATAMODE_BIT));
}
}
void loop()
{
}
|
See Also
- getResponseBuffer()
86Duino 参考资料中的文字修改自 Arduino 参考资料,并根据 知识共享署名-许可证方式共享 3.0 授权。参考资料中的程式码范例已发布到公共领域。