attach()

Description

Initialize the ModbusMasterNode object and specify the mounting channel and the corresponding node number.

Syntax

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

Parameters

node1/node2: ModbusMasterNode object.

slave_id: Specifies the corresponding 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 ModbusMaster 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

27

28

#include <Ethernet.h>

#include <Modbus86.h>

 

ModbusMaster bus1;

ModbusMaster bus2;

 

ModbusMasterNode node1;

ModbusMasterNode node2;

 

IPAddress SlaveIP(192,168,3,59);

 

void setup()

{

    Serial1.begin(115200);

    bus1.begin(MODBUS_RTU, Serial1);

    // bus1.begin(MODBUS_ASCII, Serial1);

     

    Ethernet.begin();

    bus2.begin(MODBUS_TCP, SlaveIP);

         

    node1.attach(16, bus1);

    node2.attach(bus2);

    // node2.attach(MODBUS_TCP_SLAVE, bus2);

}

 

void loop()

{

}

See Also

ModbusMaster::begin()
ModbusSlaveNode::attach()


Library Reference

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