赞
踩
NIMAX部分:
1、先在NI官网下载系统配置和NI-VISA:
系统配置:
https://www.ni.com/zh-cn/support/downloads/drivers/download.system-configuration.html#532687https://www.ni.com/zh-cn/support/downloads/drivers/download.system-configuration.html#532687NI-VISA:
2、下载之后运行,按需求和提示安装:
3、安装后按要求重启电脑,找到NI MAX并打开
4、左侧设备与接口显示连接情况
5、打开VISA测试面板,单击Query可得到产品信息
6、举例:输入volt 7\n,单击write,将电压设置为7v
7、举例:输入SYST:VERS? ,单击write,来查询当前使用的SCPI命令的版本号(指令参考设备手册)
pyvisa部分:
1、安装所需库:
pip install pyvisa
2、参考文档:
3、基础
- # write()向仪器发送命令
- # read()接收响应数据
- # query()向仪器发送命令并接收响应数据
-
- # lock()锁定仪器,防止其他程序访问
- # unlock()解锁仪器,允许其他程序访问
4、例1:设置仪器电压为5v
- import pyvisa
-
- rm = pyvisa.ResourceManager()
- instrument = rm.open_resource('USB0::0x2EC7::0x6700::802260084767510008::INSTR')
-
- # 设置电压为5V
- instrument.write("VOLT 5")
-
- # 获取电压读数
- print(instrument.query("MEAS:VOLT?"))
5、例2:设置电压为5v两秒,然后电压为10v两秒,然后电压为15v两秒,然后电压为10v两秒,然后电压为5v两秒
- import pyvisa
- import time
-
- rm = pyvisa.ResourceManager()
- instrument = rm.open_resource('USB0::0x2EC7::0x6700::802260084767510008::INSTR')
-
- # 设置电压为5V,持续两秒
- instrument.write("VOLT 5")
- time.sleep(2)
-
- # 设置电压为10V,持续两秒
- instrument.write("VOLT 10")
- time.sleep(2)
-
- # 设置电压为15V,持续两秒
- instrument.write("VOLT 15")
- time.sleep(2)
-
- # 设置电压为10V,持续两秒
- instrument.write("VOLT 10")
- time.sleep(2)
-
- # 设置电压为5V,持续两秒
- instrument.write("VOLT 5")
- time.sleep(2)
-
- # 获取电压读数
- print(instrument.query("MEAS:VOLT?"))
6、例3:使电压在五秒内逐渐由0v上升到10v,然后维持状态两秒,然后再让其逐渐下降到0v,持续五秒(0.5s为一个单位)
- import pyvisa
- import time
-
- rm = pyvisa.ResourceManager()
- instrument = rm.open_resource('USB0::0x2EC7::0x6700::802260084767510008::INSTR')
-
- # 逐渐增加电压值至10V
- for voltage in range(0, 11):
- instrument.write("VOLT {}".format(voltage))
- time.sleep(0.5) # 每0.5秒增加一个单位的电压
-
- # 维持电压值为10V两秒
- time.sleep(2)
-
- # 逐渐减少电压值至0V
- for voltage in range(10, -1, -1):
- instrument.write("VOLT {}".format(voltage))
- time.sleep(0.5) # 每0.5秒减少一个单位的电压
-
- # 维持电压值为0V五秒
- time.sleep(5)
-
- # 获取电压读数
- print(instrument.query("MEAS:VOLT?"))
7、给例3添加输出状态
- import pyvisa
- import time
-
- rm = pyvisa.ResourceManager()
- instrument = rm.open_resource('USB0::0x2EC7::0x6700::802260084767510008::INSTR')
-
- # 设置输出状态为ON
- instrument.write("OUTPUT ON")
-
- # 逐渐增加电压值至10V
- for voltage in range(0, 11):
- instrument.write("VOLT {}".format(voltage))
- time.sleep(0.5) # 每0.5秒增加一个单位的电压
-
- # 维持电压值为10V两秒
- time.sleep(2)
-
- # 逐渐减少电压值至0V
- for voltage in range(10, -1, -1):
- instrument.write("VOLT {}".format(voltage))
- time.sleep(0.5) # 每0.5秒减少一个单位的电压
-
- # 维持电压值为0V五秒
- time.sleep(5)
-
- # 获取电压读数
- print(instrument.query("MEAS:VOLT?"))
-
- # 设置输出状态为OFF
- instrument.write("OUTPUT OFF")
8、把例3封装在一个方法里方便调用
- import pyvisa
- import time
-
- def control_voltage_sequence():
- rm = pyvisa.ResourceManager()
- instrument = rm.open_resource('USB0::0x2EC7::0x6700::802260084767510008::INSTR')
-
- # 逐渐增加电压值至10V
- for voltage in range(0, 11):
- instrument.write("VOLT {}".format(voltage))
- time.sleep(0.5) # 每0.5秒增加一个单位的电压
-
- # 维持电压值为10V两秒
- time.sleep(2)
-
- # 逐渐减少电压值至0V
- for voltage in range(10, -1, -1):
- instrument.write("VOLT {}".format(voltage))
- time.sleep(0.5) # 每0.5秒减少一个单位的电压
-
- # 维持电压值为0V五秒
- time.sleep(5)
-
- # 获取电压读数
- print(instrument.query("MEAS:VOLT?"))
-
- # 调用函数执行电压控制序列
- control_voltage_sequence()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。