writeMultipleCoils()

描述

向 Slave 節點發送寫入多個 Coils 暫存器的封包指令。

語法


node1.writeMultipleCoils(write_address, write_size)
node2.writeMultipleCoils()
- 有無參數所搭配的函式與使用方法不同,詳見範例以示說明。

參數

node1/node2ModbusMasterNode 物件。

write_address:欲寫入的 Coils 暫存器之起始位址。

write_size:欲寫入的 Coils 暫存器之大小。

回傳

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

範例

#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.begin(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()
{
}
#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.begin(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()


函式庫參考主頁面

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.