ModbusMasterNode.readHoldingRegisters()

[Modbus]

説明

Send a packet command to the Slave node to read the Holding Registers register.

Syntax

node1.readHoldingRegisters(read_address, read_size)

Parameters

  • node1: ModbusMasterNode Object.
  • read_address: The starting address of the Holding Registers register to be read.
  • read_size: The size of the Holding Registers register to be read.

Returns

Int: If it succeeds, send back MODBUS_SUCCESS and vice versa, send back EXCEPTION_CODE.

Example

#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.readHoldingRegisters(5, 2);
     
    if (result != MODBUS_SUCCESS) {
        Serial.print("readHoldingRegisters => ErrorCode: ");
        Serial.println(result);
    } else {
        Serial.print("From Holding Register receiveData: ");
        receiveData = node1.getResponseBuffer(0)
                    | (node1.getResponseBuffer(1) << 16);
        Serial.println(receiveData);
    }
}
  
void loop() {}

See Also


Libraries Reference Home

86Duino のリファレンスのテキストは Arduino レファレンス を編集したもので、 Creative Commons Attribution-ShareAlike 3.0 License下でライセンスされています。リファレンス内のコードサンプルはパブリックドメインとして公開されています。

コメントする

上部へスクロール