The laboratory recently purchased two new oscilloscopes of a differing brand but I would prefer very much to use the $6,000 model from Agilent already in the laboratory. I like their products and want to outfit my own laboratory with one of their future makes. But I do not understand the differences in API content and when to use the necessary commands.
I would like to make a simple program in python to communicate with the HP54542A across national instruments GPIB-USB-HS connector using ni488.2 protocals. Agilent, National Instruments and Python are my favorite tools. I am very new in this area (scope communication) and could find nothing on the level of simplicity which I desired to implement for my Agilent scope. I think the API for the infiniium models is close/the same as for the HP54542A.
I went to pyVISA and ran a modified version of the starting program for their tektronics example. It worked perfectly...
import visa
from visa import instrument
my_instrument = instrument("GPIB0::7::INSTR")
my_instrument.write("*IDN?")
print my_instrument.read()
Returning this in the command window:::::::::::::
HEWLETT-PACKARD,54542A,US35300131,00.13,01.12,02.30,01.01
I tried the next tektronics example for data acquisition and tried to modify the API for my Agilent scope...That is really where I am struggling. I do not understand the "commands" in the API for Agilent equipment. The order of commands required to sequentially export acquired data, I need to better understand....
I do not know if my meager understanding will help but here is the tek script and here is the agilent script which I slightly modified using the API for the HP54542A.
TEK
from visa import instrument
keithley = instrument("GPIB::12")
keithley.write("*rst; status:preset; *cls")
interval_in_ms = 500
number_of_readings = 10
keithley.write("status:measurement:enable 512; *sre 1")
keithley.write("sample:count %d" % number_of_readings)
keithley.write("trigger:source bus")
keithley.write("trigger:delay %f" % (interval_in_ms / 1000.0))
keithley.write("trace:points %d" % number_of_readings)
keithley.write("trace:feed sense1; feed:control next")
keithley.write("initiate")
keithley.trigger()
keithley.wait_for_srq()
voltages = keithley.ask_for_values("trace:data?")
print "Average voltage: ", sum(voltages) / len(voltages)
keithley.ask("status:measurement?")
keithley.write("trace:clear; feed:control next")
AGILENT
from visa import instrument
HP = instrument("GPIB::7")
HP.write("*rst; status:preset; *cls")
interval_in_ms = 500
number_of_readings = 10
HP.write("status:measurement:enable 512; *sre 1")
HP.write("acquire:count %d" % number_of_readings)
HP.write("trigger:source bus")
HP.write("trigger:delay %f" % (interval_in_ms / 1000.0))
HP.write("acquire:points %d" % number_of_readings)
HP.write("trace:feed sense1; feed:control next")
HP.write("initiate")
HP.trigger()
HP.wait_for_srq()
voltages = HP.ask_for_values("trace:data?")
print "Average voltage: ", sum(voltages) / len(voltages)
HP.ask("status:measurement?")
HP.write("trace:clear; feed:control next")
So I noticed that the sample count and sample points were replaced (between Keithely 2000 DMM from TEK to HP54542A) by acquire count and acquire points. There was no trace:feed or feed:control or trace:data? commands in the API? There seemed to be some WAV:POIN command and WAV:DATA...I thought that trace is SCPI and common for most instruments?
Mostly, the problem is I do not know what sequence of commands to use and why? I will try just about anything. I do not think agilent still supports HP equipment do they? If there were a generic python module to log data that were posted in pyVISA I know hundreds of people who would choose to use it...
Thank you for the help, I really appreciate it...
I would like to make a simple program in python to communicate with the HP54542A across national instruments GPIB-USB-HS connector using ni488.2 protocals. Agilent, National Instruments and Python are my favorite tools. I am very new in this area (scope communication) and could find nothing on the level of simplicity which I desired to implement for my Agilent scope. I think the API for the infiniium models is close/the same as for the HP54542A.
I went to pyVISA and ran a modified version of the starting program for their tektronics example. It worked perfectly...
import visa
from visa import instrument
my_instrument = instrument("GPIB0::7::INSTR")
my_instrument.write("*IDN?")
print my_instrument.read()
Returning this in the command window:::::::::::::
HEWLETT-PACKARD,54542A,US35300131,00.13,01.12,02.30,01.01
I tried the next tektronics example for data acquisition and tried to modify the API for my Agilent scope...That is really where I am struggling. I do not understand the "commands" in the API for Agilent equipment. The order of commands required to sequentially export acquired data, I need to better understand....
I do not know if my meager understanding will help but here is the tek script and here is the agilent script which I slightly modified using the API for the HP54542A.
TEK
from visa import instrument
keithley = instrument("GPIB::12")
keithley.write("*rst; status:preset; *cls")
interval_in_ms = 500
number_of_readings = 10
keithley.write("status:measurement:enable 512; *sre 1")
keithley.write("sample:count %d" % number_of_readings)
keithley.write("trigger:source bus")
keithley.write("trigger:delay %f" % (interval_in_ms / 1000.0))
keithley.write("trace:points %d" % number_of_readings)
keithley.write("trace:feed sense1; feed:control next")
keithley.write("initiate")
keithley.trigger()
keithley.wait_for_srq()
voltages = keithley.ask_for_values("trace:data?")
print "Average voltage: ", sum(voltages) / len(voltages)
keithley.ask("status:measurement?")
keithley.write("trace:clear; feed:control next")
AGILENT
from visa import instrument
HP = instrument("GPIB::7")
HP.write("*rst; status:preset; *cls")
interval_in_ms = 500
number_of_readings = 10
HP.write("status:measurement:enable 512; *sre 1")
HP.write("acquire:count %d" % number_of_readings)
HP.write("trigger:source bus")
HP.write("trigger:delay %f" % (interval_in_ms / 1000.0))
HP.write("acquire:points %d" % number_of_readings)
HP.write("trace:feed sense1; feed:control next")
HP.write("initiate")
HP.trigger()
HP.wait_for_srq()
voltages = HP.ask_for_values("trace:data?")
print "Average voltage: ", sum(voltages) / len(voltages)
HP.ask("status:measurement?")
HP.write("trace:clear; feed:control next")
So I noticed that the sample count and sample points were replaced (between Keithely 2000 DMM from TEK to HP54542A) by acquire count and acquire points. There was no trace:feed or feed:control or trace:data? commands in the API? There seemed to be some WAV:POIN command and WAV:DATA...I thought that trace is SCPI and common for most instruments?
Mostly, the problem is I do not know what sequence of commands to use and why? I will try just about anything. I do not think agilent still supports HP equipment do they? If there were a generic python module to log data that were posted in pyVISA I know hundreds of people who would choose to use it...
Thank you for the help, I really appreciate it...
- Every manufacturer is free to use their own command set and syntax for controlling their instruments.
- Agilent spun out of HP, and there is some support available for older products. That said, full support is available for, usually, 5 years after discontinuance. Beyond that, here may be some information available. The 54542A went out of support in 2003, but if you go to the Agilent website, and search on that product number, you will find manuals and programming examples.
- In general, using SCPI comands is always the same. Write a command, and optionally (depending on the command) read the response. The programming examples from above are in 'C' but they would be easy to translate into Python. I used some examples like that to write my first MATLAB programs to control an Infiniium. I took the MATLAB code and used it to write my first Python code:
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 21
@author: AG
Based on the MATLAB benchmark code "Unload Benchmark"
"""
from visa import *
import time
"""
defining global tuples
"""
VisaAddress = ('USB0::0x0957::0x9001::MY50520109::0::INSTR')
Depth = (5e5, 1e6, 2e6, 5e6, 1e7, 2e7, 5e7)
BlockSize = (1e4, 2e4, 5e4, 1e5, 2e5, 5e5, 1e6, 2e6, 5e6, 1e7, 2e7)
AcqCount = 5
"""
Function AcqAndRead, matching MATLAB Function
"""
def AcqAndRead (scope, blocksize) :
scope.write(':single')
ter = 0;
while ter != 1:
ter = int(scope.ask(':ter?'))
npts = int(scope.ask(':wav:points?'))
blockCount = int(npts/blocksize)
time.sleep(0.1)
for k in range(blockCount):
blockStart = int(k*blocksize+1)
blockEnd = int((k+1)*blocksize)
blockEnd = min(blockEnd,npts)
blockPtstoRead = min(blocksize,(blockEnd-blockStart+1))
data = scope.ask(':wav:data? %i, %i' % (blockStart, blockPtstoRead))
return len(data)
"""
END AcqAndRead
"""
"""
Function TestLoopTime, matching the MATLAB function
"""
def TestLoopTime (visaaddress, acqcount, depth, blocksize):
scope = instrument(visaaddress)
# input_size = 2 * blocksize + 1
# scope.chunk_size = input_size
scope.timeout = 10
scope.write(':stop;:cdis')
scope.write('acquire:points %i' % depth)
scope.write(':waveform:view all')
scope.write(':acquire:interpolate off')
scope.write(':wav:format WORD')
scope.write(':WAVEFORM:BYTEORDER LSBFirst')
scope.write(':SYSTEM:HEADER OFF')
scope.write(':WAV:SOUR CHAN1')
startTime = time.time()
for i in range(0 , acqcount) :
nacqs = AcqAndRead(scope, blocksize)
endTime = time.time()
averageTime = (endTime - startTime) / acqcount
return averageTime
"""
END TestLoopTime
"""
"""
Main Program
"""
print 'Passes per run: %i \n' % AcqCount
print 'Intfc Language Block Time/Acq Pts/Acq Pts/sec \n'
for i in range(0,len(Depth)):
for j in range(0,len(BlockSize)):
if Depth[i] >= BlockSize[j]:
AverageTime = TestLoopTime(VisaAddress, AcqCount, int(Depth[i]), int(BlockSize[j]))
PointsPerSec = Depth[i]/AverageTime
print 'LAN, Python, %10.0f, %5.3f, %10.0f, %10.0f' % (BlockSize[j], AverageTime, Depth[i], PointsPerSec)
print 'Done'
It's ugly code, but it worked, last year when I was using it for benchmarks. It's not complete, because it doesn't unpack the captured data, but it's close.
Al