Skip to content

Commit ac78bff

Browse files
committed
ModbusRTU Stability fixes
- Fixed early bus release if no transactional callback assigned for read/write Hreg/Coil - Fixed possible responce loss for ESP32 master
1 parent f3f0567 commit ac78bff

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ V1.02](http://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf)
6363
## Last Changes
6464

6565
```diff
66+
// 3.0.5
67+
+ ModbusRTU: Fix early bus release if no callback
68+
+ ModbusRTU ESP32: Fix potential responce loss
6669
// 3.0.4
6770
+ ModbusIP: Fixed missed server connection free in destructor
6871
+ Fixed addition of missing registers in .poll*() calls

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=modbus-esp8266
2-
version=3.0.4
2+
version=3.0.5
33
author=Andre Sarmento Barbosa, Alexander Emelianov
44
maintainer=Alexander Emelianov<[email protected]>
55
sentence=Modbus RTU and Modbus TCP Library for ESP8266/ESP32

src/ModbusRTU.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,12 @@ bool ModbusRTU::rawSend(uint8_t slaveId, uint8_t* frame, uint8_t len) {
111111
_port->write(frame, len); // Send PDU
112112
_port->write(newCrc >> 8); //Send CRC
113113
_port->write(newCrc & 0xFF);//Send CRC
114-
#ifdef ESP32
115-
portEXIT_CRITICAL(&mux);
116-
#endif
117114
_port->flush();
118115
if (_txPin >= 0)
119116
digitalWrite(_txPin, _direct?LOW:HIGH);
120-
//delay(_t);
117+
#ifdef ESP32
118+
portEXIT_CRITICAL(&mux);
119+
#endif
121120
return true;
122121
}
123122

@@ -264,12 +263,12 @@ bool ModbusRTU::cleanup() {
264263

265264
uint16_t ModbusRTU::writeHreg(uint8_t slaveId, uint16_t offset, uint16_t value, cbTransaction cb) {
266265
readSlave(offset, value, FC_WRITE_REG);
267-
return send(slaveId, HREG(offset), cb, nullptr, cb);
266+
return send(slaveId, HREG(offset), cb, nullptr);
268267
}
269268

270269
uint16_t ModbusRTU::writeCoil(uint8_t slaveId, uint16_t offset, bool value, cbTransaction cb) {
271270
readSlave(offset, COIL_VAL(value), FC_WRITE_COIL);
272-
return send(slaveId, COIL(offset), cb, nullptr, cb);
271+
return send(slaveId, COIL(offset), cb, nullptr);
273272
}
274273

275274
uint16_t ModbusRTU::readCoil(uint8_t slaveId, uint16_t offset, bool* value, uint16_t numregs, cbTransaction cb) {
@@ -282,14 +281,14 @@ uint16_t ModbusRTU::readCoil(uint8_t slaveId, uint16_t offset, bool* value, uint
282281
uint16_t ModbusRTU::writeCoil(uint8_t slaveId, uint16_t offset, bool* value, uint16_t numregs, cbTransaction cb) {
283282
if (numregs < 0x0001 || numregs > 0x07D0) return false;
284283
writeSlaveBits(COIL(offset), offset, numregs, FC_WRITE_COILS, value);
285-
return send(slaveId, COIL(offset), cb, nullptr, cb);
284+
return send(slaveId, COIL(offset), cb, nullptr);
286285
}
287286

288287

289288
uint16_t ModbusRTU::writeHreg(uint8_t slaveId, uint16_t offset, uint16_t* value, uint16_t numregs, cbTransaction cb) {
290289
if (numregs < 0x0001 || numregs > 0x007D) return false;
291290
writeSlaveWords(HREG(offset), offset, numregs, FC_WRITE_REGS, value);
292-
return send(slaveId, HREG(offset), cb, nullptr, cb);
291+
return send(slaveId, HREG(offset), cb, nullptr);
293292
}
294293

295294

0 commit comments

Comments
 (0)