From 5eea418a0d679f1fbf23cb07ec615fec532d55a3 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 22 Jun 2024 16:06:17 +0200 Subject: [PATCH] add test for new memory access function --- tests/test_plc_read.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_plc_read.py b/tests/test_plc_read.py index 5eaa241..af48c90 100644 --- a/tests/test_plc_read.py +++ b/tests/test_plc_read.py @@ -134,3 +134,32 @@ def test_comapare_values(address: str, timeout: float): assert v1 == v2 lsv2.disconnect() + + +def test_plc_mem_access(address: str, timeout: float): + """test to see if reading via plc address and plc memory returns the same value""" + + lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=False) + lsv2.connect() + + for mem_address in [0, 1, 2, 4, 8, 12, 68, 69, 151, 300, 420]: + v1 = lsv2.read_plc_memory(mem_address, pyLSV2.MemoryType.DWORD, 1)[0] + v2 = lsv2.read_plc_address("D%d" % (mem_address * 4)) + assert v1 == v2 + + for mem_address in [0, 1, 2, 4, 8, 12, 68, 69, 151, 300, 420]: + v1 = lsv2.read_plc_memory(mem_address, pyLSV2.MemoryType.WORD, 1)[0] + v2 = lsv2.read_plc_address("W%d" % (mem_address * 2)) + assert v1 == v2 + + for mem_address in [0, 1, 2, 4, 8, 12, 68, 69, 151, 300, 420]: + v1 = lsv2.read_plc_memory(mem_address, pyLSV2.MemoryType.BYTE, 1)[0] + v2 = lsv2.read_plc_address("B%d" % (mem_address * 1)) + assert v1 == v2 + + for mem_address in [0, 1, 2, 4, 8, 12, 68, 69, 151, 300, 420]: + v1 = lsv2.read_plc_memory(mem_address, pyLSV2.MemoryType.MARKER, 1)[0] + v2 = lsv2.read_plc_address("M%d" % (mem_address * 1)) + assert v1 == v2 + + lsv2.disconnect()