send()

Description

Sets the arguments to the private array writeData in the ModbusMasterNode class and automatically stacks the data, using beginTransmission with writeMultipleRegisters without parameters. writeData is the content of the Modbus packet using the Write function code.

Syntax

node1.send(value)

Parameters

node1: ModbusMasterNode object.

value: The value to be filled into the writeData array, i.e. the Modbus packet content to be sent. The type can be uint8_t, uint16_t or uint32_t.

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

#include <Arduino.h>

#include <Modbus86.h>

 

ModbusMaster bus1;

ModbusMasterNode node2;

 

uint8_t reg[2];

uint8_t result;

 

void setup()

{

    while(!Serial);

    bus1.begin(MODBUS_RTU,Serial1);

    node2.attach(16, bus1);

 

    reg[0] = 0x1234;

    reg[1] = 0xabcd;

    node2.beginTransmission(5);

    node2.send(reg[0]);

    node2.send(reg[1]);

    result = node2.writeMultipleRegisters();

 

    if (result != MODBUS_SUCCESS) {

        Serial.print("ErrorCode: ");

        Serial.println(result);

    }

}

 

void loop()

{

}

See Also

beginTransmission()
writeMultipleRegisters()


Library Reference

The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.