Expanding on the Keysight automation, there’s a few differences when interfacing with older HP gear. They tend to not have USB available and USB may not have even existed. This type of equipment tends to use GPIB (IEEE-488). Luckily, you can buy some USB to GPIB cables from Agilent/Keysight. You can tend to find these on eBay for about $75 USD.
The biggest impact this will have will be how you initialize the device. You can discover the address the same way with the newer USB instruments with Keysight Connection Expert or the Keysight Command Expert programs. For this device, it’ll have the GPIB address below.
1 2 3 4 5 6 7 8 9 |
import visa import time rm = visa.ResourceManager() v34401A = rm.open_resource('GPIB0::22::INSTR') ReturnValue = v34401A.query('*IDN?') print str(ReturnValue) v34401A.close() rm.close() |
Acquiring and Plotting
For this example we’ll collect data for five seconds, save it to a CSV, and then plot the data. Doing some basic timing tests it looks like we have an acquisition rate of about 10 samples/sec when you account for the overhead of talking over GPIB, printing the results in the prompt, and saving the data to a CSV.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import visa import time import csv import datetime import matplotlib.pyplot as plt # Generate the name of the data file based on the start of the script dataTimeString = datetime.datetime.now().strftime("%y%m%d%H%M%S") fileNameString = dataTimeString + "_data.csv" figureNameString = dataTimeString + "_figure.png" # Initialize our local variables acquisitionCount = 0 totalAcquisitions = 100 #About 10/sec, so 10 seconds of data measuredValue = 0.0 acquisitionArray = [] dataArray = [] rm = visa.ResourceManager() v34401A = rm.open_resource('GPIB0::22::INSTR') # Test for connection by asking for identification ReturnValue = v34401A.query('*IDN?') print str(ReturnValue) print 'go' # Loop our acquisitions while (acquisitionCount < totalAcquisitions): temp_values = v34401A.query_ascii_values(':MEASure:VOLTage:DC? %s,%s' % ('MAX', 'MAX')) measuredValue = temp_values[0] print 'Voltage: {0}'.format(str(measuredValue)) # Commenting out prints increases acquistion speed acquisitionArray.append(acquisitionCount) # Store our data in a local array dataArray.append(float(measuredValue)) # acquisitionCount = acquisitionCount + 1 # Increment our loop counter v34401A.close() # Close our connection to the instrument rm.close() # Create the CSV and store the data c = csv.writer(open(fileNameString,"wb")) for x in acquisitionArray: c.writerow([acquisitionArray[x],dataArray[x]]) # Generate our plot plt.xlabel('Sample') plt.ylabel('Voltage') plt.title('HP 34401A Data') plt.plot(acquisitionArray,dataArray) plt.savefig(figureNameString) plt.show() |
This results in the plot below while slowing adjusting a power supply attached to the meter.
I will try this on my DSO-X 4154A.