python-3.xplotraspberry-pi4pyvisaoscilloscope

How to save 1 million point trace from oscilloscope using PyVISA


I am trying to implement some code from this old tutorial from 2015 (which is using a VERY old version of PyVISA, so everything is different now):

import numpy
import matplotlib.pyplot as plot
import sys
import pyvisa as visa
 
#Get the USB device, e.g. 'USB0::0x1AB1::0x0588::DS1ED141904883'
resources = visa.ResourceManager('@py')
usbDevices = list(filter(lambda x: 'USB' in x, resources.list_resources()))
if len(usbDevices) == 0:
    print("no usb devices found")
    sys.exit(-1)
print(usbDevices[0])
scope = resources.open_resource(usbDevices[0])
print(scope.query('*IDN?')) #Return the Rigol’s ID string to tell us it’s there
 
# Get the timescale
timescale = scope.query(":TIM:SCAL?")

# Get the timescale offset
timeoffset = scope.query(":TIM:OFFS?")
voltscale = scope.query(':CHAN1:SCAL?')

# And the voltage offset
voltoffset = scope.query(":CHAN1:OFFS?")

scope.write(":WAV:POIN:MODE RAW")
rawdata = scope.query(":WAV:DATA? CHAN1")[10:]
data_size = len(rawdata)
sample_rate = scope.query(':ACQ:SRAT?')
print('Data size:', data_size, "Sample rate:", sample_rate)

scope.write(":KEY:FORCE")
scope.close()

data = numpy.frombuffer(rawdata, 'B')

But I get the following error on the line 45, i.e., where I am trying to load the raw data into a data array:

USB0::6833::1230::DS1ZD223400795::0::INSTR
/usr/local/lib/python3.7/dist-packages/pyvisa_py/protocols/usbtmc.py:116: UserWarning: Unexpected MsgID format. Consider updating the device's firmware. See https://github.com/pyvisa/pyvisa-py/issues/20
  "Unexpected MsgID format. Consider updating the device's firmware. See https://github.com/pyvisa/pyvisa-py/issues/20"
RIGOL TECHNOLOGIES,DS1104Z Plus,DS1ZD223400795,00.04.04.SP4

Data size: 106 Sample rate: 2.500000e+08

Traceback (most recent call last):
  File "/home/pi/Documents/projects/cu/pnaci/rigol/test.py", line 45, in <module>
    data = numpy.frombuffer(rawdata, 'B')
AttributeError: 'str' object has no attribute '__buffer__'

Solution

  • The scope you are using "Rigol DS1104Z" has different SCPI commands to the "Rigol DS1052E" in your example code.

    The command ":WAV:POIN:MODE RAW" will work on the Rigol DS1052E but not on the Rigol DS1104Z

    You can check if the instrument has an error by querying ":SYSTem:ERRor?"