I want to find...

Search

Shares

Table of Content

ModbusMasterNode.writeMultipleCoils()

[Modbus]

Description

Send a packet command to the Slave node to write to multiple Coils registers.

Syntax

node1.writeMultipleCoils(write_address, write_size)
node2.writeMultipleCoils()

(See the example to illustrate the different functions and usage methods with or without parameters)

Parameters

  • node1/node2: ModbusMasterNode Object.
  • write_address: The starting address of the Coils register you want to write to.
  • write_size: The size of the Coils register that you want to write to.

Returns

Int: If it succeeds, send back MODBUS_SUCCESS and vice versa, send back EXCEPTION_CODE.

Example

#include <Arduino.h>
#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()
{
}
#include <Arduino.h>
#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.beginTransmission(5);
    node1.sendBit(true);
    node1.sendBit(false);
    result = node1.writeMultipleCoils();
 
    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