-
-
Save samclane/c0fb90219214361cb963674b3bc82848 to your computer and use it in GitHub Desktop.
#!/usr/bin/python | |
""" | |
Download data from a Rigol DS1052E oscilloscope channel 1 and | |
dump to a .wav file. | |
By Ken Shirriff, http://righto.com/rigol | |
Modified by Sawyer McLane 2/28/2019 | |
""" | |
import sys | |
import visa | |
import wave | |
import numpy | |
import time | |
rm = visa.ResourceManager() | |
# Get the USB device, e.g. 'USB0::0x1AB1::0x0588::DS1ED141904883' | |
instruments = rm.list_resources() | |
usb = [x for x in instruments if "USB" in x] | |
if len(usb) != 1: | |
print('Bad instrument list', instruments) | |
sys.exit(-1) | |
scope = rm.open_resource(usb[0]) | |
scope.values_format.use_ascii('x', '$', numpy.array) | |
scope.timeout = 25e3 | |
# Grab the raw data from channel 1 | |
# scope.write(":STOP") | |
scope.write(":WAV:POIN:MODE RAW") | |
scope.write(":WAV:DATA? CHAN1") | |
rawdata = scope.read_raw()[:int(1e7)] | |
data_size = len(rawdata) | |
sample_rate = float(''.join(scope.ask_for_values(':ACQ:SAMP?')[0])) | |
print('Data size:', data_size, "Sample rate:", sample_rate) | |
scope.write(":KEY:FORCE") | |
scope.close() | |
# Dump data to the wav file | |
wav_file = wave.open("./audio/{}.wav".format(str(int(time.time()))), "w") | |
nchannels = 1 | |
sampwidth = 1 | |
comptype = "NONE" | |
compname = "not compressed" | |
wav_file.setparams((nchannels, sampwidth, sample_rate, data_size, | |
comptype, compname)) | |
# Data will be written inverted | |
wav_file.writeframes(rawdata) | |
wav_file.close() |
Has pyvisa deprecated values_format attribute? When I run your script I get the following error: "AttributeError: 'USBInstrument' object has no attribute 'values_format'"
Yes, I think you're correct.
I haven't run this code in a while, but looking at the PyVISA docs, I can only find reference to values_format
when looking at deprecated versions.
Hello samclane
I had two questions:
- What's the alternative to values_format?
- Will this work for other RIGOL scopes like DS6064?
Hello samclane
I had two questions:
- What's the alternative to values_format?
- Will this work for other RIGOL scopes like DS6064?
-
I haven't used
pyvisa
in quite a while, so I'm not sure right now. This script is deprecated as of now, but it's probably worth me taking a look at since this script is of use to a few other people -
Again, I'm not sure. I think it should, as
VISA
sits at the driver layer and should be hardware agnostic.
Hi Samclane and Chitres,
I am not sure what the new way to set the values format is on Rigol Oscillopes, but I have found that without it, you just get data in binary format, which you can convert to voltage by querying the scope for the channel y-scale and y-offset. I've posted a jupyter-notebook which works for me:
https://github.com/josiahsinclair/RigolScopeWaveformCapture.git
Hope that helps.
Has pyvisa deprecated values_format attribute? When I run your script I get the following error: "AttributeError: 'USBInstrument' object has no attribute 'values_format'"