当前位置:   article > 正文

NIMAX下载安装使用,pyvisa基本使用

NIMAX下载安装使用,pyvisa基本使用

NIMAX部分:

1、先在NI官网下载系统配置和NI-VISA:

系统配置:

https://www.ni.com/zh-cn/support/downloads/drivers/download.system-configuration.html#532687icon-default.png?t=N7T8https://www.ni.com/zh-cn/support/downloads/drivers/download.system-configuration.html#532687NI-VISA

https://www.ni.com/zh-cn/support/downloads/drivers/download.ni-visa.html#521671icon-default.png?t=N7T8https://www.ni.com/zh-cn/support/downloads/drivers/download.ni-visa.html#521671

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、参考文档:       

https://pyvisa.readthedocs.io/en/latest/introduction/communication.htmlicon-default.png?t=N7T8https://pyvisa.readthedocs.io/en/latest/introduction/communication.html

3、基础

  1. # write()向仪器发送命令
  2. # read()接收响应数据
  3. # query()向仪器发送命令并接收响应数据
  4. # lock()锁定仪器,防止其他程序访问
  5. # unlock()解锁仪器,允许其他程序访问

4、例1:设置仪器电压为5v

  1. import pyvisa
  2. rm = pyvisa.ResourceManager()
  3. instrument = rm.open_resource('USB0::0x2EC7::0x6700::802260084767510008::INSTR')
  4. # 设置电压为5V
  5. instrument.write("VOLT 5")
  6. # 获取电压读数
  7. print(instrument.query("MEAS:VOLT?"))

5、例2:设置电压为5v两秒,然后电压为10v两秒,然后电压为15v两秒,然后电压为10v两秒,然后电压为5v两秒

  1. import pyvisa
  2. import time
  3. rm = pyvisa.ResourceManager()
  4. instrument = rm.open_resource('USB0::0x2EC7::0x6700::802260084767510008::INSTR')
  5. # 设置电压为5V,持续两秒
  6. instrument.write("VOLT 5")
  7. time.sleep(2)
  8. # 设置电压为10V,持续两秒
  9. instrument.write("VOLT 10")
  10. time.sleep(2)
  11. # 设置电压为15V,持续两秒
  12. instrument.write("VOLT 15")
  13. time.sleep(2)
  14. # 设置电压为10V,持续两秒
  15. instrument.write("VOLT 10")
  16. time.sleep(2)
  17. # 设置电压为5V,持续两秒
  18. instrument.write("VOLT 5")
  19. time.sleep(2)
  20. # 获取电压读数
  21. print(instrument.query("MEAS:VOLT?"))

6、例3:使电压在五秒内逐渐由0v上升到10v,然后维持状态两秒,然后再让其逐渐下降到0v,持续五秒(0.5s为一个单位)

  1. import pyvisa
  2. import time
  3. rm = pyvisa.ResourceManager()
  4. instrument = rm.open_resource('USB0::0x2EC7::0x6700::802260084767510008::INSTR')
  5. # 逐渐增加电压值至10V
  6. for voltage in range(0, 11):
  7. instrument.write("VOLT {}".format(voltage))
  8. time.sleep(0.5) # 每0.5秒增加一个单位的电压
  9. # 维持电压值为10V两秒
  10. time.sleep(2)
  11. # 逐渐减少电压值至0V
  12. for voltage in range(10, -1, -1):
  13. instrument.write("VOLT {}".format(voltage))
  14. time.sleep(0.5) # 每0.5秒减少一个单位的电压
  15. # 维持电压值为0V五秒
  16. time.sleep(5)
  17. # 获取电压读数
  18. print(instrument.query("MEAS:VOLT?"))

7、给例3添加输出状态

  1. import pyvisa
  2. import time
  3. rm = pyvisa.ResourceManager()
  4. instrument = rm.open_resource('USB0::0x2EC7::0x6700::802260084767510008::INSTR')
  5. # 设置输出状态为ON
  6. instrument.write("OUTPUT ON")
  7. # 逐渐增加电压值至10V
  8. for voltage in range(0, 11):
  9. instrument.write("VOLT {}".format(voltage))
  10. time.sleep(0.5) # 每0.5秒增加一个单位的电压
  11. # 维持电压值为10V两秒
  12. time.sleep(2)
  13. # 逐渐减少电压值至0V
  14. for voltage in range(10, -1, -1):
  15. instrument.write("VOLT {}".format(voltage))
  16. time.sleep(0.5) # 每0.5秒减少一个单位的电压
  17. # 维持电压值为0V五秒
  18. time.sleep(5)
  19. # 获取电压读数
  20. print(instrument.query("MEAS:VOLT?"))
  21. # 设置输出状态为OFF
  22. instrument.write("OUTPUT OFF")

8、把例3封装在一个方法里方便调用

  1. import pyvisa
  2. import time
  3. def control_voltage_sequence():
  4. rm = pyvisa.ResourceManager()
  5. instrument = rm.open_resource('USB0::0x2EC7::0x6700::802260084767510008::INSTR')
  6. # 逐渐增加电压值至10V
  7. for voltage in range(0, 11):
  8. instrument.write("VOLT {}".format(voltage))
  9. time.sleep(0.5) # 每0.5秒增加一个单位的电压
  10. # 维持电压值为10V两秒
  11. time.sleep(2)
  12. # 逐渐减少电压值至0V
  13. for voltage in range(10, -1, -1):
  14. instrument.write("VOLT {}".format(voltage))
  15. time.sleep(0.5) # 每0.5秒减少一个单位的电压
  16. # 维持电压值为0V五秒
  17. time.sleep(5)
  18. # 获取电压读数
  19. print(instrument.query("MEAS:VOLT?"))
  20. # 调用函数执行电压控制序列
  21. control_voltage_sequence()
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/979171
推荐阅读
相关标签
  

闽ICP备14008679号