diff --git a/snap7/util.py b/snap7/util.py index 88c2db5a..ac604593 100644 --- a/snap7/util.py +++ b/snap7/util.py @@ -144,7 +144,7 @@ def get_int(_bytearray, byte_index): int are represented in two bytes """ - data = _bytearray[byte_index:2] + data = _bytearray[byte_index:byte_index + 2] value = struct.unpack('>h', struct.pack('2B', *data))[0] return value diff --git a/test/test_util.py b/test/test_util.py index a4705992..4a04a93f 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -19,6 +19,7 @@ 12.7 testbool8 BOOL 13 testReal REAL 17 testDword DWORD +21 testint2 INT """ _bytearray = bytearray([ @@ -27,7 +28,8 @@ 128*0 + 64*0 + 32*0 + 16*0 + 8*1 + 4*1 + 2*1 + 1*1, # test bools 68, 78, 211, 51, # test real - 255, 255, 255, 255 # test dword + 255, 255, 255, 255, # test dword + 0, 0, # test int 2 ]) @@ -60,8 +62,10 @@ def test_get_int(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) x = row['ID'] + y = row['testint2'] self.assertEqual(x, 0) - + self.assertEqual(y, 0) + def test_set_int(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4)