begin()
描述
初始化 ModbusMaster
物件,並指定其為 Serial 類別或 IPAddress 類別。
語法
bus1.begin(mode, serial)
bus2.begin(mode, modbus_server_ip)
參數
bus1/bus2
: ModbusMaster
物件。
mode
:指定 ModbusMaster
物件的通訊模式,其引數分別為 MODBUS_RTU
、 MODBUS_ASCII
或 MODBUS_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.