Skip to content

Commit

Permalink
add test for new memory access function
Browse files Browse the repository at this point in the history
  • Loading branch information
drunsinn committed Jun 22, 2024
1 parent 97b095a commit 5eea418
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_plc_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 5eea418

Please sign in to comment.