You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Get/Set register callback function definition. Pointer to TRegister structure (see source for details) of the register and new value are passed as arguments.
Assign callback function on register modify event. Multiple sequental registers can be affected by specifing `numregs` parameter. Call in `onSetCoil(regId)` form to disconnect callback.
Assign callback function on register query event. Multiple sequental registers can be affected by specifing `numregs` parameter. Call in `onGet(regId)` form to disconnect callback.
78
+
79
+
### Macros
80
+
81
+
```c
82
+
#define COIL_VAL(v)
83
+
#define COIL_BOOL(v)
84
+
#define ISTS_VAL(v)
85
+
#define ISTS_BOOL(v)
86
+
```
87
+
88
+
### ModBus IP specific
89
+
90
+
```c
91
+
voidbegin();
92
+
voidtask();
93
+
```
94
+
95
+
### Callback example
96
+
97
+
```c
98
+
ModbusIP mb;
99
+
bool coil = false; // Define external variable to get/set value
100
+
uint16_tcbCoilSet(TRegister* reg, uint16_t val) { // 'reg' is pointer to reg to modify, 'val' is new register value
101
+
coil = COIL_BOOL(val);
102
+
return val; // Returns value to be saved to TRegister structure
@@ -5,153 +5,56 @@ used in industrial automation and can be used in other areas, such as home autom
5
5
6
6
The Modbus generally uses serial RS-232 or RS-485 as physical layer (then called Modbus Serial) and TCP/IP via Ethernet or WiFi (Modbus IP).
7
7
8
-
In the current version the library allows the ESP8266/ESP32 operate as a slave, supporting Modbus IP via wireless network. For more information about Modbus see:
8
+
In the current version the library allows the ESP8266/ESP32 operate async as a slave, supporting Modbus IP via wireless network. For more information about Modbus see:
<li>Reply exception messages for all supported functions</li>
19
-
<li>Modbus functions supported:</li>
20
-
<ul>
21
-
<li>0x01 - Read Coils</li>
22
-
<li>0x02 - Read Input Status (Read Discrete Inputs)</li>
23
-
<li>0x03 - Read Holding Registers</li>
24
-
<li>0x04 - Read Input Registers</li>
25
-
<li>0x05 - Write Single Coil</li>
26
-
<li>0x06 - Write Single Register</li>
27
-
<li>0x0F - Write Multiple Coils</li>
28
-
<li>0x10 - Write Multiple Registers</li>
29
-
</ul>
30
-
<li>Callbacks for</li>
31
-
<ul>
32
-
<li> - Incoming IP connection</li>
33
-
<li> - Read specific Register</li>
34
-
<li> - Write specific Register</li>
35
-
</ul>
36
-
</ul>
37
-
38
-
<b>Notes:</b>
16
+
* Supported platforms are
17
+
* ESP8266
18
+
* ESP32
19
+
* Operates as a slave
20
+
* Fully async operations. No loop locks.
21
+
* Supports Modbus IP (TCP)
22
+
* Reply exception messages for all supported functions
23
+
* Modbus functions supported:
24
+
* 0x01 - Read Coils
25
+
* 0x02 - Read Input Status (Read Discrete Inputs)
26
+
* 0x03 - Read Holding Registers
27
+
* 0x04 - Read Input Registers
28
+
* 0x05 - Write Single Coil
29
+
* 0x06 - Write Single Register
30
+
* 0x0F - Write Multiple Coils
31
+
* 0x10 - Write Multiple Registers
32
+
* Callbacks for
33
+
* Incoming IP connection
34
+
* Read specific Register
35
+
* Write specific Register
36
+
37
+
## Notes:
39
38
40
39
1. When using Modbus IP the transport protocol is TCP (port 502).
41
40
42
-
2. The offsets for registers are 0-based. So be careful when setting your supervisory system or your testing software. For example, in ScadaBR (http://www.scadabr.com.br)
43
-
offsets are 0-based, then, a register configured as 100 in the library is set to 100 in ScadaBR. On the other hand, in the CAS Modbus Scanner
44
-
(http://www.chipkin.com/products/software/modbus-software/cas-modbus-scanner/) offsets are 1-based, so a register configured as 100 in library should be 101 in this software.
45
-
46
-
3. Early in the library Modbus.h file there is an option to limit the operation
47
-
to the functions of Holding Registers, saving space in the program memory.
return COIL_VAL(coil); // Returns value to be returned to ModBus master as reply for current request
122
-
}
123
-
bool cbConn(IPAddress ip) {
124
-
Serial.println(ip);
125
-
return true; // Return 'true' to allow connection or 'false' to drop connection
126
-
}
127
-
ModbusIP mb; // ModbusIP object
128
-
void setup() {
129
-
...
130
-
mb.onConnect(cbConn); // Add callback on connection event
131
-
mb.begin();
132
-
mb.addCoil(COIL_NR); // Add Coil
133
-
mb.onSet(COIL(COIL_NR), cbCoilSet); // Add callback on Coil COIL_NR value set
134
-
mb.onGet(COIL(COIL_NR), cbCoilGet); // Add callback on Coil COIL_NR value get
135
-
...
136
-
}
137
-
void loop() {
138
-
...
139
-
mb.task();
140
-
...
141
-
}
142
-
```
41
+
2. The offsets for registers are 0-based. So be careful when setting your supervisory system or your testing software. For example, in [ScadaBR](http://www.scadabr.com.br)
42
+
offsets are 0-based, then, a register configured as 100 in the library is set to 100 in ScadaBR. On the other hand, in the [CAS Modbus Scanner](http://www.chipkin.com/products/software/modbus-software/cas-modbus-scanner/) offsets are 1-based, so a register configured as 100 in library should be 101 in this software.
143
43
44
+
For API specefication see [API.md](https://githab.com/emelianov/modbus-esp8266/API/md)
0 commit comments