attach()

Description

Initializes the ModbusSlaveNode object and specifies the mount channel and node number.

Syntax

node1.attach(slave_id, bus1) node2.attach(bus2)

Parameters

node1/node2: ModbusSlaveNode object.

slave_id: Specifies the slave node number. In TCP mode, if the number is not specified, the number will be preset to MODBUS_TCP_SLAVE (0xFF).

bus1/bus2: Specifies the ModbusSlave object to be mounted.

Return

bool: If successful, return true, otherwise return false

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

#include <Ethernet.h>

#include <Modbus86.h>

 

ModbusSlave bus1;

ModbusSlave bus2;

 

ModbusSlaveNode node1;

ModbusSlaveNode node2;

 

void setup()

{

    Serial1.begin(115200);

    bus1.begin(MODBUS_RTU, Serial1);

    // bus1.begin(MODBUS_ASCII, Serial1);

     

    Ethernet.begin();

    bus2.begin(MODBUS_TCP);

     

    node1.attach(16, bus1);

    node2.attach(bus2);

    // node2.attach(MODBUS_TCP_SLAVE, bus2);

}

 

void loop()

{

}

See Also

ModbusSlave::begin()
ModbusMasterNode::attach()


Library Reference Home Page

The text in the 86Duino reference material is modified from Arduino Reference Material, licensed under a Creative Commons Attribution-Share Alike 3.0 License. The code examples in the reference material have been released into the public domain.