Modify functionality of any single unit special case #98
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.
This is related to Issue #97 (which was also related to Issue #93)
This is the code that I implemented to solve the problem we had, which I described first in issue 93.
This allows special functionality when we have a single unit. It doesn't matter what the Unit Identifier of the unit is.
For TCP messages, the incoming Unit Identifier is ignored, and the spec recommends using the "insignificant" identifier, 0xFF. This means that there is a difference between the incoming Unit Identifier and the actual Unit Identifier of the defined single unit. For example, we might have defined Unit 1, but it must respond to an incoming message with Unit Identifier 1 or 0xFF. In addition, we might want to accept messages with Unit Identifier 0, which is used for broadcast. Also, we might want to accept messages from any Unit Identifier, since for TCP they can be ignored. In these cases, the incoming Unit Identifier can be several different values, but the internal unit we want to work with has an actual Unit Identifier of 1.
You will see code changes that keep track of the incoming and actual Unit Identifiers. In all cases, the Unit Identifier in the response is whatever the incoming Unit Identifier was in the request.
Miscellaneous Change: I needed to build this in a .net6 environment, so I added NET5_0_OR_GREATER to the conditional compilation lines in the ModbusTcpClient and ModbusUtils files.