Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dword support for plc input and output #63

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pyLSV2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,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
Loading