-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathModbusT1SServer.ino
55 lines (42 loc) · 1.13 KB
/
ModbusT1SServer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Modbus T1S Server
This sketch demonstrates how to receive commands from a Modbus T1S Client connected
via T1S Single Pair Ethernet.
Circuit:
- T1S shield
- Uno WiFi R4
*/
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
RS485Class serial485(RS485_SERIAL, RS485_TX_PIN, RS485_DE_PIN, RS485_RE_PIN);
static uint8_t const T1S_PLCA_NODE_ID = 0;
static uint16_t const UDP_SERVER_PORT = 8889;
Arduino_10BASE_T1S_UDP udp_server;
void setup() {
Serial.begin(115200);
ModbusT1SServer.setT1SServer(udp_server);
ModbusT1SServer.setT1SPort(UDP_SERVER_PORT);
ModbusT1SServer.setCallback(OnPlcaStatus);
if (!ModbusT1SServer.begin(T1S_PLCA_NODE_ID, 9600, SERIAL_8N1, serial485)) {
Serial.println("Failed to start Modbus T1S Server!");
while (1);
}
ModbusT1SServer.disablePOE();
}
void loop() {
ModbusT1SServer.update();
}
static void OnPlcaStatus(bool success, bool plcaStatus)
{
if (!success)
{
Serial.println("PLCA status register read failed");
return;
}
if (plcaStatus) {
Serial.println("PLCA Mode active");
} else {
Serial.println("CSMA/CD fallback");
tc6_inst->enablePlca();
}
}