Description
Sends a packet command to write multiple Holding Registers to the Slave node.
Syntax
node1.writeMultipleRegister(write_address, write_size) node2.writeMultipleRegister() - The function and usage are different with or without parameters. See the example for details.
Parameters
node1/node2: ModbusMasterNode object.
write_address: The starting address of the Holding Registers to be written.
write_size: The size of the Holding Registers to be written.
Return
int: If successful, return MODBUS_SUCCESS, otherwise return EXCEPTION_CODE.
Example
|
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
31
|
#include <Arduino.h>
#include <Modbus86.h>
ModbusMaster bus1;
ModbusMasterNode node1;
uint8_t reg[2];
uint8_t result;
void setup()
{
while(!Serial);
Serial1.begin(115200);
bus1.begin(MODBUS_RTU, Serial1);
node1.attach(16, bus1);
reg[0] = 0x1234;
reg[1] = 0xabcd;
node1.setTransmitBuffer(0, reg[0], MODBUS_DATAMODE_UINT16);
node1.setTransmitBuffer(1, reg[1], MODBUS_DATAMODE_UINT16);
result = node1.writeMultipleRegisters(5, 2);
if (result != MODBUS_SUCCESS) {
Serial.print("ErrorCode: ");
Serial.println(result);
}
}
void loop()
{
}
|
|
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
31
32
|
#include <Arduino.h>
#include <Modbus86.h>
ModbusMaster bus1;
ModbusMasterNode node2;
uint8_t reg[2];
uint8_t result;
void setup()
{
while(!Serial);
Serial1.begin(115200);
bus1.begin(MODBUS_RTU, Serial1);
node2.attach(16, bus1);
reg[0] = 0x1234;
reg[1] = 0xabcd;
node2.beginTransmission(5);
node2.send(reg[0]);
node2.send(reg[1]);
result = node2.writeMultipleRegisters();
if (result != MODBUS_SUCCESS) {
Serial.print("ErrorCode: ");
Serial.println(result);
}
}
void loop()
{
}
|
See Also
writeSingleRegister()
setTransmitBuffer()
beginTransmission()
send()
86Duino 參考資料的文本遵循 知識共享署名-相同方式共享 3.0 許可證。參考資料中的程式碼範例已發佈到公共領域。