Skip to content

Commit

Permalink
add compatibility mode to force certain parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
drunsinn committed Dec 13, 2023
1 parent d9572e5 commit 15ea673
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pyLSV2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(
port: int = 0,
timeout: float = 15.0,
safe_mode: bool = True,
compatibility_mode: bool = False
):
"""
Implementation of the LSV2 protocol used to communicate with certain CNC controls
Expand All @@ -55,6 +56,7 @@ def __init__(
:param port: port number to connect to
:param timeout: number of seconds waited for a response
:param safe_mode: switch to disable safety functions that might influence the control
:param compatibility_mode: switch to connect using the least amount of features, for example the buffer size
"""
self._logger = logging.getLogger("LSV2 Client")

Expand All @@ -68,6 +70,7 @@ def __init__(
self._sys_par = ld.SystemParameters()

self._secure_file_send = False
self._comp_mode = compatibility_mode

@property
def versions(self) -> ld.VersionInfo:
Expand Down Expand Up @@ -321,19 +324,26 @@ def _configure_connection(self):
if selected_command is None:
self._logger.debug("use smallest buffer size of 256")
self._llcom.buffer_size = selected_size
elif self._comp_mode:
self._logger.debug("compatibility mode active, use lowest buffer size of 256")
self._llcom.buffer_size = 256
else:
self._logger.debug("use buffer size of %d", selected_size)
if self._send_recive(lc.CMD.C_CC, struct.pack("!H", selected_command), lc.RSP.T_OK):
self._llcom.buffer_size = selected_size
else:
raise LSV2ProtocolException("error in communication while setting buffer size to %d" % selected_size)

if not self._send_recive(lc.CMD.C_CC, struct.pack("!H", lc.ParCCC.SECURE_FILE_SEND), lc.RSP.T_OK):
self._logger.debug("secure file transfer not supported? use fallback")
if self._comp_mode:
self._logger.debug("compatibility mode active, secure file send is ignored")
self._secure_file_send = False
else:
self._logger.debug("secure file send is enabled")
self._secure_file_send = True
if not self._send_recive(lc.CMD.C_CC, struct.pack("!H", lc.ParCCC.SECURE_FILE_SEND), lc.RSP.T_OK):
self._logger.debug("secure file transfer not supported? use fallback")
self._secure_file_send = False
else:
self._logger.debug("secure file send is enabled")
self._secure_file_send = True

self.login(login=lc.Login.FILETRANSFER)

Expand Down

0 comments on commit 15ea673

Please sign in to comment.