writeSingleCoil()

描述

向 Slave 節點發送寫入單一 Coil 暫存器的封包指令。

語法


node1.writeSingleCoil(write_address, value)

參數

node1ModbusMasterNode 物件。

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

value:欲寫入的 Coil 暫存器之值,通常為 0 或 1 。

回傳

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

範例

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

	result = node1.writeSingleCoil(5, led);
	
	if (result != MODBUS_SUCCESS) {
		Serial.print("writeSingleCoil => ErrorCode: ");
		Serial.println(result);
	}
}
 
void loop()
{
}


See Also

writeMultipleCoils()


函式庫參考主頁面

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.