Collecting data as fast as possible from 34465A? - Page 1
Forum section: electronics / projects

author: Pack34
author_rank: Frequent Contributor
timestamp: March 12, 2019, 12:53:46 pm
content: These are supposed to be 5000 samples/sec, but when using some Python to control it, I seem to only be getting <100 samples per second. Could this simply be a limitation due to Python or is there a way to speed it up?Code:from subprocess import callimport visaimport timeimport csvimport datetime# start of UntitledfileNameString = datetime.datetime.now().strftime("%y%m%d%H%M") + "_data.csv"c = csv.writer(open(fileNameString,"wb"))dcVoltage=0dcVoltage2=0counts = 0limit = 5000range='1V'resolution='MAXimum'rm = visa.ResourceManager()v34465A = rm.open_resource('USB0::0x2A8D::0x0101::MY57514375::0::INSTR')v34465A_2 = rm.open_resource('USB0::0x2A8D::0x0101::MY54505836::0::INSTR')while (counts < limit):temp_values = v34465A.query_ascii_values(':MEASure:VOLTage:DC? %s,%s' % (range, resolution))dcVoltage = temp_valuestemp_values2 = v34465A_2.query_ascii_values(':MEASure:VOLTage:DC? %s,%s' % (range, resolution))dcVoltage2 = temp_values2c.writerow([counts,dcVoltage,dcVoltage2])counts = counts + 1v34465A.close()v34465A_2.close()rm.close()# end of Untitled

author: bson
author_rank: Unknown
timestamp: March 13, 2019, 11:37:03 am
content: The main problem is there's limit to how fast you can issue commands. Between commands the instruments sit idle.Try something along the lines of:CONF:VOLT:DC 1V,0.0003SAMP:COUN 1000TRIG:COUN 1TRIG:SOUR IMMINITFETCH?The INIT will start the sampling, and FETCH? will wait for the sampling to finish and return the data.So you can set up your two instruments, send them both INIT, and then FETCH? the data from them.If you need tighter synchronization, then you can have one instrument trigger off the other. Hook up thetrig out BNC on instrument A to ext trig in BNC on instrument B, then set instrument A to output a trigger:OUTP:TRIG:SLOP POSThen on instrument B have it trigger off this, instead of TRIG:SOURCE IMM use:TRIG:SOUR EXT;SLOP POSThen on B issue INIT, and on A issue INIT. A will start sampling and issue a trigger for B to also start.Then FETCH? on the two instruments to get the results.Or something along those lines.

author: Pack34
author_rank: Frequent Contributor
timestamp: March 14, 2019, 03:15:40 am
content: Thanks!Is there a way to set the sampling interval?

author: bson
author_rank: Unknown
timestamp: March 14, 2019, 04:38:17 am
content: I don't really know. I'd strongly recommend downloading the manual (from Keysight) and reading through the SCPI programming section. It has a bunch of examples too. There's definitely a bit of a learning curve to this.

author: samipetri
author_rank: Newbie
timestamp: March 14, 2019, 05:49:39 am
content: There is free memory upgrade promo for this meter.https://www.keysight.com/main/editorial.jspx?cc=FI&lc=fin&ckey=2990857&nid=-32051.1242959.00&id=2990857I think that fastest way collect data is take samples to internal memoy first.Also shutting down the meter display will increase sampling rate.

author: bson
author_rank: Unknown
timestamp: March 15, 2019, 12:43:37 am
content: BTW, the 0.0003 in the example is 0.3ms, which is the shortest sampling interval (5kHz, rounded to a PLC boundary) you can use without the DIG digitizer option.Whenever you use INIT it always captures to internal memory. FETCH? and R? retrieve from memory. I forget the difference off hand, but I think FETCH? waits while R? returns a partial set. It's all in the manual.

author: Pack34
author_rank: Frequent Contributor
timestamp: June 07, 2023, 08:02:55 pm
content: I'm about to ask another question, so felt I should answer my old one.The below code captures data as fast as possible. If you uncomment the first SAMPLE:SOURCE and SAMPLE:TIMER and comment out the second SAMPLE:SOURCE you can switch to taking samples at the specified 100ms.Code:import pyvisa as visaimport timeimport csvimport datetime# Setup our instrumentrm = visa.ResourceManager()v34465A = rm.open_resource('USB0::0x2A8D::0x0101::MY57514376::0::INSTR') # Open instrument over USBv34465A.write(':CONFigure:VOLTage:DC %G,%s' % (1.0, 'MAXimum')) # Set range and resolutionv34465A.write(':SAMPle:COUNt %d' % (100)) # 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 100msv34465A.write(':SAMPle:SOURce %s' % ('IMMediate')) # Sample as fast as possiblev34465A.write(':TRIGger:SOURce %s' % ('IMMediate')) # Immediately trigger on initv34465A.write(':FORMat:DATA %s' % ('ASCii')) # Data format must be set to fetchv34465A.write(':INITiate:IMMediate') # Start sampling# Delay needed to sample. Fetching data will timeout if data not readyprint("Sampling...")time.sleep(1)print("Done")# Retrieve the data from the instrumenttemp_values = v34465A.query_ascii_values(':FETCh?')# Create data filefileNameString = 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 = 0for x in temp_values:data = [ sample_counter, x ]c.writerow(data)sample_counter = sample_counter+1f1.close()v34465A.close()rm.close()

author: Gribo
author_rank: Frequent Contributor
timestamp: June 07, 2023, 08:18:17 pm
content: You might want to use the LXI interface instead of the USB interface.