Repository: drunsinn/pyLSV2 (language: python)

Issue:
Machine PLC Restart on running LSV2_demo.py
I was trying out the LSV2_demo script and below is my output, i have got T_ER from the PLC and also the PLC had issues (restart), any idea on how to connect with the iTNC530 machine to gets the progam_status execution_status and spindle speed and spindle feed data


```
Connecting to "IP of the machine"
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_WRONG_PARA
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_WRONG_PARA
Connected to "iTNC530" with NC Software "*****"
Running LSV2 Version 1 with Flags 255
Drive Info: [(removed for security reason)]
Current Folder TNC:/ Free Space: 2085650432 Attrib: ['*', '*', '*', '*']
PLC Marker: [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
PLC Word: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
PLC Double Word: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
PLC String: [' ']
PLC Input: [False, True, False, True, True]
PLC Word Output: [0, 0, 0, 0, 0]
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\PLC\memory\D\7928". This does not work for all control types
PLC Double Word 7928: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\PLC\memory\K\1". This does not work for all control types
PLC Constant 1: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\PLC\memory\M\211". This does not work for all control types
PLC Marker 211: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\PLC\memory\B\7192". This does not work for all control types
PLC Byte 7192: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\PLC\memory\W\10908". This does not work for all control types
PLC Word 10908: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\PLC\memory\I\11". This does not work for all control types
PLC Input 11: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\PLC\memory\S\30". This does not work for all control types
PLC String 30: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\TABLE\TOOL\T\1\DOC". This does not work for all control types
DOC column of tool 1: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\TABLE\TOOL\T\1\L". This does not work for all control types
L column of tool 1: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\TABLE\TOOL\T\1\R". This does not work for all control types
R column of tool 1: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\TABLE\TOOL\T\1\PLC". This does not work for all control types
PLC column of tool 1: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\TABLE\TOOL\T\1\TMAT". This does not work for all control types
TMAT column of tool 1: None
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_NOT_FOUND
WARNING:root:an error occurred while querying data path "\TABLE\TOOL\T\1\LAST_USE". This does not work for all control types
LAST_USE column of tool 1: None
Current Language: 0
Current Program Stack: {'Line': 0, 'Main_PGM': 'TNC:/*****', 'Current_PGM': ''}
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_WRONG_PARA
WARNING:root:an error occurred while querying current tool information. This does not work for all control types
Direct reading to current tool not supported for this control type. using backup strategy
Traceback (most recent call last):
  File "lsv2_demo.py", line 104, in <module>
    con.recive_file(local_path=str(local_recive_path),
  File "/pyLSV2-master/pyLSV2/client.py", line 846, in recive_file
    response, content = self._llcom.telegram(CMD.R_FL, payload, buffer_size=self._buffer_size)
  File "/pyLSV2-master/pyLSV2/low_level_com.py", line 118, in telegram
    response_length = struct.unpack('!L', response[0:4])[
struct.error: unpack requires a buffer of 4 bytes
```



Discussion / hints:
Hello @SabarinathRajendran 
getting some errors is normal, this happens when the control dosen't support a certain command. I tried to make pyLSV2 be as forgiving as possible when it comes to these kind of problems. In your case it seems the control dosen't support reading PLC values.

If you could run the lsv2_demo script with logging level DEBUG it would also I can tell you exactly what didn't work.
There are differences in the available functions between iTNC530 and TNC640 and also between the software versions.

The only serious problem I see is the exception at the end. It happens at a place where it tries to read some parameter from the data received from the control. At this point it always assumed to be at least 4 bytes but from the message it seems to be less than that.
There is currently no debug message that would tell us what really gets received. Could you please add a line like
`print(response)`
just before the line where it gives the exception and post the output?
@drunsinn thank you for the speedy response, will attach the debugging log once I run it again. It's seems to be an issues with set_sys_command function with this particular control, thank you for the speedy reply and I would also like to make a pull request where the warning can be made Bold 😅😅, those should be highlighted, thank you for the kind reply ,will keep you updated with the status and solutions.
Pull requests are always welcome!
We are running a few iTNC 530 machines with 340422-08 on them. Using the demo script:
https://github.com/drunsinn/pyLSV2/blob/c85d1dc64ce7c5f7e2941d0f558a22a6c702798f/scripts/lsv2_demo.py

The control terminates the EXT process when trying to access the tool file. Seems like error above. Below is the output with logging.basicConfig(level=logging.DEBUG)

I added 
con.login(login=pyLSV2.Login.PLCDEBUG, password="807667")
after the block of read_plc_memory requests after line 36 to /lsv2_demo.py. The password is no big secret to the world.

Thought the output could be useful for the above problem; we also have a  iTNC 530 machines with 340422-13 we could test against.

