Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 2 #194

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/ModbusMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -705,21 +728,15 @@ 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]);
}

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();
Expand Down
2 changes: 2 additions & 0 deletions src/ModbusMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class ModbusMaster
void idle(void (*)());
void preTransmission(void (*)());
void postTransmission(void (*)());
virtual void preTransmission();
virtual void postTransmission();

// Modbus exception codes
/**
Expand Down