getResponseBuffer()

描述

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

語法


node1.getResponseBuffer(index, mode)

參數

node1ModbusMasterNode 物件。

indexreadData 陣列的索引值。

mode:從 readData 陣列中讀取數據的模式,其引數為 MODBUS_DATAMODE_BITMODBUS_DATAMODE_UINT16 ,若不給予引數將預設為 MODBUS_DATAMODE_UINT16

回傳

int:從 readData 陣列中取出的數值,錯誤則回傳 0xFFFF 。

範例

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

uint8_t result;
uint32_t receiveData;

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: ");
		receiveData = node1.getResponseBuffer(0) 
					| (node1.getResponseBuffer(1) << 16);
		Serial.println(receiveData);
	}
}
 
void loop()
{
}


See Also

clearResponseBuffer()
readCoils()
readDiscreteInputs()
readHoldingRegisters()
readInputRegisters()
readWriteMultipleRegisters()


函式庫參考主頁面

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.