What I'm trying to accomplish, is to set the DMM to using the external trigger and collecting 1 sample at each edge of the trigger. The issue is that the amount of triggers will be unknown. I'd like to be able to set the
TRIGGER:COUNT to infinity as per the programming manual and then do a
READ? when I'm ready to grab the data. The issue is that this doesn't work. The number of triggers specified seems to need to be satisfied in order to query the data from the meter. Otherwise it just times out waiting for a response.
When doing a
READ instead of a
FETCH it triggers error
420 Query UNTERMINATED.
The programming manual gives the option of INIFINTIY for the TRIGGER_COUNT value so I would assume I should be able to do something like this. Unless there's a specific mode I need to put it in? Do I need to send an alternate of INIT to close the data collection process?
import pyvisa as visa
import time
import csv
import datetime
# Setup our instrument
rm = visa.ResourceManager()
v34465A = rm.open_resource('USB0::0x2A8D::0x0101::MY57514376::0::INSTR') # Open instrument over USB
v34465A.write(':CONFigure:VOLTage:DC %G,%s' % (1.0, 'MAXimum')) # Set range and resolution
v34465A.write(':SAMPle:COUNt %d' % (1)) # Specify number of samples to 100
#v34465A.write(':SAMPle:SOURce %s' % ('TIMer')) # Sample using a timer
#v34465A.write(':SAMPle:TIMer %G' % (0.1)) # Timer interval of 100ms
v34465A.write(':SAMPle:SOURce %s' % ('IMMediate')) # Sample as fast as possible
v34465A.write(':TRIGger:SOURce %s;SLOP POS' % ('EXTernal')) # Immediately trigger on init
v34465A.write(':TRIGger:COUNt %d' % (10)) #
v34465A.write(':FORMat:DATA %s' % ('ASCii')) # Data format must be set to fetch
v34465A.write(':INITiate:IMMediate') # Start sampling
# Delay needed to sample. Fetching data will timeout if data not ready
print("Sampling...")
input("Press Enter to continue...")
print("Done")
# Retrieve the data from the instrument
temp_values = v34465A.query_ascii_values(':READ?')
# temp_values = v34465A.query_ascii_values(':FETCh?')
# Create data file
fileNameString = datetime.datetime.now().strftime("%y%m%d%H%M") + "_data.csv"
f1 = open(fileNameString, "w", newline='', encoding='utf-8')
c = csv.writer(f1)
header = ['Sample', 'Voltage']
c.writerow(header)
sample_counter = 0
for x in temp_values:
data = [ sample_counter, x ]
c.writerow(data)
sample_counter = sample_counter+1
f1.close()
v34465A.close()
rm.close()