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

Add TXT datatype #14

Merged
merged 3 commits into from
Jul 2, 2024
Merged

Add TXT datatype #14

merged 3 commits into from
Jul 2, 2024

Conversation

alexrudd2
Copy link
Owner

@alexrudd2 alexrudd2 commented Jun 3, 2024

Add text (TXT) support.

This is tricky and different from the other datatypes because two 8-bit addresses are packed into a single 16-bit register. For some strange reason it's little-endian.

For example, consider the following state:

address register value
TXT1 436865 (LSB) A
TXT2 436865 (MSB) B
TXT3 436866 (LSB) C
TXT4 436866 (MSB) D

In memory, or using a "naive" Modbus client, this will appear as BADC.

To read TXT1, the whole 16-bit holding register [4]36865 must be read and the first 8 bits (MSB) discarded.
To read TXT2, the whole 16-bit holding register [4]36865 must be read and the last 8 bits (LSB) discarded.

To write TXT1:

  • First read TXT2 and save its 8 bit value
  • Then pack the 8 bits of TXT2 into the MSB of a 16-bit value, and the 8 bits of TXT1 into the LSB
  • Then write the combined 16 bits into holding register [4]36865

To write TXT2:

  • First read TXT1 and save its 8 bit value
  • Then pack the 8 bits of TXT2 into the MSB of a 16-bit value, and the 8 bits of TXT1 into the LSB
  • Then write the combined 16 bits into holding register [4]36865

@alexrudd2
Copy link
Owner Author

@cperry-adcTAG

@alexrudd2 alexrudd2 merged commit a70e300 into master Jul 2, 2024
37 checks passed
@alexrudd2 alexrudd2 deleted the txt branch July 2, 2024 15:22
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.

1 participant