我正在尝试使用Pyvisa从我的Keithly 2701数字万用表的一个通道捕获数据。
我通过temp = keithly.ask('SCPI COmmand')
得到一个静态的一次性响应,但我想要做的是不断打印新数据,而不设置任何预定义的大小,即捕获300个数据点。
如果我看到了超过10000个数据点的趋势,或者在另一个实验中,我可能看到超过2500个数据点的趋势,我想确定何时停止捕获。
from pylab import *
from visa import instrument
inst = SerialInstument(args)
while new data:
print inst.aks('channel')
发布于 2012-10-18 05:52:51
while True:
print inst.ask('channel')
time.sleep(1)
然后,您可以按ctrl-c组合键在您认为合适的时候停止循环。
上面的脚本很简单-它只是把数字放在屏幕上,直到你杀了它。我发现使用matplotlib实时绘制来自PyVISA的数据非常有用。我发现这在pyplot模式下有错误(当我关闭交互模式,ymmv时,我得到了很多空白屏幕),所以我把它嵌入到tkinter窗口中,如下所示:
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()
它可能看起来不是很多,但我们逐渐将这样一个简短的脚本开发成了一个功能相当强大的仪器控制程序;)
https://stackoverflow.com/questions/12939083
复制相似问题