pyLSV2 package content¶
pyLSV2 base¶
A pure Python3 implementation of the LSV2 protocol
This library is an attempt to implement the LSV2 communication protocol used by certain CNC controls. Please consider the dangers of using this library on a production machine! This library is by no means complete and could damage the control or cause injuries! Everything beyond simple file manipulation is blocked by a lockout parameter. Use at your own risk!
-
class
pyLSV2.
LSV2
(hostname, port=0, timeout=15.0, safe_mode=True)¶ Implementation of the LSV2 protocol used to communicate with certain CNC controls
-
change_directory
(remote_directory)¶ Change the current working directoyon the control
- Parameters
remote_directory (str) – path of directory on the control
- Returns
True if changing of directory succeeded
- Return type
bool
-
connect
()¶ connect to control
-
copy_local_file
(source_path, target_path)¶ Copy file on control from one place to another
- Parameters
source_path (str) – path of file on the control
target_path (str) – path of target location
- Returns
True if copying of file completed successfully
- Return type
bool
-
delete_empty_directory
(dir_path)¶ Delete empty directory on control
- Parameters
file_path (str) – path of directory on the control
- Returns
True if deleting of directory completed successfully
- Return type
bool
-
delete_file
(file_path)¶ Delete file on control
- Parameters
file_path (str) – path of file on the control
- Returns
True if deleting of file completed successfully
- Return type
bool
-
disconnect
()¶ logout of all open logins and close connection
-
get_directory_content
()¶ Query content of current working directory from the control. In some situations it is necessary to fist call get_directory_info() or else the attributes won’t be correct.
- Returns
list of dict with info about directory entries
- Return type
list
-
get_directory_info
(remote_directory=None)¶ Query information a the current working directory on the control
- Parameters
remote_directory (str) – optional. If set, working directory will be changed
- Returns
dictionary with info about the directory or False if an error occurred
- Return type
dict
-
get_drive_info
()¶ Query info all drives and partitions from the control
- Returns
list of dict with with info about drive entries
- Return type
list
-
get_error_messages
()¶ Get information about the first or next error displayed on the control
- Parameters
next_error (bool) – if True check if any further error messages are available
- Returns
error information or False if something went wrong
- Return type
dict
-
get_execution_status
()¶ Get status code of program state to text See https://github.com/drunsinn/pyLSV2/issues/1
- Returns
status code or False if something went wrong
- Return type
int
-
get_file_info
(remote_file_path)¶ Query information about a file
- Parameters
remote_file_path (str) – path of file on the control
- Returns
dictionary with info about file of False if remote path does not exist
- Return type
dict
-
get_file_list
(path=None, descend=True, pattern=None)¶ Get list of files in directory structure.
- Parameters
path (str) – path of the directory where files should be searched. if None than the current directory is used
descend (bool) – control if search should run recursiv
pattern (str) – regex string to filter the file names
- Returns
list of files found in directory
- Return type
list
-
get_machine_parameter
(name)¶ Read machine parameter from control. Requires access INSPECT level to work.
- Parameters
name (str) – name of the machine parameter. For iTNC the parameter number hase to be converted to string
- Returns
value of parameter or False if command not successful
- Return type
str or bool
-
get_override_info
()¶ Get information about the override info
- Returns
override information or False if something went wrong
- Return type
dict
-
get_program_stack
()¶ Get path of currently active nc program(s) and current line number See https://github.com/tfischer73/Eclipse-Plugin-Heidenhain/issues/1
- Returns
dictionary with line number, main program and current program or False if something went wrong
- Return type
dict
-
get_program_status
()¶ Get status code of currently active program See https://github.com/tfischer73/Eclipse-Plugin-Heidenhain/issues/1
- Returns
status code or False if something went wrong
- Return type
int
-
get_spindle_tool_status
()¶ Get information about the tool currently in the spindle
- Returns
tool information or False if something went wrong
- Return type
dict
-
get_system_parameter
(force=False)¶ Get all version information, result is bufferd since it is also used internally. With parameter force it is possible to manually re-read the information form the control
- Parameters
force (bool) – if True the information is read even if it is already buffered
- Returns
dictionary with system parameters like number of plc variables, supported lsv2 version etc.
- Return type
dict
-
get_versions
(force=False)¶ Get all version information, result is bufferd since it is also used internally. With parameter force it is possible to manually re-read the information form the control
- Parameters
force (bool) – if True the information is read even if it is already buffered
- Returns
dictionary with version text for control type, nc software, plc software, software options etc.
- Return type
dict
-
is_itnc
()¶ return true if control is of a iTNC
-
is_pilot
()¶ return true if control is of a CNCPILOT640
-
is_tnc
()¶ return true if control is of a TNC
-
login
(login, password=None)¶ Request additional access rights. To elevate this level a logon has to be performed. Some levels require a password.
- Parameters
login (str) – One of the known login strings
password (str) – optional. Password for login
- Returns
True if execution was successful
- Return type
bool
-
logout
(login=None)¶ Drop one or all access right. If no login is supplied all active access rights are dropped.
- Parameters
login (str) – optional. One of the known login strings
- Returns
True if execution was successful
- Return type
bool
-
make_directory
(dir_path)¶ Create a directory on control. If necessary also creates parent directories
- Parameters
dir_path (str) – path of directory on the control
- Returns
True if creating of directory completed successfully
- Return type
bool
-
move_local_file
(source_path, target_path)¶ Move file on control from one place to another
- Parameters
source_path (str) – path of file on the control
target_path (str) – path of target location
- Returns
True if moving of file completed successfully
- Return type
bool
-
read_plc_memory
(address, mem_type, count=1)¶ Read data from plc memory.
- Parameters
address – which memory location should be read, starts at 0 up to the max number for each type
mem_type – what datatype to read
count – how many elements should be read at a time, from 1 (default) up to 255 or max number
- Returns
a list with the data values
- Raises
Exception – raises an Exception
-
recive_file
(remote_path, local_path, override_file=False, binary_mode=False)¶ Download a file from control
- Parameters
remote_path (str) – path of file on the control
local_path (str) – local path of destination with or without file name
override_file (bool) – flag if file should be replaced if it already exists
binary_mode (bool) – flag if binary transfer mode should be used, if not set the file name is checked for known binary file type
- Returns
True if transfer completed successfully
- Return type
bool
-
send_file
(local_path, remote_path, override_file=False, binary_mode=False)¶ Upload a file to control
- Parameters
remote_path (str) – path of file on the control
local_path (str) – local path of destination with or without file name
override_file (bool) – flag if file should be replaced if it already exists
binary_mode (bool) – flag if binary transfer mode should be used, if not set the file name is checked for known binary file type
- Returns
True if transfer completed successfully
- Return type
bool
-
send_key_code
(key_code)¶ - Send key code to control. Behaves as if the associated key was pressed on the keyboard. Requires access MONITOR level to work.
To work correctly you first have to lock the keyboard and unlock it afterwards!:
set_keyboard_access(False) send_key_code(KEY_SPEC_CE) set_keyboard_access(True)
- Parameters
key_code (int) – code number of the keyboard key
- Returns
True or False if command was executed successfully
- Return type
bool
-
set_keyboard_access
(unlocked)¶ Enable or disable the keyboard on the control. Requires access level MONITOR to work.
- Parameters
unlocked (bool) – if True unlocks the keyboard. if false, input is set to locked
- Returns
True or False if command was executed successfully
- Return type
bool
-
set_machine_parameter
(name, value, safe_to_disk=False)¶ - Set machine parameter on control. Requires access PLCDEBUG level to work.
Writing a parameter takes some time, make sure to set timeout sufficiently high!
- Parameters
name (str) – name of the machine parameter. For iTNC the parameter number hase to be converted to string
value (str) – new value of the machine parameter. There is no type checking, if the value can not be converted by the control an error will be sent.
safe_to_disk (bool) – If True the new value will be written to the harddisk and stay permanent. If False (default) the value will only be available until the next reboot.
- Returns
True or False if command was executed successfully
- Return type
bool
-
set_system_command
(command, parameter=None)¶ Execute a system command on the control if command is one a known value. If safe mode is active, some of the commands are disabled. If necessary additinal parameters can be supplied.
- Parameters
command (int) – system command
parameter (str) – optional. parameter payload for system command
- Returns
True if execution was successful
- Return type
bool
-
Table reader¶
-
class
pyLSV2.
TableReader
¶ generic parser for table files commonly used by TNC, iTNC, CNCPILOT and MANUALplus controls
-
static
format_entry_bool
(str_value)¶ convert the string value of a table cell to boolean value
-
static
format_entry_float
(str_value)¶ convert the string value of a table cell to float value
-
static
format_entry_int
(str_value)¶ convert the string value of a table cell to int value
-
parse_table
(table_path)¶ Parse a file of one of the common table formats
- Parameters
or Path table_path (str) – Path to the table file
- Returns
list od dictionaries. key is the column name, value the content of the table cell
- Return type
list
-
static
Contants¶
Constant values used in LSV2
-
pyLSV2.const.
DRIVE_LOG
= 'LOG:'¶ drive name for partition LOG, contains log files. Not availible on all controls
-
pyLSV2.const.
DRIVE_PLC
= 'PLC:'¶ drive name for partition PLC, contains PLC program and configuration data
-
pyLSV2.const.
DRIVE_SYS
= 'SYS:'¶ drive name for partition SYS, ???
-
pyLSV2.const.
DRIVE_TNC
= 'TNC:'¶ drive name for partition TNC, contains NC programs and tables
-
pyLSV2.const.
EXEC_STATE_MANUAL
= 0¶ known execution states
-
pyLSV2.const.
FS_ENTRY_IS_HIDDEN
= 8¶ files system attributes
-
pyLSV2.const.
KEY_LOWER_A
= 97¶ key codes
-
pyLSV2.const.
LOGIN_INSPECT
= 'INSPECT'¶ const for login
-
pyLSV2.const.
LSV2_ERROR_T_ER_BAD_FORMAT
= 20¶ Error map
-
pyLSV2.const.
PGM_STATE_STARTED
= 0¶ known program states
-
pyLSV2.const.
PLC_MEM_TYPE_MARKER
= 1¶ Memory types for reading from PLC memory
-
pyLSV2.const.
REGEX_FILE_NAME_H
= '[\\$A-Za-z0-9_-]*\\.[hH]$'¶ Regex pattern for Klartext file names
-
pyLSV2.const.
REGEX_FILE_NAME_I
= '[\\$A-Za-z0-9_-]*\\.[iI]$'¶ Regex pattern for DIN/ISO file names
-
pyLSV2.const.
RUN_INFO_EXEC_STATE
= 23¶ const for relegram R_RI
-
pyLSV2.const.
TYPE_MILL_NEW_STYLE
= 1¶ Majour control types