題目の通り。
前回のような手順できちんとlinux-gpibパッケージでpython-bindingがインストールできていれば以下で行けるはず。
- import gpib
- import time
- from datetime import datetime
- device = gpib.dev(0, 5)
- gpib.timeout(device, gpib.T10s)
- log_file = "measurement_log.csv"
- with open(log_file, "w") as f:
- f.write("Timestamp,Voltage\n")
- try:
- while True:
- gpib.write(device, "MEAS:VOLT?\n")
- response = gpib.read(device, 100).decode().strip()
- timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
- with open(log_file, "a") as f:
- f.write(f"{timestamp},{response}\n")
- print(f"{timestamp} -> {response} V")
- time.sleep(1)
- except KeyboardInterrupt:
- print("測定を中断しました。")
- finally:
- gpib.close(device)
- print("GPIBデバイスを閉じました。")
gpib.write(device."*IDN?\n")print(gpib.read(device, 100))
としてしまうと,結果が,
b'HEWLETT-PACKARD,34401A,0,1.0\n'
みたいになってしまう。なので,
print(gpib.read(device, 100).decode().strip())
とすれば
HEWLETT-PACKARD,34401A,0,1.0と返ってくる。
よく使う関数をまとめておく。
| 関数 | 説明 |
|---|---|
gpib.dev(board_index, pad) | デバイスハンドルを取得 |
gpib.write(device, command) | コマンド送信 |
gpib.read(device, length) | 応答読み取り |
gpib.close(device) | デバイスを閉じる |
gpib.timeout(device, value) | タイムアウト設定(例: gpib.T10s) |
0 件のコメント:
コメントを投稿