Open
Conversation
added 10 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.
Uses a loopback stream to set up communication between a master and slave on the same machine. Exercises various MODBUS functions, and tests that the results are correct. Test failures are reported to Serial, labelled "FAIL".
Modbus::get_FC1() - the code used to preserve old data in the high byte of au16regs words. So, if a single coil is returned from the slave, au16regs[0]'s high byte was left with junk in it. Modbus::process_FC1() - make sure that the data returned to the master is clean. Unused bits should be zeroed, according to the spec.
Author
|
(Includes, and depends upon the Serial changes I already put in the other pull request.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uses a loopback stream to set up communication between a master and slave on the same machine. Exercises various MODBUS functions, and tests that the results are correct. Test failures are reported to Serial, labelled "FAIL".
Also contains a couple of bug-fixes, which ensure that junk is not included in the MODBUS messages. (Found by the test harness.)
The motivation is to prepare for future code changes. Having a working test harness will help to ensure that changes have not broken anything.