Modbus86 Gateway

Modbus86 Gateway 能使 86Duino 模擬成 Modbus Gateway ,是轉發 Modbus Master 通訊資料的閘道器。

範例


使用 Modbus TCP 作為與 Modbus Master 通訊方式,並將其通訊資料轉發至 Modbus RTU 上的節點

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

ModbusMaster bus;
ModbusMasterNode node1;
ModbusMasterNode node2;

ModbusGateway gateway;

byte mac[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
IPAddress localIp(192,168,1,102);

void setup()
{
    Ethernet.begin(mac, localIp);
    Serial485.begin(115200);

    gateway.begin(MODBUS_TCP);

    bus.begin(MODBUS_RTU, Serial485);
    
    node1.attach(11, bus);
    node2.attach(12, bus);
    
    gateway.connect(node1);
    gateway.connect(node2);
	gateway.setTimeout(500);
}

void loop()
{
    gateway.poll();
}

函式庫參考主頁面

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.