readCoils()

描述

向 Slave 節點發送讀取 Coils 暫存器的封包指令。

語法


node1.readCoils(read_address, read_size)

參數

node1ModbusMasterNode 物件。

read_address:欲讀取的 Coils 暫存器之起始位址。

read_size:欲讀取的 Coils 暫存器之大小。

回傳

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

範例

#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);

	result = node1.readCoils(5, 2);
	
	if (result != MODBUS_SUCCESS) {
		Serial.print("readCoils => ErrorCode: ");
		Serial.println(result);
	} else {
		Serial.print("From Coil Status receiveData: ");
		Serial.print(node1.getResponseBuffer(0, MODBUS_DATAMODE_BIT));
		Serial.print(", ");
		Serial.println(node1.getResponseBuffer(1, MODBUS_DATAMODE_BIT));
	}
}
 
void loop()
{
}


See Also

getResponseBuffer()


函式庫參考主頁面

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.