receive()

Description

Returns the data of the private array readData in the ModbusMasterNode class. readData is the array stored after reading back the Slave device register using the Read function code.

Syntax

node1.receive()

Parameters

node1: ModbusMasterNode object.

Return

uint16_t: Returns the data of the private array readData in the ModbusMasterNode class

Example

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

#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()

{

}

See Also

available()


Library Reference

The text of the 86Duino reference material follows the Creative Commons Attribution-Share Alike 3.0 License. The code examples in the reference material have been released into the public domain.