ModbusSlaveNode.attach()

[Modbus]

Description

Initialize the ModbusSlaveNode object and specify the mount channel and node number.

Syntax

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

Parameters

  • node1/node2: ModbusSlaveNode Object.
  • slave_id: Specify the Slave node number, not specifying the number in TCP mode will cause the number to default to MODBUS_TCP_SLAVE (0xFF).
  • bus1/bus2: Specify the ModbusSlave object to be mounted.

Returns

bool: return true if successful, return false if not.

Example

#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


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