maskWriteRegister()

描述

向 Slave 節點發送寫入 Holding Register 暫存器的封包遮罩運算指令,其運算公式如下:
(Current_Contents AND and_mask) OR (or_mask AND (NOT and_mask))

語法


node1.maskWriteRegister(write_address , and_mask , or_mask)

參數

node1ModbusMasterNode 物件。

write_address:欲寫入的 Holding Register 暫存器之位址。

and_mask:「與」閘遮罩參數。

or_mask:「或」閘遮罩參數。

回傳

int:如果成功回傳 MODBUS_SUCCESS,反之回傳 EXCEPTION_CODE

範例

#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.begin(16, bus1); 

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

	if (result != MODBUS_SUCCESS) {
		Serial.print("maskWriteRegister => ErrorCode: ");
		Serial.println(result);
	}
}

void loop()
{
}

函式庫參考主頁面

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.