Skip to content

add more getter methods for utils#357

Merged
gijzelaerr merged 12 commits into
gijzelaerr:masterfrom
swamper123:add_getter_utils
May 25, 2022
Merged

add more getter methods for utils#357
gijzelaerr merged 12 commits into
gijzelaerr:masterfrom
swamper123:add_getter_utils

Conversation

@swamper123

Copy link
Copy Markdown
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
Comment thread snap7/util.py
bytearray_[byte_index + 2 + r] = ord(' ')


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

Copy link
Copy Markdown
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
Copy Markdown
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.

@swamper123 swamper123 Mar 28, 2022

Copy link
Copy Markdown
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
@swamper123 swamper123 requested a review from gijzelaerr March 28, 2022 09:00
@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.

2 participants