gijzelaerr / python-snap7

A Python wrapper for the snap7 PLC communication library
http://python-snap7.readthedocs.org/
MIT License
643 stars 246 forks source link

Add support to read/write space-padded fixed-length strings #378

Closed vmsh0 closed 2 years ago

vmsh0 commented 2 years ago

Following the discussion in issue #375, I'm offering this PR with the modifications we are using internally to support the datatype.

A recap of what this is, adapted from the commit message:

These strings are not part of the official s7comm specification, but they are commonly found in real-world systems. They simply consist of a byte array that contains characters forming a string, padded on the right with spaces (ascii 32) when the string length is shorter than the array.

This commit adds support for reading and writing, as well as usage in tables (snap7.util.DB), and unit tests.

vmsh0 commented 2 years ago

I kept this separate from #377 in case you only want that fix (and not this feature), but if you wish I can both changes on your last master and offer a single pull request with both things.

vmsh0 commented 2 years ago

I have made the requested change as well as fixed the reported linting issues.