Author Topic: Collecting data as fast as possible from 34465A?  (Read 1804 times)

0 Members and 1 Guest are viewing this topic.

Offline Pack34Topic starter

  • Frequent Contributor
  • **
  • Posts: 753
Collecting data as fast as possible from 34465A?
« on: March 12, 2019, 12:53:46 pm »
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: [Select]
from subprocess import call
import visa
import time
import csv
import datetime
# start of Untitled

fileNameString = datetime.datetime.now().strftime("%y%m%d%H%M") + "_data.csv"
c = csv.writer(open(fileNameString,"wb"))

dcVoltage=0
dcVoltage2=0
counts = 0
limit = 5000
range='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_values[0]
    temp_values2 = v34465A_2.query_ascii_values(':MEASure:VOLTage:DC? %s,%s' % (range, resolution))
    dcVoltage2 = temp_values2[0]
    c.writerow([counts,dcVoltage,dcVoltage2])
    counts = counts + 1

v34465A.close()
v34465A_2.close()
rm.close()

# end of Untitled

 

Offline bson

  • Supporter
  • ****
  • Posts: 2253
  • Country: us
Re: Collecting data as fast as possible from 34465A?
« Reply #1 on: March 13, 2019, 11:37:03 am »
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.0003
SAMP:COUN 1000
TRIG:COUN 1
TRIG:SOUR IMM
INIT
FETCH?

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 the
trig out BNC on instrument A to ext trig in BNC on instrument B, then set instrument A to output a trigger:
OUTP:TRIG:SLOP POS

Then on instrument B have it trigger off this, instead of TRIG:SOURCE IMM use:
TRIG:SOUR EXT;SLOP POS

Then 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.
 

Offline Pack34Topic starter

  • Frequent Contributor
  • **
  • Posts: 753
Re: Collecting data as fast as possible from 34465A?
« Reply #2 on: March 14, 2019, 03:15:40 am »
Thanks!

Is there a way to set the sampling interval?
 

Offline bson

  • Supporter
  • ****
  • Posts: 2253
  • Country: us
Re: Collecting data as fast as possible from 34465A?
« Reply #3 on: March 14, 2019, 04:38:17 am »
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.
 

Offline samipetri

  • Newbie
  • Posts: 2
  • Country: fi
Re: Collecting data as fast as possible from 34465A?
« Reply #4 on: March 14, 2019, 05:49:39 am »
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=2990857
I think that fastest way collect data is take samples to internal memoy first.
Also shutting down the meter display will increase sampling rate.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2253
  • Country: us
Re: Collecting data as fast as possible from 34465A?
« Reply #5 on: March 15, 2019, 12:43:37 am »
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. :D
 

Offline Pack34Topic starter

  • Frequent Contributor
  • **
  • Posts: 753
Re: Collecting data as fast as possible from 34465A?
« Reply #6 on: June 07, 2023, 08:02:55 pm »
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: [Select]
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' % (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 100ms
v34465A.write(':SAMPle:SOURce %s' % ('IMMediate'))                              # Sample as fast as possible
v34465A.write(':TRIGger:SOURce %s' % ('IMMediate'))                         # Immediately trigger on init
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...")
time.sleep(1)
print("Done")

# Retrieve the data from the instrument
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()
 

Offline Gribo

  • Frequent Contributor
  • **
  • Posts: 628
  • Country: ca
Re: Collecting data as fast as possible from 34465A?
« Reply #7 on: June 07, 2023, 08:18:17 pm »
You might want to use the LXI interface instead of the USB interface.
I am available for freelance work.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf