receive()

描述

回傳 ModbusMasterNode 類別中的私有陣列 readData 的資料。
readData 是使用 Read 功能碼讀回 Slave 裝置暫存器後存放的陣列。

語法


node1.receive()

參數

node1ModbusMasterNode 物件。

回傳

uint16_t:回傳 ModbusMasterNode 類別中的私有陣列 readData 的資料

範例

#include <Modbus86.h>
 
ModbusMaster bus1;
ModbusMasterNode node1;

uint8_t result;

uint8_t j = 0;
uint16_t data[6];

void setup()
{
	while(!Serial);
	Serial1.begin(115200);
	bus1.begin(MODBUS_RTU, Serial1);
	node1.begin(16, bus1);

	result = node1.readHoldingRegisters(0, 6);
	if (result != MODBUS_SUCCESS) {
		Serial.print("readHoldingRegisters => ErrorCode: ");
		Serial.println(result);
	} else {
		Serial.print("From Holding Register receiveData: ");
		while(node1.available() > 0) {
			data[j++] = node1.receive();
			Serial.println(data[j - 1]);
		}
	}
}
 
void loop()
{
}


See Also

available()


函式庫參考主頁面

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.