[Modbus]
Description
Send the packet mask operation instruction written to the Holding Register register to the Slave node with the following formula:
(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 to.and_mask
: The “with” gate mask parameter.or_mask
: “or” gate mask parameter.
Returns
Int: If it succeeds, send back MODBUS_SUCCESS and vice versa, send back EXCEPTION_CODE.
Example
#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() { }
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.