Python VISA(USB和以太网)库,用于控制RIGOL DS1000Z系列示波器。
Rigol1000z的Python项目详细描述
里戈尔1000Z
python库控制基于visa协议(pyvisa)的rigol ds1000z系列示波器。示波器可以通过USB或以太网连接到本地网络(有关更多信息,请参阅PYVISA文档)。
使用RIGOL DS1054Z在Windows 10和Arch Linux上测试。
依赖关系
示例
importvisaimportRigol1000zrm=visa.ResourceManager()# We are connecting the oscilloscope through USB here.# Only one VISA-compatible instrument is connected to our computer,# thus the first resource on the list is our oscilloscope.# You can see all connected and available local devices calling## print(rm.list_resources())#osc_resource=rm.open_resource(rm.list_resources()[0])osc=Rigol1000z.Rigol1000z(osc_resource)# Change voltage range of channel 1 to 50mV/div.osc[1].set_vertical_scale_V_div(50e-3)# Stop the scope.osc.stop()# Take a screenshot.osc.get_screenshot('screenshot.png','png')# Capture the data sets from channels 1--4 and# write the data sets to their own file.forcinrange(1,5):osc[c].get_data('raw','channel%i.dat'%c)
调用其他命令
这个库实现了一些功能接口,这些接口是在RIGOL DS1000Z系列示波器中最常用的SCPI命令。但是,在“mso1000z/dso1000z编程指南”(http://int.rigol.com/File/TechDoc/20151218/MSO1000Z&DS1000Z_ProgrammingGuide_EN.pdf)中还有更多的命令。我还没有验证,但很可能物理菜单和屏幕菜单中的所有可用选项都有相应的scpi命令。用户可以通过以下方法直接从示波器发送SCPI命令和接收信息:
visa_write(cmd)# Will read all bytes in the buffer until a termination character is found, # and interpret them as ASCII charactersvisa_read()# Will read num_bytes bytes in the buffer, or until a termination caracter is found if# num_bytes == -1, and hand them out as binary informationvisa_read_raw(num_bytes=-1):# Combines the functions of visa_write(cmd) and visa_read()visa_ask(cmd):# Combines the functions of visa_write(cmd) and visa_read_raw()visa_ask_raw(cmd,num_bytes=-1)
读取软件测量和静态数据
由于接收统计和测量数据的许多可能的组合例程没有预先编程,必须由用户使用直接的visa通信功能来实现。例如:
# Select channel 1 as an input to the hardware frequency counterscope.visa_write(':MEASure:COUNter:SOURce CHANnel1')# Turn on statistics displayscope.visa_write(':MEASure:STATistic:DISPlay ON')# Change statistics mode to 'difference'scope.visa_write(':MEASure:STATistic:MODE DIFFerence')# We can have up to five different measurementes displayed# on the oscilloscope screen at the same time# Select Vpp measurement on channel 1 to be displayedscope.visa_write(':MEASure:STATistic:ITEM VPP,CHANnel1')# Select Vpp measurement on channel 2 to be displayedscope.visa_write(':MEASure:STATistic:ITEM VPP,CHANnel2')# Select Rising Edge Delay measurement between channel 1 and# channel 2 to be displayedscope.visa_write(':MEASure:STATistic:ITEM RDELay,CHANnel1,CHANnel2')# Clear the statistical results in memoryscope.visa_write(':MEASure:STATistic:RESet')# We can read the statistical results (averages, maximums, minimums, deviations, etc.)# or the current values of the measurements enabled above.# Numeric results are given in ASCII scientific notation, so a quick conversion# to float is neededvin=float(scope.visa_ask(':MEASure:STATistic:ITEM? AVERages,VPP,CHANnel1'))vout=float(scope.visa_ask(':MEASure:STATistic:ITEM? AVERages,VPP,CHANnel2'))delay=float(scope.visa_ask(':MEASure:STATistic:ITEM? AVERages,RDELay'))freq=float(scope.visa_ask(':MEASure:COUNter:VALue?'))
手动扫频bode图测量的完整实现可在examples文件夹中找到。
致谢
基于@jtambasco的原始工作。我已经做了一个代码清理,几个错误修复和一个完整的后端重写,现在有一个pyvisa依赖关系,以便使这个库跨平台。还改进了文档并添加了示例。