From c891b65ae6b14687a5c759182249135e6f3dc7f1 Mon Sep 17 00:00:00 2001 From: PeterTM Date: Thu, 9 Mar 2017 18:00:48 +0000 Subject: [PATCH 1/3] Added test to pull int from end of DB --- test/test_util.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test_util.py b/test/test_util.py index a4705992..46744fb6 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([ @@ -28,6 +29,7 @@ 8*1 + 4*1 + 2*1 + 1*1, # test bools 68, 78, 211, 51, # test real 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) From f3fd0d8359be05b31c8256e317e1b033e322e2b4 Mon Sep 17 00:00:00 2001 From: PeterTM Date: Thu, 9 Mar 2017 22:26:45 +0000 Subject: [PATCH 2/3] fixed get_int address bug attempting to read an int from anywhere but address zero of the bytearray would return struct.error: pack expected 2 items for packing (got 0) --- snap7/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From c4aa2961ae1ace62905adf190a2611271ad1f034 Mon Sep 17 00:00:00 2001 From: PeterTM Date: Thu, 9 Mar 2017 22:38:46 +0000 Subject: [PATCH 3/3] Fixed Typo --- test/test_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_util.py b/test/test_util.py index 46744fb6..4a04a93f 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -28,7 +28,7 @@ 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 ])