begin()

描述

初始化 ModbusMaster 物件,並指定其為 Serial 類別或 IPAddress 類別。

語法


bus1.begin(mode, serial)
bus2.begin(mode, modbus_server_ip)

參數

bus1/bus2ModbusMaster 物件。

mode:指定 ModbusMaster 物件的通訊模式,其引數分別為 MODBUS_RTUMODBUS_ASCIIMODBUS_TCP

serial:指定 Serial 類別做為傳輸通道。

modbus_server_ip:指定 IPAddress 類別做為傳輸通道。

回傳

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

範例

#include <Ethernet.h>
#include <Modbus86.h>

ModbusMaster bus1;
ModbusMaster bus2;

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);    
}

void loop()
{
}

See Also

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


函式庫參考主頁面

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.