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系列常见命令
是德万用表常见命令
欢迎一起讨论~