Skip to content

Commit

Permalink
add first implementation for nativ addressing
Browse files Browse the repository at this point in the history
  • Loading branch information
drunsinn committed Apr 21, 2024
1 parent 9dafce0 commit 7a9fb1a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pyLSV2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,36 @@ def read_plc_memory(
)
return plc_values

def read_plc_address(self, value_address: str) -> Union[None, int, float, str]:
"""
read from plc memory using the nativ addressing scheme of the control
Requires access level ``PLCDEBUG`` to work.
:param value_address: address of the plc memory location in the format used by the nc like W1090, M0 or S20
:raises LSV2InputException: if unknowns memory type is requested or if the to many elements are requested
:raises LSV2DataException: if number of received values does not match the number of expected
"""
if result := re.fullmatch(r"(?P<type>[MBWDS])(?P<num>\d+)", value_address):
if result.group("type") == "M":
val_num = int(result.group("num"))
val_type = lc.MemoryType.MARKER
elif result.group("type") == "B":
val_num = int(result.group("num"))
val_type = lc.MemoryType.BYTE
elif result.group("type") == "W":
val_num = int(result.group("num")) / 2
val_type = lc.MemoryType.WORD
elif result.group("type") == "D":
val_num = int(result.group("num")) / 4
val_type = lc.MemoryType.DWORD
else: # "S"
val_num = int(result.group("num"))
val_type = lc.MemoryType.STRING
else:
return None
return self.read_plc_memory(int(val_num), val_type, 1)[0]

def set_keyboard_access(self, unlocked: bool) -> bool:
"""
Enable or disable the keyboard on the control.
Expand Down

0 comments on commit 7a9fb1a

Please sign in to comment.