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 more getter methods for utils #357

Merged
merged 12 commits into from
May 25, 2022

Conversation

swamper123
Copy link
Contributor

fix shadow declarations like min and type
add S-1200 compatible getter functions
add missing, but not testable datatype getters

Tests will be added soon. This is a sneak-peak for now. Tested with a S1200 and supported datatypes.
Stuff, like LINT, can't be verified with a real device from me.

@swamper123 swamper123 changed the title fix get_string function add more getter methods for utils Mar 15, 2022
@swamper123 swamper123 marked this pull request as ready for review March 16, 2022 13:37
@@ -451,7 +451,7 @@ def set_string(bytearray_: bytearray, byte_index: int, value: str, max_size: int
bytearray_[byte_index + 2 + r] = ord(' ')


def get_string(bytearray_: bytearray, byte_index: int, max_size: int) -> str:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks backwards compatibility, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right with that.

Imo. max_size is irrelevant for this kind of function.
Both sizes are in the first to bytes of the bytearray.
Byte 0 is for the max. string length (that's why a string can only be 255 (ascii) chars long, x\FF).
Byte 1 is the amount of used chars in the string.

Byte 0: 0x07
Byte 1: 0x05
[H] [E] [L] [L] [O] [ ] ][ ]

So all informations have already to be in that bytestring and the max amount is 255 as default. Otherwise it wouldn't be s7comm conform.
If sb. wants to shorten the string, it should be done outside this function, since this function is only for transforming bytearrays (form an s7) to string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_size is important for set/write methods, where you also have to be aware of the max. length.

If you get an already read bytearray, the information is already in the bytearray.

fbeitler added 7 commits March 28, 2022 08:25
fix shadow declarations like min and type
add S-1200 compatible getter functions
add missing, but not testable datatype getters
fix pycodestyle
add getter tests
add some set methods
@swamper123 swamper123 marked this pull request as draft March 28, 2022 06:29
@swamper123 swamper123 marked this pull request as ready for review March 28, 2022 08:56
@gijzelaerr gijzelaerr merged commit 9171517 into gijzelaerr:master May 25, 2022
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

2 participants