It looks like either python-ivi or pyvisa will use the same python-vxi11 module (import vxi11) to connect to an instrument over LAN. I've tested and they are both very slow, it takes 23 minutes to fetch 24MSa.
# pip install python-vxi11
# Successfully installed python-vxi11-0.9
import vxi11
dso = vxi11.Instrument('192.168.1.3')
# alternatives (transfer speed is the same):
# dso = vxi11.Instrument("TCPIP::192.168.1.3::INSTR")
print(dso.ask('*IDN?'))
dso.write(':RUN')
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':ACQ:MDEP 24000000') # !!! can only be set when in :RUN mode
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:MODE MAX') # !!! 1200 points in :RUN mode, all MDEP points in STOP mode
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:FORM BYTE')
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:SOUR CHAN1')
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:STAR 1')
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':STOP')
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:STOP 250000') # !!! will be ignored and always 1200 in :RUN mode
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
wvfm_pre = dso.ask('WAV:PRE?')
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
print(wvfm_pre)
print(dso.ask('WAV:MODE?'), dso.ask('WAV:STAR?'), dso.ask('WAV:STOP?'))
dso.write(':STOP')
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
import time
t0 = time.time()
wvfm = dso.ask_raw(b':WAV:DATA?') # get 1200 points in :RUN mode or :WAV:STOP? points in :STOP mode
t1 = time.time() - t0
print('Time to fetch the first waveform chunk: ' , t1)
print(type(wvfm), len(wvfm))
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
to_fetch = 1_000_000 # fetch only 1Msa of ADC samples
MAX_CHUNK = 250_000
M_DEPTH = int(dso.ask(':ACQ:MDEP?'))
all_wvfm = bytes()
t0 = time.time()
for i in range(0, min(to_fetch, M_DEPTH), MAX_CHUNK):
dso.write(':WAV:STAR ' + str(i+1))
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:STOP ' + str(i + min(MAX_CHUNK, M_DEPTH, to_fetch-i)))
while dso.ask('*OPC?') != '1': print('Waiting for command to finish')
wvfm = dso.ask_raw(b':WAV:DATA?') # get 1200 points in :RUN mode or :WAV:STOP? points in :STOP mode
all_wvfm += wvfm[12:]
print(len(wvfm))
t1 = time.time() - t0
print('Time to fetch ' + str(to_fetch) + ' ADC samples using "python-vxi11": ' + str(t1))
dso.close()
If I open a connection with SOCKET, or if I use something like the 'socketscpi' module, it fetches 24MSa in 23 seconds.
# socketscpi is using direct TCP socket instead of VXI-11
# pip install socketscpi
# Successfully installed socketscpi-2022.8.0
# might work as a backend for PyVISA ????? for LXI instruments
# https://github.com/morgan-at-keysight/socketscpi/blob/master/examples.py
import socketscpi
dso = socketscpi.SocketInstrument(ipAddress='192.168.1.3', port=5555, timeout=1)
# dso = socketscpi.SocketInstrument(ipAddress='192.168.1.3', port=5555, globalErrCheck=True)
print(dso.instId)
dso.write(':RUN')
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':ACQ:MDEP 24000000') # !!! can only be set when in :RUN mode
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:MODE MAX') # !!! 1200 points in :RUN mode, all MDEP points in STOP mode
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:FORM BYTE')
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:SOUR CHAN1')
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:STAR 1')
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':STOP')
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:STOP 250000') # !!! will be ignored and always 1200 in :RUN mode
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
wvfm_pre = dso.query('WAV:PRE?')
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
print(wvfm_pre)
print(dso.query('WAV:MODE?'), dso.query('WAV:STAR?'), dso.query('WAV:STOP?'))
dso.write(':STOP')
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
import time
t0 = time.time()
wvfm = dso.query(':WAV:DATA?') # get 1200 points in :RUN mode or :WAV:STOP? points in :STOP mode
t1 = time.time() - t0
print('Time to fetch the first waveform chunk: ' , t1)
print(type(wvfm), len(wvfm))
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
to_fetch = 1_000_000 # fetch only 1Msa of ADC samples
MAX_CHUNK = 250_000
M_DEPTH = int(dso.query(':ACQ:MDEP?'))
all_wvfm = b''
t0 = time.time()
for i in range(0, min(to_fetch, M_DEPTH), MAX_CHUNK):
dso.write(':WAV:STAR ' + str(i+1))
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
dso.write(':WAV:STOP ' + str(i + min(MAX_CHUNK, M_DEPTH, to_fetch-i)))
while dso.query('*OPC?') != '1': print('Waiting for command to finish')
wvfm = dso.query(':WAV:DATA?') # get 1200 points in :RUN mode or :WAV:STOP? points in :STOP mode
b = bytes(wvfm[12:], 'latin_1')
all_wvfm += b
print(len(wvfm))
t1 = time.time() - t0
print('Time to fetch ' + str(to_fetch) + ' ADC samples using "socketscpi": ' + str(t1))
dso.close()
The downside is if I send a wrong command I have to power cycle the oscilloscope.
My oscilloscope is Rigol DS1104Z (in python-ivi its driver module is 'rigol.rigolDS1054'), it has the fixed IP 192.168.1.3, and the port for SOCKET access is 5555.
Do you have a working code example, please, for connecting to the oscilloscope from python-ivi, or even from PyVISA, but using SOCKET instead of VXI11, and then print the result of the '*IDN?'