Connecting to 192.168.1.32
DEBUG:root:Socket successfully created, host 192.168.1.32 was resolved to IP 192.168.1.32
INFO:root:safe mode is off, login and system commands are not restricted. Use with caution!
DEBUG:root:Connected to host 192.168.1.32 at port 19000
DEBUG:root:telegram to transmit: command CMD.A_LG payload length 8 bytes data: bytearray(b'\x00\x00\x00\x08A_LGINSPECT\x00')
INFO:root:login executed successfully for login Login.INSPECT
DEBUG:root:telegram to transmit: command CMD.R_VR payload length 1 bytes data: bytearray(b'\x00\x00\x00\x01R_VR\x01')
DEBUG:root:command CMD.R_VR executed successfully, received S_VR with 8 bytes payload
DEBUG:root:telegram to transmit: command CMD.R_VR payload length 1 bytes data: bytearray(b'\x00\x00\x00\x01R_VR\x02')
DEBUG:root:command CMD.R_VR executed successfully, received S_VR with 10 bytes payload
DEBUG:root:telegram to transmit: command CMD.R_VR payload length 1 bytes data: bytearray(b'\x00\x00\x00\x01R_VR\x03')
DEBUG:root:command CMD.R_VR executed successfully, received S_VR with 11 bytes payload
DEBUG:root:telegram to transmit: command CMD.R_VR payload length 1 bytes data: bytearray(b'\x00\x00\x00\x01R_VR\x04')
DEBUG:root:command CMD.R_VR executed successfully, received S_VR with 18 bytes payload
DEBUG:root:telegram to transmit: command CMD.R_VR payload length 1 bytes data: bytearray(b'\x00\x00\x00\x01R_VR\x05')
DEBUG:root:command CMD.R_VR executed successfully, received S_VR with 24 bytes payload
DEBUG:root:telegram to transmit: command CMD.R_VR payload length 1 bytes data: bytearray(b'\x00\x00\x00\x01R_VR\x06')
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: wrong parameter
DEBUG:root:telegram to transmit: command CMD.R_VR payload length 1 bytes data: bytearray(b'\x00\x00\x00\x01R_VR\x07')
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: wrong parameter
DEBUG:root:got version info: {'Control': 'iTNC530', 'NC_Version': '340422 08', 'PLC_Version': 'GR34CB.00G', 'Options': '%0000111100000011', 'ID': '000.160.205.001.009.057', 'SPLC_Version': 'not supported'}
DEBUG:root:telegram to transmit: command CMD.R_PR payload length 0 bytes data: bytearray(b'\x00\x00\x00\x00R_PR')
DEBUG:root:command CMD.R_PR executed successfully, received S_PR with 124 bytes payload
DEBUG:root:got system parameters: {'Marker_Start': 12064, 'Markers': 10000, 'Input_Start': 22064, 'Inputs': 1000, 'Output_Start': 23064, 'Outputs': 1000, 'Counter_Start': 24064, 'Counters': 144, 'Timer_Start': 24208, 'Timers': 1000, 'Word_Start': 64, 'Words': 10000, 'String_Start': 25208, 'Strings': 16, 'String_Length': 128, 'Input_Word_Start': 10064, 'Input Words': 1000, 'Output_Word_Start': 11064, 'Output_Words': 1000, 'LSV2_Version': 1, 'LSV2_Version_Flags': 255, 'Max_Block_Length': 4096, 'HDH_Bin_Version': 0, 'HDH_Bin_Revision': 0, 'ISO_Bin_Version': 0, 'ISO_Bin_Revision': 0, 'HardwareVersion': 0, 'LSV2_Version_Flags_Ex': 53, 'Max_Trace_Line': 0, 'Scope_Channels': 0, 'PW_Encryption_Key': 0}
INFO:root:setting connection settings for iTNC530 and block length 4096
DEBUG:root:use buffer size of 4096
DEBUG:root:telegram to transmit: command CMD.C_CC payload length 2 bytes data: bytearray(b'\x00\x00\x00\x02C_CC\x00\x07')
DEBUG:root:telegram to transmit: command CMD.C_CC payload length 2 bytes data: bytearray(b'\x00\x00\x00\x02C_CC\x00\x13')
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: wrong parameter
DEBUG:root:unknown or unsupported system command
WARNING:root:secure file transfer not supported? use fallback
DEBUG:root:telegram to transmit: command CMD.A_LG payload length 5 bytes data: bytearray(b'\x00\x00\x00\x05A_LGFILE\x00')
INFO:root:login executed successfully for login Login.FILETRANSFER
INFO:root:successfully configured connection parameters and basic logins. selected buffer size is 4096, use secure file send: False
DEBUG:root:version info already in memory, return previous values
Connected to "iTNC530" with NC Software "340422 08"
DEBUG:root:version info already in memory, return previous values
Running LSV2 Version 1 with Flags 255
DEBUG:root:telegram to transmit: command CMD.R_DI payload length 0 bytes data: bytearray(b'\x00\x00\x00\x00R_DI')
DEBUG:root:command CMD.R_DI executed successfully, received S_DI with 170 bytes payload
DEBUG:root:successfully received directory information {'Free Size': 3590074368, 'Dir_Attributs': ['E', 'M', 'S', 'P', 'IN', 'DRV', 'DIR', 'H'], 'Attributes': (1, 131, 1, 39, 1, 16, 64, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 'Path': 'TNC:/'}
Current Folder TNC:/ Free Space: 3590074368 Attrib: ['E', 'M', 'S', 'P', 'IN', 'DRV', 'DIR', 'H']

DEBUG:root:telegram to transmit: command CMD.A_LG payload length 9 bytes data: bytearray(b'\x00\x00\x00\tA_LGPLCDEBUG\x00')
INFO:root:login executed successfully for login Login.PLCDEBUG
DEBUG:root:telegram to transmit: command CMD.R_MB payload length 5 bytes data: bytearray(b'\x00\x00\x00\x05R_MB\x00\x00/ \x0f')
DEBUG:root:command CMD.R_MB executed successfully, received S_MB with 15 bytes payload
DEBUG:root:read 15 value(s) from address 0
PLC Marker: [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
DEBUG:root:login already active
DEBUG:root:telegram to transmit: command CMD.R_MB payload length 5 bytes data: bytearray(b'\x00\x00\x00\x05R_MB\x00\x00\x00F\x14')
DEBUG:root:command CMD.R_MB executed successfully, received S_MB with 20 bytes payload
DEBUG:root:read 10 value(s) from address 6
PLC Word: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
DEBUG:root:login already active
DEBUG:root:telegram to transmit: command CMD.R_MB payload length 5 bytes data: bytearray(b'\x00\x00\x00\x05R_MB\x00\x00\x00@(')
DEBUG:root:command CMD.R_MB executed successfully, received S_MB with 40 bytes payload
DEBUG:root:read 10 value(s) from address 0
PLC Double Word: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
DEBUG:root:login already active
DEBUG:root:telegram to transmit: command CMD.R_MB payload length 5 bytes data: bytearray(b'\x00\x00\x00\x05R_MB\x00\x00b\xfa\x80')
DEBUG:root:command CMD.R_MB executed successfully, received S_MB with 128 bytes payload
DEBUG:root:read string 130
DEBUG:root:telegram to transmit: command CMD.R_MB payload length 5 bytes data: bytearray(b'\x00\x00\x00\x05R_MB\x00\x00cz\x80')
DEBUG:root:command CMD.R_MB executed successfully, received S_MB with 128 bytes payload
DEBUG:root:read string 258
PLC String: [' 0    1   46    4    2    0      [%]\x00 2    0      [%]\x00    2    0      [%]\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00  ', '0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00  ']
DEBUG:root:login already active
DEBUG:root:telegram to transmit: command CMD.R_MB payload length 5 bytes data: bytearray(b'\x00\x00\x00\x05R_MB\x00\x00V0\x05')
DEBUG:root:command CMD.R_MB executed successfully, received S_MB with 5 bytes payload
DEBUG:root:read 5 value(s) from address 0
PLC Input: [True, False, True, True, True]
DEBUG:root:login already active
DEBUG:root:telegram to transmit: command CMD.R_MB payload length 5 bytes data: bytearray(b'\x00\x00\x00\x05R_MB\x00\x00\x00J\n')
DEBUG:root:command CMD.R_MB executed successfully, received S_MB with 10 bytes payload
DEBUG:root:read 5 value(s) from address 10
PLC Word Output: [0, 0, 0, 0, 0]
DEBUG:root:login already active
DEBUG:root:telegram to transmit: command CMD.A_LG payload length 4 bytes data: bytearray(b'\x00\x00\x00\x04A_LGDNC\x00')
INFO:root:login executed successfully for login Login.DNC
DEBUG:root:telegram to transmit: command CMD.R_RI payload length 2 bytes data: bytearray(b'\x00\x00\x00\x02R_RI\x00\x18')
DEBUG:root:command CMD.R_RI executed successfully, received S_RI with 30 bytes payload
DEBUG:root:successfully read active program stack and line number: {'Line': 0, 'Main_PGM': 'TNC:/Unison/620181-1-3.h', 'Current_PGM': ''}
Current Program Stack: {'Line': 0, 'Main_PGM': 'TNC:/Unison/620181-1-3.h', 'Current_PGM': ''}
DEBUG:root:login already active
DEBUG:root:telegram to transmit: command CMD.R_RI payload length 2 bytes data: bytearray(b'\x00\x00\x00\x02R_RI\x00\x1a')
DEBUG:root:command CMD.R_RI executed successfully, received S_RI with 2 bytes payload
DEBUG:root:successfully read state of active program: No Program running
Current Program Status: 7
DEBUG:root:login already active
DEBUG:root:telegram to transmit: command CMD.R_RI payload length 2 bytes data: bytearray(b'\x00\x00\x00\x02R_RI\x00\x17')
DEBUG:root:command CMD.R_RI executed successfully, received S_RI with 2 bytes payload
DEBUG:root:read execution state 4 : Automatic execution
Current Execution Status: 4
DEBUG:root:login already active
DEBUG:root:telegram to transmit: command CMD.R_RI payload length 2 bytes data: bytearray(b'\x00\x00\x00\x02R_RI\x003')
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: wrong parameter
WARNING:root:an error occurred while querying current tool information. This does not work for all control types
Direct reading to current tool not supported for this control type. using backup strategy
Getting tool with itnc method
DEBUG:root:telegram to transmit: command CMD.R_FI payload length 16 bytes data: bytearray(b'\x00\x00\x00\x10R_FITNC:/TOOL_P.TCH\x00')
DEBUG:root:command CMD.R_FI executed successfully, received S_FI with 31 bytes payload
DEBUG:root:successfully received file information {'Size': 1624, 'Timestamp': datetime.datetime(2022, 6, 3, 15, 29, 28), 'Attributes': 0, 'is_file': True, 'is_directory': False, 'is_write_protected': False, 'Name': 'TNC:/TOOL_P.TCH'}
DEBUG:root:loading file from TNC:/TOOL_P.TCH to /tmp/pyLSV2_fw5rltm6/tool_p.tch
DEBUG:root:telegram to transmit: command CMD.R_FL payload length 16 bytes data: bytearray(b'\x00\x00\x00\x10R_FLTNC:/TOOL_P.TCH\x00')
Traceback (most recent call last):
  File "./demo-1.py", line 106, in <module>
    con.recive_file(local_path=str(local_recive_path), remote_path=pocket_table_path, binary_mode=transfer_binary)
  File "/odoo/.local/lib/python3.6/site-packages/pyLSV2/client.py", line 963, in recive_file
    CMD.R_FL, payload, buffer_size=self._buffer_size
  File "/odoo/.local/lib/python3.6/site-packages/pyLSV2/low_level_com.py", line 132, in telegram
    response_length = struct.unpack("!L", response[0:4])[
struct.error: unpack requires a buffer of 4 bytes




Hello @manusolve,

yeah, the standard key numbers is quite an open secret if you can use any search engine :-)
I still decided to not include it in the code since I don't want to risk someone to ruin their machine by for example deleting files on the PLC partition. That is also the reason i added the safe_mode parameter.

Your problem is definitely the same bug as reported by @SabarinathRajendran.

I wasn't able to make any progress since i could not reproduce the same problem with the machines and programming stations I have access to.

A simple thing to try would be to force using binary mode for the file transfer. To do this change the block starting at line 153 in `lsv2_demo.py` from 
```
        elif con.is_itnc():
            pocket_table_path = "TNC:/TOOL_P.TCH"
            transfer_binary = False
            spindel_lable = "0"
```
to
```
        elif con.is_itnc():
            pocket_table_path = "TNC:/TOOL_P.TCH"
            transfer_binary = True
            spindel_lable = "0"
```
Sometimes the ASCII mode behaves a bit strange......

If this doesn't help you will have to do a bit more changes. To debug this further it would be great if you could modify the code in `low_level_com.py` so it prints exactly what the response looks like. To get more info what happens you will have to replace the block of code starting at line 131. Currently it should look something like this:
```
        if response is not None:
            response_length = struct.unpack("!L", response[0:4])[
                0
            ]  # read 4 bytes for response length
            response_command = response[4:8].decode(
                "utf-8", "ignore"
            )  # read 4 bytes for response type
        else:
            response_length = 0
            response_command = None
```

I would like you to change this block to this:

```
        if response is not None:
            logging.debug("received block of data with length %d and content %s" % (len(response), response))
            if len(response) >= 8:
                response_length = struct.unpack("!L", response[0:4])[
                    0
                ]  # read 4 bytes for response length
                response_command = response[4:8].decode(
                    "utf-8", "ignore"
                )  # read 4 bytes for response type
            else:
                # response is less than 8 bytes long which is not enough space for package length and response message!
                raise Exception()
        else:
            response_length = 0
            response_command = None
```
With this change all the received data is printed 1:1 as a debug message when you run the demo script again.
For our application we just need the current program name and the machine run state; this works. However thought the debug information would be of use. 

I'm running the master branch as of yesterday; (I skipped the binary/ascii mod you proposed); adjusted the low_level_com file as:

```
        if response is not None:
            logging.debug("received block of data with length %d and content %s" % (len(response), response))
            if len(response) >= 8:
                response_length = struct.unpack("!L", response[0:4])[
                    0
                ]  # read 4 bytes for response length
                response_command = response[4:8].decode(
                    "utf-8", "ignore"
                )  # read 4 bytes for response type
            else:
                # response is less than 8 bytes long which is not enough space for package length and response message!
                raise Exception()
        else:
            response_length = 0
            response_command = None
```

The machine control goes RED and halts. It says that a log file is in the SYS: partition. Cannot access that with TNCRemo. The password is not the same as the one for the PLC (nor can I see them in "iTNC 530 Technical Manual_02_2011_en" amongst others). 

Let me know any other tests you would like to make.

Here is the output.

```
DEBUG:root:login already active
DEBUG:root:telegram to transmit: command CMD.R_RI payload length 2 bytes data: bytearray(b'\x00\x00\x00\x02R_RI\x003')
DEBUG:root:received block of data with length 10 and content b'\x00\x00\x00\x02T_ER\x01\x18'
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_WRONG_PARA
WARNING:root:an error occurred while querying current tool information. This does not work for all control types
Direct reading to current tool not supported for this control type. using backup strategy
Getting tool with itnc method
DEBUG:root:telegram to transmit: command CMD.R_FI payload length 16 bytes data: bytearray(b'\x00\x00\x00\x10R_FITNC:/TOOL_P.TCH\x00')
DEBUG:root:received block of data with length 39 and content b'\x00\x00\x00\x1fS_FI\x00\x00\x06Xb\x9a(\xd8\x00\x00\x00\x00TNC:/TOOL_P.TCH\x00\x00\x00\x00'
DEBUG:root:command CMD.R_FI executed successfully, received S_FI with 31 bytes payload
DEBUG:root:successfully received file information {'Size': 1624, 'Timestamp': datetime.datetime(2022, 6, 3, 15, 29, 28), 'Attributes': 0, 'is_file': True, 'is_directory': False, 'is_write_protected': False, 'Name': 'TNC:/TOOL_P.TCH'}
DEBUG:root:loading file from TNC:/TOOL_P.TCH to /tmp/pyLSV2_sccxc0eg/tool_p.tch
DEBUG:root:telegram to transmit: command CMD.R_FL payload length 16 bytes data: bytearray(b'\x00\x00\x00\x10R_FLTNC:/TOOL_P.TCH\x00')
DEBUG:root:received block of data with length 0 and content b''
Traceback (most recent call last):
  File "./demo-1.py", line 106, in <module>
    con.recive_file(local_path=str(local_recive_path), remote_path=pocket_table_path, binary_mode=transfer_binary)
  File "/odoo/pyLSV2/pyLSV2/pyLSV2/client.py", line 963, in recive_file
    CMD.R_FL, payload, buffer_size=self._buffer_size
  File "/odoo/pyLSV2/pyLSV2/pyLSV2/low_level_com.py", line 142, in telegram
    raise Exception()
Exception
```


On another control with a similar, later, revision the result is the same; The tool file is called TOOL_P60.TCH on that machine.

`DEBUG:root:got version info: {'Control': 'iTNC530', 'NC_Version': '340422 12 SP3', 'PLC_Version': 'GR34CS.01G', 'Options': '%0000111100000000', 'ID': '000014581109', 'SPLC_Version': 'not supported'}`

```

DEBUG:root:login already active
DEBUG:root:telegram to transmit: command CMD.R_RI payload length 2 bytes data: bytearray(b'\x00\x00\x00\x02R_RI\x003')
DEBUG:root:received block of data with length 10 and content b'\x00\x00\x00\x02T_ER\x01\x18'
WARNING:root:T_ER or T_BD received, an error occurred during the execution of the last command: LSV2_ERROR_T_ER_WRONG_PARA
WARNING:root:an error occurred while querying current tool information. This does not work for all control types
Direct reading to current tool not supported for this control type. using backup strategy
Getting tool with itnc method
DEBUG:root:telegram to transmit: command CMD.R_FI payload length 18 bytes data: bytearray(b'\x00\x00\x00\x12R_FITNC:/TOOL_P60.TCH\x00')
DEBUG:root:received block of data with length 41 and content b'\x00\x00\x00!S_FI\x00\x00\x0cpb\xa3oH\x00\x00\x00\x00TNC:/TOOL_P60.TCH\x00\x00\x00\x00'
DEBUG:root:command CMD.R_FI executed successfully, received S_FI with 33 bytes payload
DEBUG:root:successfully received file information {'Size': 3184, 'Timestamp': datetime.datetime(2022, 6, 10, 16, 20, 24), 'Attributes': 0, 'is_file': True, 'is_directory': False, 'is_write_protected': False, 'Name': 'TNC:/TOOL_P60.TCH'}
DEBUG:root:loading file from TNC:/TOOL_P60.TCH to /tmp/pyLSV2_0_025bqv/tool_p.tch
DEBUG:root:telegram to transmit: command CMD.R_FL payload length 18 bytes data: bytearray(b'\x00\x00\x00\x12R_FLTNC:/TOOL_P60.TCH\x00')
DEBUG:root:received block of data with length 0 and content b''
Traceback (most recent call last):
  File "./demo-1.py", line 107, in <module>
    con.recive_file(local_path=str(local_recive_path), remote_path=pocket_table_path, binary_mode=transfer_binary)
  File "/odoo/pyLSV2/pyLSV2/pyLSV2/client.py", line 963, in recive_file
    CMD.R_FL, payload, buffer_size=self._buffer_size
  File "/odoo/pyLSV2/pyLSV2/pyLSV2/low_level_com.py", line 142, in telegram
    raise Exception()
Exception
```


Fix patch:
diff --git a/README.md b/README.md
index 178c8cc..fadc0ef 100644
--- a/README.md
+++ b/README.md
@@ -51,6 +51,7 @@ In chronological order:
 - Michal Navrátil
 - PandaRoux8
 - sazima
+- manusolve
 
 ## Compatibility
 Since there are a lot of different software versions and machine configurations out there 
@@ -66,6 +67,7 @@ been tested:
 | TNC640      | 340595 11 SP1  |
 | TNC640      | 340595 11 SP4  |
 | iTNC530     | 606425 04 SP20 |
+| iTNC530     | 340494 08 SP2  |
 | CNCpilot640 | 1230521 03 SP1 |
 
 ### Machines
diff --git a/pyLSV2/client.py b/pyLSV2/client.py
index 744ca08..ba363ba 100644
--- a/pyLSV2/client.py
+++ b/pyLSV2/client.py
@@ -24,6 +24,7 @@
     ParRRI,
     ParRDR,
     BIN_FILES,
+    PATH_SEP,
     MODE_BINARY,
 )
 
@@ -35,6 +36,7 @@
     decode_override_information,
     decode_system_parameters,
     decode_tool_information,
+    is_file_binary,
 )
 from .translate_messages import (
     get_error_text,
@@ -507,10 +509,16 @@ def get_program_stack(self):
             stack_info = dict()
             stack_info["Line"] = struct.unpack("!L", result[:4])[0]
             stack_info["Main_PGM"] = (
-                result[4:].split(b"\x00")[0].decode().strip("\x00").replace("\\", "/")
+                result[4:]
+                .split(b"\x00")[0]
+                .decode()
+                .strip("\x00")  # .replace("\\", "/")
             )
             stack_info["Current_PGM"] = (
-                result[4:].split(b"\x00")[1].decode().strip("\x00").replace("\\", "/")
+                result[4:]
+                .split(b"\x00")[1]
+                .decode()
+                .strip("\x00")  # .replace("\\", "/")
             )
             logging.debug(
                 "successfully read active program stack and line number: %s", stack_info
@@ -575,7 +583,7 @@ def change_directory(self, remote_directory):
         :returns: True if changing of directory succeeded
         :rtype: bool
         """
-        dir_path = remote_directory.replace("\\", "/")
+        dir_path = remote_directory.replace("/", PATH_SEP)
         payload = bytearray()
         payload.extend(map(ord, dir_path))
         payload.append(0x00)
@@ -593,7 +601,7 @@ def get_file_info(self, remote_file_path):
         :returns: dictionary with info about file of False if remote path does not exist
         :rtype: dict
         """
-        file_path = remote_file_path.replace("\\", "/")
+        file_path = remote_file_path.replace("/", PATH_SEP)
         payload = bytearray()
         payload.extend(map(ord, file_path))
         payload.append(0x00)
@@ -657,12 +665,10 @@ def make_directory(self, dir_path):
         :returns: True if creating of directory completed successfully
         :rtype: bool
         """
-        path_parts = dir_path.replace("\\", "/").split(
-            "/"
-        )  # convert path to unix style
+        path_parts = dir_path.replace("/", PATH_SEP).split(PATH_SEP)  # convert path
         path_to_check = ""
         for part in path_parts:
-            path_to_check += part + "/"
+            path_to_check += part + PATH_SEP
             # no file info -> does not exist and has to be created
             if self.get_file_info(path_to_check) is False:
                 payload = bytearray()
@@ -685,7 +691,7 @@ def delete_empty_directory(self, dir_path):
         :returns: True if deleting of directory completed successfully
         :rtype: bool
         """
-        dir_path = dir_path.replace("\\", "/")
+        dir_path = dir_path.replace("/", PATH_SEP)
         payload = bytearray()
         payload.extend(map(ord, dir_path))
         payload.append(0x00)
@@ -705,7 +711,7 @@ def delete_file(self, file_path):
         :returns: True if deleting of file completed successfully
         :rtype: bool
         """
-        file_path = file_path.replace("\\", "/")
+        file_path = file_path.replace("/", PATH_SEP)
         payload = bytearray()
         payload.extend(map(ord, file_path))
         payload.append(0x00)
@@ -726,12 +732,12 @@ def copy_local_file(self, source_path, target_path):
         :returns: True if copying of file completed successfully
         :rtype: bool
         """
-        source_path = source_path.replace("\\", "/")
-        target_path = target_path.replace("\\", "/")
+        source_path = source_path.replace("/", PATH_SEP)
+        target_path = target_path.replace("/", PATH_SEP)
 
-        if "/" in source_path:
+        if PATH_SEP in source_path:
             # change directory
-            source_file_name = source_path.split("/")[-1]
+            source_file_name = source_path.split(PATH_SEP)[-1]
             source_directory = source_path.rstrip(source_file_name)
             if not self.change_directory(remote_directory=source_directory):
                 raise Exception("could not open the source directory")
@@ -739,7 +745,7 @@ def copy_local_file(self, source_path, target_path):
             source_file_name = source_path
             source_directory = "."
 
-        if target_path.endswith("/"):
+        if target_path.endswith(PATH_SEP):
             target_path += source_file_name
 
         payload = bytearray()
@@ -769,11 +775,11 @@ def move_local_file(self, source_path, target_path):
         :returns: True if moving of file completed successfully
         :rtype: bool
         """
-        source_path = source_path.replace("\\", "/")
-        target_path = target_path.replace("\\", "/")
+        source_path = source_path.replace("/", PATH_SEP)
+        target_path = target_path.replace("/", PATH_SEP)
 
-        if "/" in source_path:
-            source_file_name = source_path.split("/")[-1]
+        if PATH_SEP in source_path:
+            source_file_name = source_path.split(PATH_SEP)[-1]
             source_directory = source_path.rstrip(source_file_name)
             if not self.change_directory(remote_directory=source_directory):
                 raise Exception("could not open the source directory")
@@ -781,7 +787,7 @@ def move_local_file(self, source_path, target_path):
             source_file_name = source_path
             source_directory = "."
 
-        if target_path.endswith("/"):
+        if target_path.endswith(PATH_SEP):
             target_path += source_file_name
 
         payload = bytearray()
@@ -822,14 +828,14 @@ def send_file(
             logging.error("the supplied path %s did not resolve to a file", local_file)
             raise Exception("local file does not exist! {}".format(local_file))
 
-        remote_path = remote_path.replace("\\", "/")
+        remote_path = remote_path.replace("/", PATH_SEP)
 
-        if "/" in remote_path:
-            if remote_path.endswith("/"):  # no filename given
+        if PATH_SEP in remote_path:
+            if remote_path.endswith(PATH_SEP):  # no filename given
                 remote_file_name = local_file.name
                 remote_directory = remote_path
             else:
-                remote_file_name = remote_path.split("/")[-1]
+                remote_file_name = remote_path.split(PATH_SEP)[-1]
                 remote_directory = remote_path.rstrip(remote_file_name)
                 if not self.change_directory(remote_directory=remote_directory):
                     raise Exception(
@@ -840,21 +846,21 @@ def send_file(
         else:
             remote_file_name = remote_path
             remote_directory = self.get_directory_info()["Path"]  # get pwd
-        remote_directory = remote_directory.rstrip("/")
+        remote_directory = remote_directory.rstrip(PATH_SEP)
 
         if not self.get_directory_info(remote_directory):
             logging.debug("remote path does not exist, create directory(s)")
             self.make_directory(remote_directory)
 
-        remote_info = self.get_file_info(remote_directory + "/" + remote_file_name)
+        remote_info = self.get_file_info(remote_directory + PATH_SEP + remote_file_name)
 
         if remote_info:
             logging.debug("remote path exists and points to file's")
             if override_file:
-                if not self.delete_file(remote_directory + "/" + remote_file_name):
+                if not self.delete_file(remote_directory + PATH_SEP + remote_file_name):
                     raise Exception(
                         "something went wrong while deleting file {}".format(
-                            remote_directory + "/" + remote_file_name
+                            remote_directory + PATH_SEP + remote_file_name
                         )
                     )
             else:
@@ -864,15 +870,19 @@ def send_file(
         logging.debug(
             "ready to send file from %s to %s",
             local_file,
-            remote_directory + "/" + remote_file_name,
+            remote_directory + PATH_SEP + remote_file_name,
         )
 
         payload = bytearray()
-        payload.extend(map(ord, remote_directory + "/" + remote_file_name))
+        payload.extend(map(ord, remote_directory + PATH_SEP + remote_file_name))
         payload.append(0x00)
-        if binary_mode or self._is_file_type_binary(local_path):
+        if binary_mode or is_file_binary(local_path):
             payload.append(MODE_BINARY)
             logging.info("selecting binary transfer mode for this file type")
+        else:
+            payload.append(0x00)
+            logging.info("selecting non binary transfer mode")
+
         response, content = self._llcom.telegram(
             CMD.C_FL, payload, buffer_size=self._buffer_size
         )
@@ -934,6 +944,8 @@ def recive_file(
         :returns: True if transfer completed successfully
         :rtype: bool
         """
+
+        remote_path = remote_path.replace("/", PATH_SEP)
         remote_file_info = self.get_file_info(remote_path)
         if not remote_file_info:
             logging.error("remote file does not exist: %s", remote_path)
@@ -948,7 +960,9 @@ def recive_file(
             if override_file:
                 local_file.unlink()
             else:
-                logging.warning("remote file already exists, override was not set")
+                logging.warning(
+                    "local file already exists and override was not set. doing nothing"
+                )
                 return False
 
         logging.debug("loading file from %s to %s", remote_path, local_file)
@@ -956,9 +970,13 @@ def recive_file(
         payload = bytearray()
         payload.extend(map(ord, remote_path))
         payload.append(0x00)
-        if binary_mode or self._is_file_type_binary(remote_path):
+        if binary_mode or is_file_binary(remote_path):
             payload.append(MODE_BINARY)  # force binary transfer
             logging.info("using binary transfer mode")
+        else:
+            payload.append(0x00)
+            logging.info("using non binary transfer mode")
+
         response, content = self._llcom.telegram(
             CMD.R_FL, payload, buffer_size=self._buffer_size
         )
@@ -1019,21 +1037,6 @@ def recive_file(
 
         return True
 
-    def _is_file_type_binary(self, file_name):
-        """Check if file is expected to be binary by comparing with known expentions.
-
-        :param file_name: name of the file to check
-        :returns: True if file matches know binary file type
-        :rtype: bool
-        """
-        for bin_type in BIN_FILES:
-            if isinstance(file_name, Path):
-                if file_name.suffix == bin_type:
-                    return True
-            elif file_name.endswith(bin_type):
-                return True
-        return False
-
     def read_plc_memory(self, address, mem_type, count=1):
         """Read data from plc memory.
 
@@ -1383,7 +1386,7 @@ def get_file_list(self, path=None, descend=True, pattern=None):
         else:
             file_list = list()
             for entry in self._walk_dir(descend):
-                file_name = entry.split("/")[-1]
+                file_name = entry.split(PATH_SEP)[-1]
                 if re.match(pattern, file_name):
                     file_list.append(entry)
         return file_list
@@ -1400,7 +1403,7 @@ def read_data_path(self, path):
                 "Reading values from data path does not work on non iTNC controls!"
             )
 
-        path = path.replace("/", "\\").replace('"', "'")
+        path = path.replace("/", PATH_SEP).replace('"', "'")
 
         self.login(login=Login.DATA)
 
diff --git a/pyLSV2/const.py b/pyLSV2/const.py
index 13cda7f..aab8f4f 100644
--- a/pyLSV2/const.py
+++ b/pyLSV2/const.py
@@ -13,6 +13,8 @@
 #: enable binary file transfer for C_FL and R_FL
 MODE_BINARY = 0x01
 
+PATH_SEP = "\\"
+
 #: Regex pattern for Klartext file names
 REGEX_FILE_NAME_H = r"[\$A-Za-z0-9_-]*\.[hH]$"
 
diff --git a/pyLSV2/low_level_com.py b/pyLSV2/low_level_com.py
index 2275483..b32730c 100644
--- a/pyLSV2/low_level_com.py
+++ b/pyLSV2/low_level_com.py
@@ -129,12 +129,16 @@ def telegram(self, command, payload=None, buffer_size=0, wait_for_response=True)
             raise
 
         if response is not None:
-            response_length = struct.unpack("!L", response[0:4])[
-                0
-            ]  # read 4 bytes for response length
-            response_command = response[4:8].decode(
-                "utf-8", "ignore"
-            )  # read 4 bytes for response type
+            logging.debug("recived block of data with lenght %d" % len(response))
+            # logging.debug("recived data: %s" % response)
+            if len(response) >= 8:
+                # read 4 bytes for response length
+                response_length = struct.unpack("!L", response[0:4])[0]
+                # read 4 bytes for response type
+                response_command = response[4:8].decode("utf-8", "ignore")
+            else:
+                # respons is less than 8 bytes long which is not enough space for package lengh and response message!
+                raise Exception("response to short: %s" % response)
         else:
             response_length = 0
             response_command = None
diff --git a/pyLSV2/misc.py b/pyLSV2/misc.py
index ed82741..d3097ac 100644
--- a/pyLSV2/misc.py
+++ b/pyLSV2/misc.py
@@ -3,8 +3,9 @@
 """misc helper functions for pyLSV2"""
 import struct
 from datetime import datetime
+from pathlib import Path
 
-from .const import ControlType
+from .const import ControlType, BIN_FILES
 
 
 def decode_system_parameters(result_set):
@@ -177,3 +178,19 @@ def decode_error_message(data_set):
     error_info["Number"] = struct.unpack("!l", data_set[4:8])[0]
     error_info["Text"] = data_set[8:].decode("latin1").strip("\x00")
     return error_info
+
+
+def is_file_binary(file_name):
+    """Check if file is expected to be binary by comparing with known expentions.
+    
+    :param file_name: name of the file to check
+    :returns: True if file matches know binary file type
+    :rtype: bool
+    """
+    for bin_type in BIN_FILES:
+        if isinstance(file_name, Path):
+            if file_name.suffix == bin_type:
+                return True
+        elif file_name.endswith(bin_type):
+            return True
+    return False
\ No newline at end of file


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index afdf192..a7ddbfa 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -20,7 +20,7 @@ def address(request):
     """process commandline option 'address'"""
     par = request.config.getoption("--address")
     if par is None:
-        par = "192.168.56.101"
+        par = "localhost"
     return par
 
 
diff --git a/tests/test_file_functions.py b/tests/test_file_functions.py
index 960e521..4fb53ca 100644
--- a/tests/test_file_functions.py
+++ b/tests/test_file_functions.py
@@ -11,13 +11,13 @@ def test_read_info(address, timeout):
     lsv2.connect()
 
     if lsv2.is_itnc():
-        mdi_path = "TNC:/$MDI.H"
+        mdi_path = "TNC:\\$MDI.H"
     elif lsv2.is_pilot():
-        mdi_path = "TNC:/nc_prog/ncps/PGM01.nc"
+        mdi_path = "TNC:\\nc_prog\\ncps\\PGM01.nc"
     else:
-        mdi_path = "TNC:/nc_prog/$mdi.h"
+        mdi_path = "TNC:\\nc_prog\\$mdi.h"
 
-    assert lsv2.change_directory(remote_directory="TNC:/nc_prog") is True
+    assert lsv2.change_directory(remote_directory="TNC:\\nc_prog") is True
     assert lsv2.get_directory_info() is not False
     assert lsv2.get_file_info(remote_file_path=mdi_path) is not False
     assert lsv2.get_directory_content() is not False
@@ -37,19 +37,19 @@ def test_directory_functions(address, timeout):
     test_dir = "TNC:/nc_prog/pyLSV2_test/"
 
     lsv2.connect()
-    assert lsv2.change_directory("TNC:/nc_prog") is True
-    assert lsv2.make_directory(test_dir + "T1/T2/T3") is True
-    assert lsv2.delete_empty_directory(test_dir + "T1/T2/T3") is True
-    assert lsv2.change_directory(test_dir + "T1/T2/T3") is False
-    assert lsv2.change_directory(test_dir + "T1/T2") is True
+    assert lsv2.change_directory("TNC:\\nc_prog") is True
+    assert lsv2.make_directory(test_dir + "T1\\T2\\T3") is True
+    assert lsv2.delete_empty_directory(test_dir + "T1\\T2\\T3") is True
+    assert lsv2.change_directory(test_dir + "T1\\T2\\T3") is False
+    assert lsv2.change_directory(test_dir + "T1\\T2") is True
 
     if lsv2.is_itnc():
-        assert lsv2.delete_empty_directory(test_dir + "T1/T2") is True
-        assert lsv2.change_directory("TNC:/nc_prog") is True
+        assert lsv2.delete_empty_directory(test_dir + "T1\\T2") is True
+        assert lsv2.change_directory("TNC:\\nc_prog") is True
     else:
-        assert lsv2.delete_empty_directory(test_dir + "T1/T2") is False
-        assert lsv2.change_directory("TNC:/nc_prog") is True
-        assert lsv2.delete_empty_directory(test_dir + "T1/T2") is True
+        assert lsv2.delete_empty_directory(test_dir + "T1\\T2") is False
+        assert lsv2.change_directory("TNC:\\nc_prog") is True
+        assert lsv2.delete_empty_directory(test_dir + "T1\\T2") is True
 
     assert lsv2.delete_empty_directory(test_dir + "T1") is True
     assert lsv2.delete_empty_directory(test_dir) is True
@@ -61,16 +61,16 @@ def test_remote_file_functions(address, timeout):
     lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=True)
     lsv2.connect()
 
-    test_dir = "TNC:/nc_prog/pyLSV2_test/"
+    test_dir = "TNC:\\nc_prog\\pyLSV2_test\\"
 
     if lsv2.is_itnc():
-        mdi_dir = "TNC:/"
+        mdi_dir = "TNC:\\"
         mdi_name = "$MDI.H"
     elif lsv2.is_pilot():
-        mdi_dir = "TNC:/nc_prog/ncps/"
+        mdi_dir = "TNC:\\nc_prog\\ncps\\"
         mdi_name = "PGM01.nc"
     else:
-        mdi_dir = "TNC:/nc_prog/"
+        mdi_dir = "TNC:\\nc_prog\\"
         mdi_name = "$mdi.h"
 
     test_file_1 = test_dir + "aa.h"
@@ -78,6 +78,7 @@ def test_remote_file_functions(address, timeout):
     test_file_3 = test_dir + "cc.h"
 
     assert lsv2.make_directory(test_dir) is True
+
     assert lsv2.change_directory(test_dir) is True
 
     if lsv2.is_tnc():
@@ -113,3 +114,20 @@ def test_remote_file_functions(address, timeout):
     assert lsv2.change_directory(mdi_dir) is True
     assert lsv2.delete_empty_directory(test_dir) is True
     lsv2.disconnect()
+
+
+def test_path_formating(address, timeout):
+    """test if reading of file information with / instead of \\ as path seperator"""
+    lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=True)
+    lsv2.connect()
+
+    if lsv2.is_itnc():
+        mdi_path = "TNC:/$MDI.H"
+    elif lsv2.is_pilot():
+        mdi_path = "TNC:/nc_prog/ncps/PGM01.nc"
+    else:
+        mdi_path = "TNC:/nc_prog/$mdi.h"
+
+    assert lsv2.get_file_info(mdi_path) is not False
+
+    lsv2.disconnect()
diff --git a/tests/test_plc_read.py b/tests/test_plc_read.py
index c507d55..d0d2514 100644
--- a/tests/test_plc_read.py
+++ b/tests/test_plc_read.py
@@ -72,4 +72,7 @@ def test_data_path_read(address, timeout):
         )
         assert lsv2.read_data_path("/PLC/program/symbol/global/+STG_WZM[1]") is not None
 
+        # check if path is sanitized correctly
+        assert lsv2.read_data_path("\\PLC\\memory\\K\\1") is not None
+
     lsv2.disconnect()
diff --git a/tests/test_transfer.py b/tests/test_transfer.py
index ce4df50..b9d683e 100644
--- a/tests/test_transfer.py
+++ b/tests/test_transfer.py
@@ -88,3 +88,27 @@ def test_file_transfer_binary(address, timeout):
         assert (digests[0] == digests[1]) is True
 
     lsv2.disconnect()
+
+
+def test_path_formating(address, timeout):
+    """test if reading of file information with / instead of \\ as path seperator"""
+    lsv2 = pyLSV2.LSV2(address, port=19000, timeout=timeout, safe_mode=True)
+    lsv2.connect()
+
+    if lsv2.is_itnc():
+        mdi_path = "TNC:/$MDI.H"
+    elif lsv2.is_pilot():
+        mdi_path = "TNC:/nc_prog/ncps/PGM01.nc"
+    else:
+        mdi_path = "TNC:/nc_prog/$mdi.h"
+
+    with tempfile.TemporaryDirectory(suffix=None, prefix="pyLSV2_") as tmp_dir_name:
+        local_mdi_path = Path(tmp_dir_name).joinpath("mdi.h")
+        assert (
+            lsv2.recive_file(
+                local_path=str(local_mdi_path), remote_path=mdi_path, binary_mode=False
+            )
+            is True
+        )
+
+    lsv2.disconnect()