Skip to content

Commit

Permalink
add dword support for plc input and output (#63)
Browse files Browse the repository at this point in the history
* add dword for input and output memory

* add test and demo for input/output word and dword
  • Loading branch information
drunsinn authored Jun 20, 2024
1 parent 281edd0 commit 151346b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pyLSV2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,16 @@ def read_plc_memory(
max_elements = self._sys_par.number_of_output_words
mem_byte_count = 2
unpack_string = "<H"
elif mem_type is lc.MemoryType.OUTPUT_DWORD:
start_address = self._sys_par.output_words_start_address
max_elements = self._sys_par.number_of_output_words / 4
mem_byte_count = 4
unpack_string = "<l"
elif mem_type is lc.MemoryType.INPUT_DWORD:
start_address = self._sys_par.input_words_start_address
max_elements = self._sys_par.number_of_input_words / 4
mem_byte_count = 4
unpack_string = "<l"
else:
raise LSV2InputException("unknown address type")

Expand Down
2 changes: 2 additions & 0 deletions pyLSV2/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class MemoryType(IntEnum):
STRING = 9
INPUT_WORD = 10
OUTPUT_WORD = 11
OUTPUT_DWORD = 12
INPUT_DWORD = 13


class LSV2StatusCode(IntEnum):
Expand Down
6 changes: 5 additions & 1 deletion pyLSV2/scripts/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ def comprehensive_demo():
print("## double word: {}".format(con.read_plc_memory(0, MemoryType.DWORD, 5)))
print("## string: {}".format(con.read_plc_memory(0, MemoryType.STRING, 5)))
print("## input: {}".format(con.read_plc_memory(0, MemoryType.INPUT, 5)))
print("## output: {}".format(con.read_plc_memory(0, MemoryType.OUTPUT_WORD, 5)))
print("## output: {}".format(con.read_plc_memory(0, MemoryType.OUTPUT, 5)))
print("## input word: {}".format(con.read_plc_memory(0, MemoryType.INPUT_WORD, 5)))
print("## output word: {}".format(con.read_plc_memory(0, MemoryType.OUTPUT_WORD, 5)))
print("## input dword: {}".format(con.read_plc_memory(0, MemoryType.INPUT_DWORD, 5)))
print("## output dword: {}".format(con.read_plc_memory(0, MemoryType.OUTPUT_DWORD, 5)))

print("# data values via data path, only available on some iTNC530")
if con.versions.is_itnc():
Expand Down
5 changes: 4 additions & 1 deletion tests/test_plc_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ def test_plc_read(address: str, timeout: float):
assert lsv2.read_plc_memory(0, pyLSV2.MemoryType.WORD, 1) is not False
assert lsv2.read_plc_memory(0, pyLSV2.MemoryType.DWORD, 1) is not False
assert lsv2.read_plc_memory(0, pyLSV2.MemoryType.STRING, 1) is not False
assert lsv2.read_plc_memory(0, pyLSV2.MemoryType.INPUT, 1) is not False
assert lsv2.read_plc_memory(0, pyLSV2.MemoryType.OUTPUT_WORD, 1) is not False
assert lsv2.read_plc_memory(0, pyLSV2.MemoryType.OUTPUT_DWORD, 1) is not False
assert lsv2.read_plc_memory(0, pyLSV2.MemoryType.INPUT, 1) is not False
assert lsv2.read_plc_memory(0, pyLSV2.MemoryType.INPUT_WORD, 1) is not False
assert lsv2.read_plc_memory(0, pyLSV2.MemoryType.INPUT_DWORD, 1) is not False

lsv2.logout(pyLSV2.Login.PLCDEBUG)

Expand Down

0 comments on commit 151346b

Please sign in to comment.