I want to find...

Search

Shares

Table of Content

ModbusMasterNode.readDiscreteInputs()

[Modbus]

Description

Sends a packet command to the Slave node to read the Discrete Inputs register.

Syntax

node1.readDiscreteInputs(read_address, read_size)

Parameters

  • node1: ModbusMasterNode Object.
  • read_address: The starting address of the Discrete Inputs register to be read.
  • read_size: The size of the Discrete Inputs 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;
     
void setup()
{
    while(!Serial);
    Serial1.begin(115200);
    bus1.begin(MODBUS_RTU, Serial1);
    node1.attach(16, bus1);
 
    result = node1.readDiscreteInputs(5, 2);
     
    if (result != MODBUS_SUCCESS) {
        Serial.print("readDiscreteInputs => ErrorCode: ");
        Serial.println(result);
    } else {
        Serial.print("From Input Status receiveData: ");
        Serial.print(node1.getResponseBuffer(0, MODBUS_DATAMODE_BIT));
        Serial.print(", ");
        Serial.println(node1.getResponseBuffer(1, MODBUS_DATAMODE_BIT));
    }
}
 
void loop() {}

See Also


Libraries Reference Home

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.

Leave a Comment

Scroll to Top