smarmengol / Modbus-Master-Slave-for-Arduino

Modbus Master-Slave library for Arduino
GNU Lesser General Public License v2.1
473 stars 328 forks source link

Conditional software serial #45

Closed alextingle closed 4 years ago

alextingle commented 5 years ago

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.)

alextingle commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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.)