writeSingleCoil()

Description

Sends a packet command to the Slave node to write to a single Coil register.

Syntax

node1.writeSingleCoil(write_address, value)

Parameters

node1: ModbusMasterNode object.

write_address: The address of the Coil register to be written.

value: The value of the Coil register to be written, usually 0 or 1.

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

#include <Modbus86.h>

  

ModbusMaster bus1;

ModbusMasterNode node1;

 

uint8_t result;

uint8_t led = 1;

     

void setup()

{

    while(!Serial);

    Serial1.begin(115200);

    bus1.begin(MODBUS_RTU, Serial1);

    node1.attach(16, bus1);

 

    result = node1.writeSingleCoil(5, led);

     

    if (result != MODBUS_SUCCESS) {

        Serial.print("writeSingleCoil => ErrorCode: ");

        Serial.println(result);

    }

}

  

void loop()

{

}

 

See Also

writeMultipleCoils()


Library Reference

86Duino Reference Text Modified from Arduino Reference Material, licensed under a Creative Commons Attribution-Share Alike 3.0 License. The code examples in the reference material have been released into the public domain.