writeMultipleCoils()

Description

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

Syntax

node1.writeMultipleCoils(write_address, write_size) node2.writeMultipleCoils() - 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 Coils register to be written.

write_size: The size of the coils register 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

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

{

}

 

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

#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

– writeSingleCoil()
– setTransmitBuffer()
– beginTransmission()
– sendBit()

 


Library Reference

The text of the 86Duino reference material is licensed under the Creative Commons Attribution-Share Alike 3.0 License. The code examples in the reference material have been released into the public domain.