ModbusMasterNode.setTransmitBuffer()

[Modbus]

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: 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.

Returns

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

Example

#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


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

Scroll to Top