ModbusMasterNode.available()

[Modbus]

描述

Return the data number 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.available()

參數

node1: ModbusMasterNode object.

回傳

uint8_t: Return the data number of the private array readData in the ModbusMasterNode class.

範例

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

也可以看看


函式庫參考主頁面

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

發表評論

上部へスクロール