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

Conditional software serial #45

Merged
merged 8 commits into from Jan 17, 2020

Conversation

alextingle
Copy link

Addresses Issue #10.

Avoids pulling in SoftwareSerial dependencies unless they are needed. Saves program memory and working memory.

(I've removed a large commented-out function which makes this diff look more complicated than it really is.)

Alex Tingle added 7 commits June 3, 2019 21:12
New macro USE_SOFTWARE_SERIAL may be set to 0 (default, hardware)
or 1 (software) to select software/hardware serial implementation
at compile time.
Replace overloaded methods with default parameter values.
Eliminate duplicate code by having initialisation methods
call each other, rather than replicate code.

Preserves all possible ways that users might be contructing a
working ModbusRtu object.
Eliminate any dependence upon SoftwareSerial class.
ModbusRtu now just refers to the base class Stream, which
is the parent of both HardwareSerial and SoftwareSerial.

The only function that is not in the base class is begin().
Ideally, users will call this function on their port object
directly, and then call the new ModbusRtu::start() function.

I've added in a couple of template begin() methods that
enable existing code to work without modification. These should
be deprecated, to encourage users to begin() their port objects
directly.

This approach also fixes Issue smarmengol#44 - "how to setup Serial
settings: parity, stop bits".
This will create a warning in users' build output, which
will encourage them to switch to the new, simpler constructor.

Changed the documentation to describe how to upgrade.
@alextingle
Copy link
Author

I've updated this solution, and I'm now a lot happier with it:

Eliminate any dependence upon SoftwareSerial class. ModbusRtu now just refers to the base class Stream, which is the parent of both HardwareSerial and SoftwareSerial. This means either hardware or software serial can be used interchangeably, without up needing any dependency upon either of them.

The only function that is not in the Serial base class is begin(). Ideally, users will call this function on their port object directly, and then call the new ModbusRtu::start() function.

I've added in a couple of template begin() methods that enable existing code to work without modification. I've marked them deprecated, to encourage users to begin() their port objects directly.

This approach also fixes Issue #44 - "how to setup Serial settings: parity, stop bits".

@ysmilda
Copy link

ysmilda commented Aug 1, 2019

This would also make it possible to use this library on boards that don't have support for the SoftwareSerial library like the SAMD based Arduino Zero board.

@alextingle
Copy link
Author

You can just use my branch directly:

https://github.com/alextingle/Modbus-Master-Slave-for-Arduino

(I'm thinking of separating it out as a new top-level, because it's now profoundly changed from this version. Smarmengol did say he might add me as a contributor to this project, but he hasn't done so yet - fair enough since my changes are so wide ranging.)

@smarmengol smarmengol merged commit df2fc9b into smarmengol:master Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants