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、基础

# 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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不吃橘子的橘猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值