Skip to content

Commit

Permalink
Merge branch 'master' into nativ_plc_addressing
Browse files Browse the repository at this point in the history
  • Loading branch information
drunsinn committed Jun 22, 2024
2 parents 0f78d28 + de3647d commit a5dc285
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
- Md-aliy7
- npalmerDNX
- Andreas-strg
- oxbown

## Usage
See [lsv2_demo.py](https://github.com/drunsinn/pyLSV2/blob/master/pyLSV2/demos/lsv2_demo.py) for a demonstration of some of the functions.
Expand Down Expand Up @@ -215,7 +216,7 @@ These changes where made intentionally to make further development easier. See t
```
vermin --no-parse-comments .
```
The results indicate that pyLSV2 should work with python 3.5 and even with 3.4 if you install
The results indicate that pyLSV2 should work with python 3.6 and even with older versions if you install
the packported modules argparse, enum and typing. While argpares is only used in the demo script
the other two are necessary. Therefore it should be possible to use pyLSV2 with the current version
of [IronPython](https://ironpython.net/) if you install these two modules.
Expand Down
5 changes: 5 additions & 0 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ For iTNC 530:
- open the MOD dialog and enable the external access by toggling the soft key "External access"
- restart control

For iTNC 530 programming station:
- open the MOD dialog and enable the external access by toggling the soft key "External access"
- close and disable virtual keyboard (only one MONITOR connection can be active at a time)
- restart control

For TNC 320, 620, 640
- open the MOD dialog
- navigate to Machine settings/External access
Expand Down
13 changes: 12 additions & 1 deletion pyLSV2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def _send_recive(
self._logger.debug("unknown or unsupported system command %s", bytes_to_send)
return False

lsv_content = self._llcom.telegram(command, bytes_to_send)
wait_for_response = bool(expected_response is not lc.RSP.NONE)
lsv_content = self._llcom.telegram(command, bytes_to_send, wait_for_response)

if self._llcom.last_response is lc.RSP.UNKNOWN:
self._logger.error("unknown response received")
Expand Down Expand Up @@ -1279,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
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ log_cli = true
log_cli_level = "INFO"
log_format = "%(asctime)s %(levelname)s %(message)s"
log_date_format = "%Y-%m-%d %H:%M:%S"
addopts = "--address 192.168.56.101"
#addopts = "--address 192.168.56.102"
#addopts = "--address 192.168.56.103"
#addopts = "--address localhost"

[tool.codespell]
skip = "*.po,*.ts,./docs/_build,./docs/_static,./.git"
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
32 changes: 32 additions & 0 deletions tests/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,38 @@ def test_file_transfer_binary(address: str, timeout: float):
lsv2.disconnect()


def test_file_transfer_comp_mode(address: str, timeout: float):
"""test if transferring a file with active compatibility mode works. This is to test if transfer without
secure file transfer works as expected."""
lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=True, compatibility_mode=True)
lsv2.connect()

with tempfile.TemporaryDirectory(suffix=None, prefix="pyLSV2_") as tmp_dir_name:
local_send_path = Path("./data/testdata.bmp")
local_recive_path = Path(tmp_dir_name).joinpath("test.bmp")
remote_path = pyLSV2.DriveName.TNC + pyLSV2.PATH_SEP + local_send_path.name

assert lsv2.file_info(remote_path) is not True

assert lsv2.send_file(local_path=local_send_path, remote_path=remote_path, override_file=True, binary_mode=True) is True

assert lsv2.recive_file(local_path=str(local_recive_path), remote_path=remote_path, override_file=True, binary_mode=True) is True

assert lsv2.delete_file(remote_path) is True

digests = []
for filename in [local_send_path, local_recive_path]:
hasher = hashlib.md5()
with open(filename, "rb") as f_p:
buf = f_p.read()
hasher.update(buf)
h_d = hasher.hexdigest()
digests.append(h_d)
assert (digests[0] == digests[1]) is True

lsv2.disconnect()


def test_recive_with_path_formating(address: str, timeout: float):
"""test if reading of file information with / instead of \\ as path separator"""
lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=True)
Expand Down

0 comments on commit a5dc285

Please sign in to comment.