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.


node1.setTransmitBuffer(index, value, mode)


  • node1: ModbusMasterNode object.
  • index: the 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: mode of reading data from writeData array, the citation is MODBUS_DATAMODE_BIT or MODBUS_DATAMODE_UINT16, if no citation is given it will be MODBUS_DATAMODE_UINT16 by default.


int: if successful return MODBUS_SUCCESS and vice versa return EXCEPTION_CODE.


#include <Modbus86.h>
ModbusMaster bus1;
ModbusMasterNode node1;
uint8_t result;
void setup()
    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: ");
void loop() {}

See Also

Libraries Reference Home

The text of the 86Duino reference is a modification of the Arduino reference and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top