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 missing lreal to util.py #487

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion snap7/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ def get_lreal(bytearray_: bytearray, byte_index: int) -> float:
return struct.unpack_from(">d", bytearray_, offset=byte_index)[0]


def set_lreal(bytearray_: bytearray, byte_index: int, lreal: float) -> bytearray:
def set_lreal(bytearray_: bytearray, byte_index: int, lreal) -> bytearray:
"""Set the long real

Notes:
Expand Down Expand Up @@ -1801,6 +1801,9 @@ def set_value(self, byte_index: Union[str, int], type_: str, value: Union[bool,
if type_ == 'REAL':
return set_real(bytearray_, byte_index, value)

if type_ == 'LREAL':
return set_lreal(bytearray_, byte_index, value)

if isinstance(value, int):
type_to_func = {
'DWORD': set_dword,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def test_set_byte(self):
row['testByte'] = 255
self.assertEqual(row['testByte'], 255)

def test_set_lreal(self):
test_array = bytearray(_bytearray)
row = util.DB_Row(test_array, test_spec, layout_offset=4)
row['testLreal'] = 123.123
self.assertEqual(row['testLreal'], 123.123)

def test_get_s5time(self):
"""
S5TIME extraction from bytearray
Expand Down
Loading