首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PyVisa和打印新数据

PyVisa和打印新数据
EN

Stack Overflow用户
提问于 2012-10-18 00:36:52
回答 1查看 1K关注 0票数 2

我正在尝试使用Pyvisa从我的Keithly 2701数字万用表的一个通道捕获数据。

我通过temp = keithly.ask('SCPI COmmand')得到一个静态的一次性响应,但我想要做的是不断打印新数据,而不设置任何预定义的大小,即捕获300个数据点。

如果我看到了超过10000个数据点的趋势,或者在另一个实验中,我可能看到超过2500个数据点的趋势,我想确定何时停止捕获。

代码语言:javascript
运行
复制
from pylab import *
from visa import instrument

inst = SerialInstument(args)

while new data:
    print inst.aks('channel')
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-18 05:52:51

代码语言:javascript
运行
复制
while True:
    print inst.ask('channel')
    time.sleep(1)

然后,您可以按ctrl-c组合键在您认为合适的时候停止循环。

上面的脚本很简单-它只是把数字放在屏幕上,直到你杀了它。我发现使用matplotlib实时绘制来自PyVISA的数据非常有用。我发现这在pyplot模式下有错误(当我关闭交互模式,ymmv时,我得到了很多空白屏幕),所以我把它嵌入到tkinter窗口中,如下所示:

代码语言:javascript
运行
复制
import matplotlib
matplotlib.use('TkAgg')  # this has to go before the other imports
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import Tkinter as Tk
import visa

# set up a PyVISA instrument and a list for the data
data = []
keithley = visa.instrument('GPIB0::whatever')

# make a Tkinter window
root = Tk.Tk()

# add a matplotlib figure to the Tk window
fig = Figure()
ax = fig.add_subplot(111)
canv = FigureCanvasTkAgg(fig, master=root)
canv.show()
canv.get_tk_widget().pack(fill='both', expand=True)

# a function that is called periodically by the event loop
def plot_update():
    # add a new number to the data
    data.append(keithley.ask('SCPI:COMM:AND?'))

    # replot the data in the Tk window
    ax.clear()
    ax.plot(data)
    fig.tight_layout()
    canv.draw()

    # wait a second before the next plot
    root.after(1000, plot_update)

root.after(1000, plot_update)
root.mainloop()

它可能看起来不是很多,但我们逐渐将这样一个简短的脚本开发成了一个功能相当强大的仪器控制程序;)

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12939083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档