setTransmitBuffer()

Description

Sets the value of the private array writeData in the ModbusMasterNode class. writeData is the content of the Modbus packet using the Write function code.

Syntax

node1.setTransmitBuffer(index, value, mode)

Parameters

node1: ModbusMasterNode object.

index: Index value of the writeData array.

value: The value to be filled in the writeData array, i.e. the content of the Modbus packet to be sent.

mode: The mode for reading data from the writeData array. Its argument is MODBUS_DATAMODE_BIT or MODBUS_DATAMODE_UINT16. If no argument is given, it will be preset to MODBUS_DATAMODE_UINT16.

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

#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);

 

    node1.setTransmitBuffer(0, true, MODBUS_DATAMODE_BIT);

    node1.setTransmitBuffer(1, false, MODBUS_DATAMODE_BIT);

    result = node1.writeMultipleCoils(5, 2);  

 

    if (result != MODBUS_SUCCESS) {

        Serial.print("ErrorCode: ");

        Serial.println(result);

    }

}

 

void loop()

{

}

See Also

clearTransmitBuffer()
writeSingleCoil()
writeSingleRegisters()
writeMultipleCoils()
writeMultipleRegisters()
readWriteMultipleRegisters()


Library Reference Home Page

The text in the 86Duino reference is modified from the Arduino reference and is licensed under the Creative Commons Attribution-ShareAlike 3.0 License. The code examples in the reference have been released into the public domain.