diff --git a/src/ModbusMaster.cpp b/src/ModbusMaster.cpp index 4169e58..0558353 100644 --- a/src/ModbusMaster.cpp +++ b/src/ModbusMaster.cpp @@ -216,6 +216,29 @@ void ModbusMaster::postTransmission(void (*postTransmission)()) _postTransmission = postTransmission; } +/** +Function extends the preTransmission functionality, and we can now +inherit the class and override this method. + +@see ModbusMaster::ModbusMasterTransaction() +@see ModbusMaster::preTransmission() +*/ +void ModbusMaster::preTransmission() { + if (_preTransmission) + _preTransmission(); +} + +/** +Function extends the postTransmission functionality, and we can now +inherit the class and override this method. + +@see ModbusMaster::ModbusMasterTransaction() +@see ModbusMaster::postTransmission() +*/ +void ModbusMaster::postTransmission() { + if (_postTransmission) + _postTransmission(); +} /** Retrieve data from response buffer. @@ -705,10 +728,7 @@ uint8_t ModbusMaster::ModbusMasterTransaction(uint8_t u8MBFunction) while (_serial->read() != -1); // transmit request - if (_preTransmission) - { - _preTransmission(); - } + preTransmission(); for (i = 0; i < u8ModbusADUSize; i++) { _serial->write(u8ModbusADU[i]); @@ -716,10 +736,7 @@ uint8_t ModbusMaster::ModbusMasterTransaction(uint8_t u8MBFunction) u8ModbusADUSize = 0; _serial->flush(); // flush transmit buffer - if (_postTransmission) - { - _postTransmission(); - } + postTransmission(); // loop until we run out of time or bytes, or an error occurs u32StartTime = millis(); diff --git a/src/ModbusMaster.h b/src/ModbusMaster.h index 8c433e6..0d50e4a 100644 --- a/src/ModbusMaster.h +++ b/src/ModbusMaster.h @@ -75,6 +75,8 @@ class ModbusMaster void idle(void (*)()); void preTransmission(void (*)()); void postTransmission(void (*)()); + virtual void preTransmission(); + virtual void postTransmission(); // Modbus exception codes /**