attach()

描述

初始化 ModbusSlaveNode 物件,並指定掛載通道與節點編號。

語法


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

參數

node1/node2ModbusSlaveNode 物件。

slave_id:指定 Slave 節點編號,於 TCP 模式下不指定編號將會使編號預設為 MODBUS_TCP_SLAVE (0xFF) 。

bus1/bus2:指定欲掛載之 ModbusSlave 物件。

回傳

bool:如果成功回傳 true,反之回傳 false

範例

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


函式庫參考主頁面

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.