2

私はPyvisaを使用して、Keithly2701DMMのチャネルの1つからデータをキャプチャしようとしています。

を介して静的なワンタイム応答を取得します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')
4

1 に答える 1

4
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()

大したことではないように思えるかもしれませんが、私たちはこのような短いスクリプトを徐々に開発して、かなり有能な計測器制御プログラムにしました ;)

于 2012-10-17T21:52:51.223 に答える