python-3.x - 如何使用 PyVISA 从示波器中保存 100 万个点轨迹
问题描述
我正在尝试从 2015 年的这个旧教程中实现一些代码(它使用的是非常旧版本的 PyVISA,所以现在一切都不同了):
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')
但是我在第 45 行收到以下错误,即我试图将原始数据加载到数据数组中:
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__'
解决方案
您使用的示波器“Rigol DS1104Z”与示例代码中的“Rigol DS1052E”具有不同的 SCPI 命令。
命令“:WAV:POIN:MODE RAW”在 Rigol DS1052E 上有效,但在 Rigol DS1104Z 上无效
您可以通过查询“:SYSTem:ERRor?”来检查仪器是否有错误。
推荐阅读
- c++ - 无法链接到现有的 libopenblas.so.0 DLL
- node.js - 授权的oauth实施不起作用
- php - 仅在最后一个值中打印数组值中的 foreach 循环
- docker - Dockerfile/ Docker Compose 用于具有不同端口的多个项目
- python - 重复字符串匹配 Leetcode
- laravel-5 - 如何在共享主机上部署 vue.js 和 laravel 应用程序
- python - 我应该在哪里调用 django CBV 中的自定义方法?(详细视图)
- outlook - 如何使用 python 读取特定的 Outlook 电子邮件并将其保存到 excel/csv
- pyvmomi - pyvmomi perfManager - 获取所有统计信息
- react-native - 我们可以从我的应用程序中访问本地 Whatsapp 消息吗?