我想找...

搜尋

分享

目錄

ModbusMasterNode.getResponseBuffer()

[Modbus]

描述

Reads the value of the private array readData in the ModbusMasterNode class.

readData is the array stored after reading back to the Slave device registers using the Read function code.

語法

node1.getResponseBuffer(index, mode)

參數

  • node1: ModbusMasterNode object.
  • index: index value of the readData array.
  • mode: mode of reading data from readData array, its citation is MODBUS_DATAMODE_BIT or MODBUS_DATAMODE_UINT16. If no citation is given it will be MODBUS_DATAMODE_UINT16 by default.

回傳

int: The value taken from the readData array, or 0xFFFF if it is wrong.

範例

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

也可以看看


函式庫參考主頁面

86Duino 參考的文本是根據 Creative Commons Attribution-ShareAlike 3.0 License,部分文本是從 the Arduino reference 修改的。 參考中的代碼示例已發佈到公共領域。

返回頂端