jwinterm
jwinterm

Reputation: 334

Reading output buffer of Agilent 4156C using PyVisa

I'm trying to use PyVisa to control an Agilent 4156C using its FLEX command set. The communication seems to be working OK, as I can query the instrument with *IDN? and read the status byte. I also think I'm setting up my voltage sweep properly now, as I don't see any errors on the screen of the 4156 when I execute the Python script. My problem is that when I try to read the measurement data using the RMD? command, the instrument doesn't respond, and the program errors due to timeout. Here is my current program:

import visa

rm = visa.ResourceManager()

inst = rm.open_resource('GPIB0::17::INSTR')
print(inst.query('*IDN?'))
inst.timeout = 6000

print(inst.write('US'))
print(inst.write('FMT 1,1'))

# Set short integration time
print(inst.write('SLI 1'))
# Enable SMU 3
print(inst.write('CN 3'))
# Set measurement mode to sweep (2) on SMU 3
print(inst.write('MM 2,3'))
# Setup voltage sweep on SMU 3
#print(inst.write('WV 3,3,0,0.01,0.1,0.01'))
print(inst.write('WV 3,3,0,-0.1,0.1,0.01,0.01,0.001,1'))
# Execute
print(inst.write('XE'))

# Query output buffer
print("********** Querying RMD **********")
print(inst.write('RMD? 0'))
print(inst.read())

print("********** Querying STB **********")
print(inst.query('*STB?'))

The program always hangs when I try to read after writing 'RMD? 0', or if I query that command. I feel like I am missing something simple, but just not able to find it in the available Agilent or PyVisa documentation. Any help would be greatly appreciated. I'm using the standard NI VISA that comes with LabView (I mention that because I came across this post).

Upvotes: 0

Views: 2427

Answers (1)

Jean
Jean

Reputation: 21

I encountered the same problem and solved it. Command XE launches the execution of current/voltages measurements with Agilent 4156C: it is thus not possible to send any additional GPIB command during execution. Even "STB?" does not work. The only way I found to check status byte and measurement completion is checking continuously "inst.stb" paramter which is updated continuously by visa driver. Hope this will help other users. My code:

class Agilent4156C:
    def __init__(self, address):
        try:
            rm = visa.ResourceManager(r'C:\\Windows\\system32\\visa32.dll')
            self.com=rm.open_resource(address)
            self.com.read_termination = '\n'
            self.com.query_delay = 0.0
            self.com.timeout=5000
        except:
            print("** error while connecting to B1500 **")
    def execution(self):
        self.com.write("XE")
        while self.com.stb != 17:
            time.sleep(0.5)         

Upvotes: 2

Related Questions