Skip to content

Problem with some setters #553

@core-engineering

Description

@core-engineering

Hi,

First, I would like to say that this python library is quite usefull to me ! Thanks a lot for the contributors and the maintainer. The original snap7 library is also awesome !

During one dev, I couldn't use the util.set_dint and the util.set_udint methods properly.

After code check, it appears that the return statement is missing in some util.set methods.

Original code :

def set_dint(bytearray_: bytearray, byte_index: int, dint: int) -> None:

    dint = int(dint)
    _bytes = struct.unpack("4B", struct.pack(">i", dint))
    for i, b in enumerate(_bytes):
        bytearray_[byte_index + i] = b

Working code :

def set_dint(bytearray_: bytearray, byte_index: int, dint: int) -> bytearray:

    dint = int(dint)
    _bytes = struct.unpack("4B", struct.pack(">i", dint))
    for i, b in enumerate(_bytes):
        bytearray_[byte_index + i] = b
    return bytearray_

If needed, I can propose a pull request !

Camille

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions