Skip to content

Commit 7fb4bcb

Browse files
authored
add missing lreal to util.py (gijzelaerr#487)
* add missing lreal to utile.py * fix mypy issue
1 parent 5f9de73 commit 7fb4bcb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

snap7/util.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ def get_lreal(bytearray_: bytearray, byte_index: int) -> float:
10431043
return struct.unpack_from(">d", bytearray_, offset=byte_index)[0]
10441044

10451045

1046-
def set_lreal(bytearray_: bytearray, byte_index: int, lreal: float) -> bytearray:
1046+
def set_lreal(bytearray_: bytearray, byte_index: int, lreal) -> bytearray:
10471047
"""Set the long real
10481048
10491049
Notes:
@@ -1801,6 +1801,9 @@ def set_value(self, byte_index: Union[str, int], type_: str, value: Union[bool,
18011801
if type_ == 'REAL':
18021802
return set_real(bytearray_, byte_index, value)
18031803

1804+
if type_ == 'LREAL':
1805+
return set_lreal(bytearray_, byte_index, value)
1806+
18041807
if isinstance(value, int):
18051808
type_to_func = {
18061809
'DWORD': set_dword,

tests/test_util.py

+6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ def test_set_byte(self):
143143
row['testByte'] = 255
144144
self.assertEqual(row['testByte'], 255)
145145

146+
def test_set_lreal(self):
147+
test_array = bytearray(_bytearray)
148+
row = util.DB_Row(test_array, test_spec, layout_offset=4)
149+
row['testLreal'] = 123.123
150+
self.assertEqual(row['testLreal'], 123.123)
151+
146152
def test_get_s5time(self):
147153
"""
148154
S5TIME extraction from bytearray

0 commit comments

Comments
 (0)