maskWriteRegister()

Description

Sends a packet mask operation instruction to the Slave node to write into the Holding Register register. The operation formula is as follows: (Current_Contents AND and_mask) OR (or_mask AND (NOT and_mask))

Syntax

node1.maskWriteRegister(write_address, and_mask, or_mask)

Parameters

node1: ModbusMasterNode object.

write_address: The address of the Holding Register to be written.

and_mask: "AND" gate mask parameter.

or_mask: "OR" gate mask parameter.

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

#include <Modbus86.h>

 

#define AND_MASK    0xF87F

#define OR_MASK     0x0300

     

ModbusMaster bus1;

ModbusMasterNode node1;

 

uint8_t result;

 

void setup()

{

    while(!Serial);

    Serial1.begin(115200);

    bus1.begin(MODBUS_RTU, Serial1);

    node1.attach(16, bus1);

 

    result = node1.maskWriteRegister(5, AND_MASK, OR_MASK);

 

    if (result != MODBUS_SUCCESS) {

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

        Serial.println(result);

    }

}

void loop()

{

}

 


Library Reference

86Duino Reference Text Follows Creative Commons Attribution-Share Alike 3.0 License. The code examples in the references have been released into the public domain.