C# 基于winform 使用NI-VISA USB口远程控制电源 万用表

1.下载完整版本NI-VISA

NI-VISA Download - NI

*注意支持的操作系统,以便后期编译

安装完成之后,打开NI MAX,插上usb口,打开测试面板进行通信

2.编程示例

见本地文件夹C:\Users\Public\Documents\National Instruments\NI-VISA\Examples\.NET

首先添加引用

不同操作系统可引用的组件不同,win11引用NationalInstruments.Visa,win10 win7 引用ivi.visa

//win11

using Ivi.Visa;
using NationalInstruments.Visa; // 引用NI VISA库
//查找设备
private void SelectResource_Load(object sender, EventArgs e)
        {
            using (var rmSession = new ResourceManager())
            {
                var resources = rmSession.Find("(ASRL|GPIB|TCPIP|USB)?*");
                foreach (string s in resources)
                {
                    availableResourcesListBox.Items.Add(s);
                }
            }
        }

ResourceManager resourceManager = new ResourceManager();
MessageBasedSession tmcSession = (MessageBasedSession)resourceManager.Open("USB0::0x05E6::0x2220");//资源名称

tmcSession.RawIO.Write("*IDN?");//发送命令
tmcSession.FormattedIO.FlushWrite(true);
string[] res = new string[] { "", "", "", "" };
tmcSession.FormattedIO.Scanf("%,s", out res);//读取命令
//win10  win7 查找设备

using Ivi.Visa.FormattedIO;//win10  win7
using Ivi.Visa;

private void SelectResource_Load(object sender, EventArgs e)
        {
            IEnumerable<string> devices;
            try
            {
                devices = GlobalResourceManager.Find();
                foreach (string device in devices)
                {
                    Console.WriteLine("\tAddress: {0}, Alias: {1}", device, GlobalResourceManager.Parse(device).AliasIfExists);
                    availableResourcesListBox.Items.Add(device);
                }
            }
            catch (VisaException ex)
            {
            }
        }



//发送命令  读取命令
IMessageBasedSession session = GlobalResourceManager.Open("USB0::0x05E6::0x2220") as IMessageBasedSession;
MessageBasedFormattedIO formattedIO = new MessageBasedFormattedIO(session);
formattedIO.WriteLine("*IDN?");//发送命令
string res = formattedIO.ReadLine();//读取命令

设备具体编程命令可见用户手册,是德电源2200系列常见命令

是德万用表常见命令

欢迎一起讨论~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值