You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用外部触发时,如何通过PyVISA读取Keysight SMU的测量值

解决Keysight B2901A外部触发下电流测量读取问题

问题根源分析

  1. 触发源配置错误:你使用了:TRIG:ACQ:SOUR EXT9,但Keysight B2901A的外部触发源正确参数是EXT(对应后面板的TRIG IN接口),EXT9是无效选项,会导致触发系统无法正常响应外部信号。
  2. 无限触发计数导致读取超时::ARM:ACQ:COUN INF设置为无限次触发,此时使用:FETC?会让设备一直等待下一个触发事件,最终触发PyVISA的超时错误。
  3. :MEAS命令的冲突::MEAS是独立的单次测量命令,会打断你之前通过:INIT:ACQ启动的触发测量序列,因此返回无效值。

解决方案与修正代码

方案1:单次外部触发读取电流

适合每次触发后读取单个测量值的场景:

import pyvisa as visa

rm = visa.ResourceManager()
instrument = rm.open_resource('USB0::0x0957::0x8B18::MY51142340::INSTR')
# 设置超时时间,根据你的触发间隔调整,这里设为10秒
instrument.timeout = 10000

# 配置源参数
instrument.write(":SOUR:FUNC:MODE VOLT")
instrument.write(":SOUR:VOLT 2.5")
instrument.write(":SENS:CURR:PROT 5E-3")

# 修正触发配置
instrument.write(":ARM:ACQ:COUN 1")  # 设置单次触发测量
instrument.write(":TRIG:ACQ:SOUR EXT")  # 正确的外部触发源
instrument.write(":TRIG:ACQ:DEL 0")

# 4线测量配置
instrument.write(":SENS:REM ON")

# 测量参数配置
instrument.write(":SENS:VOLT:RANG:AUTO OFF")
instrument.write(":SENS:VOLT:RANG 20")
instrument.write(":SENS:CURR:RANG:AUTO OFF")
instrument.write(":SENS:CURR:RANG 1E-3")
instrument.write(":SENS:VOLT:APER 0.006")

# 启动测量序列
instrument.write(":OUTP ON")
instrument.write(":INIT:ACQ")

# 等待外部触发后读取电流值
current = instrument.query(":FETC:CURR?")
print(f"测量电流值: {current} A")

# 关闭输出
instrument.write(":OUTP OFF")
instrument.close()

方案2:多次外部触发+缓冲区读取

适合需要连续触发并批量读取多个测量值的场景:

import pyvisa as visa

rm = visa.ResourceManager()
instrument = rm.open_resource('USB0::0x0957::0x8B18::MY51142340::INSTR')
instrument.timeout = 30000  # 延长超时时间适配多次触发

# 源参数配置(同方案1)
instrument.write(":SOUR:FUNC:MODE VOLT")
instrument.write(":SOUR:VOLT 2.5")
instrument.write(":SENS:CURR:PROT 5E-3")

# 触发与缓冲区配置
measurement_count = 10  # 设置要测量的触发次数
instrument.write(f":ARM:ACQ:COUN {measurement_count}")
instrument.write(":TRIG:ACQ:SOUR EXT")
instrument.write(":TRIG:ACQ:DEL 0")
# 配置数据缓冲区大小与触发次数匹配
instrument.write(f":SENS:DATA:POIN {measurement_count}")

# 4线测量与参数配置(同方案1)
instrument.write(":SENS:REM ON")
instrument.write(":SENS:VOLT:RANG:AUTO OFF")
instrument.write(":SENS:VOLT:RANG 20")
instrument.write(":SENS:CURR:RANG:AUTO OFF")
instrument.write(":SENS:CURR:RANG 1E-3")
instrument.write(":SENS:VOLT:APER 0.006")

# 启动测量序列
instrument.write(":OUTP ON")
instrument.write(":INIT:ACQ")

# 等待所有触发完成后读取所有电流值
current_list = instrument.query(":FETC:CURR?").split(',')
print("所有测量电流值:")
for idx, curr in enumerate(current_list, 1):
    print(f"第{idx}次触发: {curr} A")

# 关闭输出
instrument.write(":OUTP OFF")
instrument.close()

关键注意事项

  • 触发源验证:确认外部触发信号连接到B2901A后面板的TRIG IN接口,信号电平符合设备要求(TTL兼容)。
  • 超时设置:根据你的触发间隔调整instrument.timeout值,避免因触发延迟导致读取超时。
  • 无限触发场景:如果必须使用无限触发(:ARM:ACQ:COUN INF),需要使用连续轮询或事件监听的方式读取,例如在循环中调用:FETC:CURR?,每次读取最新的触发测量值,但要注意处理超时问题。

内容的提问来源于stack exchange,提问作者Francesco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 03:50:10