Posted Sat, 21 Oct 2023 18:04:46 GMT by Hill, Richard
I am having trouble communicating with my DAQ6510 over Ethernet, using PyVISA and TSP. I'm using Python to establish a connection with the 6510 and execute one command:
 
import pyvisa
resource_mgr = pyvisa.ResourceManager()
print(resource_mgr.list_resources())

my_instr = resource_mgr.open_resource("TCPIP0::192.168.10.121::inst0::INSTR")

# my_instr.query('dmm.measure.read()')
my_instr.write('dmm.measure.read()')
The open_resource() call fails with a timeout:
 
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.

Pinging the 6510 works fine, and using Test Script Builder works fine as well. I can send commands with Test Script Builder interactively and also run scripts from the IDE, this all works fine.

I don't have a lot of experience with PyVISA, I am essentially following the Tek app note titled "How to Write Scripts for Test Script Processing (TSP)". In that app note they claim to be using PyVISA in the example code but actually import "visa" (a module for the credit card institution) which has nothing to do with PyVISA so I am assuming that was a typo and "pyvisa" is the library that I should be using. 

The 6510 is the only TSP-enabled instrument that I have available so I can't try this with anything else.

Does anyone have any ideas what could be going wrong here?
 
Posted Mon, 23 Oct 2023 13:44:14 GMT by Hill, Richard
Update/clarification (editing my previous post seems to destroy the formatting):

The VISA resource string I use in the open_resource() call is the same one reported by list_resources(). This is also the same string that I have been passing to Test Script Builder, it works there.

Also, the DAQ6510 is configured for TSP (not SCPI) I have double-checked that.
Posted Wed, 25 Oct 2023 02:07:35 GMT by C, Andrea
Hi Richard,

I do not see anything wrong with that you are doing.
Is the LAN connection from Test Script Builder closed?  The instrument can accept only one connection at a time.

For future reference, when the LAN connection gets stranded, there is a dead socket recovery port.
If you can connect on the dead socket and then close, it forces any open LXI LAN connection (port 5025) to close.
If my theory about an open connection from Test Script Builder is why you are having troubles, the dead socket would let you take it away.
import pyvisa
import time


resource_mgr = pyvisa.ResourceManager()
#optional print available VISA resources on this computer
resource_list = resource_mgr.list_resources()
for resource in resource_list:
    print(resource)

try:
     #get a session/handle for one resource
     instrument_resource_string = "TCPIP0::192.168.1.55::inst0::INSTR" 
     #resource_list[0]  #for me, resource_list[0] = 
     my_instr = resource_mgr.open_resource(instrument_resource_string)
except(pyvisa.VisaIOError):
     #try connect on dead socket on port 5030
     print("Attempting Dead Socket recovery.....")
     my_instr = resource_mgr.open_resource("TCPIP0::192.168.1.55::5030::SOCKET")
     my_instr.close()
     time.sleep(0.5)
     #try again now on normal LXI port
     my_instr = resource_mgr.open_resource(instrument_resource_string)
     print("Done attempting Dead Socket recovery.....")
    


my_instr.write("*IDN?\n")
print("*****")
print(my_instr.read())
Posted Thu, 26 Oct 2023 19:16:09 GMT by Hill, Richard
Hi Andrea, thank you for your reply.

I think there were two problems at play here, one of them you identified when you said "The instrument can accept only one connection at a time," of which I was not aware.

I was using Test Script Builder interactively to do a sanity-check of my TSP commands, but was leaving it running so that explains why I could no longer communicate after starting TSB.

My underlying problem -- the reason why my Python script was not working in the first place, was I think due to a quirk with TSP when running over PyVISA. Please confirm my suspicion here, but I think that this line of code will not work:
 
my_instr.query('dmm.measure.read()')

The code above causes a timeout for me (my original problem). This however does work:
 
my_instr.query('print(dmm.measure.read())')

The subtle distinction being that TSP print(...) produces something on stdout which I suppose is captured and returned by the query() command, but dmm.measure.read() does not produce anything on stdout. So that I and maybe others aren't tripped up by this in the future, can you advise what TSP statements can be used with VISA query(), other than print(..) ?


Thanks in advance,
Richard



 
Posted Fri, 27 Oct 2023 21:08:09 GMT by C, Andrea
You have it correct.
Only commands that end in question mark will automatically cause a response to be put into the output queue.
Your VISA read transfers the output queue.
In conventional SCPI there are often query form of commands to interrogate instrument settings.
In TSP, we rely on the print() or printbuffer() to place content in output queue.

There is a status.condition register with a message available bit (MAV) that will be logic 1 if there is content in output queue.  Use VISA ReadSTB rather than a visa read after writing print(status.condition) command.

You must be signed in to post in this forum.