AnsweredAssumed Answered

File Transfer from PC to NA with Python

Question asked by joanna.cropsey@caci.com on Nov 30, 2020

Hello!

I am running into a rather annoying issue trying to transfer a .sta file from my PC to network analyzer. (Currently, I am testing with P5004A VNA but I need it to work with our PNA-X N5241B down the line).

I have been able to test the code I wrote, using Python 3.8, with the MMEM:TRAN SCPI command. It works with a simple .txt file but will not work with the .sta file I want to transfer - the error I keep getting is: 

[SCPI: -161]: Invalid block data; Received ^END before specified end of Definite Length Block

 

Since I've gotten this to work with a simple text file, I do not believe my code to be the issue - I think that it is recognizing some kind of null byte in the file as the end of file.

 

The code I have is:

with open(source_path, 'rb') as file:
read_file = file.read()
byte_count = len(read_file)
num_digits = len(str(byte_count))

if isinstance(read_file[0], int):
ascii_list = [chr(x) for x in read_file]
read_file = ''.join(ascii_list)
else:
read_file = read_file.decode()

send_str = f'#{num_digits}{byte_count}{read_file}\n'
self.send_command('transfer file', target_path, send_str)

The method takes a local PC filepath (in this case, to the .sta) and attempts to read and format into a valid command to send on to the instrument. 

The send_command argument will be in the form: "MMEM:TRAN "<new filepath on VNA>",#{num_digits}{byte_count}{read_file}". For the P5004A, this will be sent over IVI-COM client, for the N5241B it will be sent over a TCP connection.

 

I have used the MMEM:TRAN? command to query an identical .sta file I have stored on the NA and it produces an identical string response to the one I am sending when attempting to transfer from PC to NA.

 

First few lines of command being sent are:

 

And first few lines of the received bin block query (ignoring INFO log bit):

 

I'm at a loss on what to do to fix the EOF error. Any help would be greatly appreciated! Thanks in advance.

Outcomes