寻找包含Ivi.Visa.Interop命名空间的NuGet包
问题描述
尝试编译Keysight官网提供的仪器截图控制台程序,但无法找到包含代码中Ivi.Visa.Interop命名空间的公开NuGet包。搜索Ivi.Visa.Interop无结果,搜索Ivi.Visa得到以下包:
Kelary.Ivi.Visa Ldx.Ni.Visa IviFoundation.Visa hyf.Ivi.Visa
但这些包均不含Ivi.Visa.Interop命名空间。程序代码如下:
using System; using System.IO; using System.Net.Mail; using Ivi.Visa.Interop; namespace GetScreenshot_CSharp { class Program { // ***WARRANT DISCLAIMER*** --> This example is provided as an illustration "as is", and Keysight Technologies // makes no warranty of any kind with regard to this example. //This program uses the VISA-COM library which is installed with the Keysight IO Libraries Suite. //The IO Suite can be found at www.keysight.com/find/iosuite //You must add a reference to the VISA COM 3.0 (OR 5.2 or newer depending on IO Suite version) Type library by //right-clicking on the project and selecting Add Reference. //Modify the address to match your instrument. //Address Examples (GPIB, RS-232, USB or LAN): // GPIB0::22::INSTR // ASRL1::INSTR // USB0::0x0957::0x2007::MY49002286::0::INSTR // TCPIP0::159.149.151.62::inst0::INSTR // Address can also be a VISA Alias // This example just saves the screenshot directly to your desktop and will overwrite any file with the same name. // // ****This example will work on the Keysight 3446xA DMM's, 33500/33600 ARB's and the 53200 series counters.**** public static void Main() { Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); Ivi.Visa.Interop.FormattedIO488 ioobj = new Ivi.Visa.Interop.FormattedIO488(); string idnStr = null; byte[] myImage = null; string desktop = null; try { //Open a session and get the IDN string ioobj.IO = (Ivi.Visa.Interop.IMessage)rm.Open("USB0::0x0957::0x2C07::MY52814625::0::INSTR", Ivi.Visa.Interop.AccessMode.EXCLUSIVE_LOCK, 0, ""); ioobj.WriteString("*IDN?", true); idnStr = ioobj.ReadString(); Console.WriteLine("IDN response = " + idnStr); Console.WriteLine("Hit Enter to Continue and get ARB screenshot"); Console.ReadLine(); //Upload the screenshot and write to a file on the desktop names test1.bmp ioobj.WriteString("HCOPy:SDUMp:DATA:FORMat BMP", true); ioobj.WriteString("HCOPy:SDUMp:DATA?", true); myImage = ioobj.ReadIEEEBlock(Ivi.Visa.Interop.IEEEBinaryType.BinaryType_UI1); desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); using (BinaryWriter writer = new BinaryWriter(File.Open((desktop + "\\test1.bmp"), FileMode.Create))) { foreach (byte value in myImage) { writer.Write(value); } } Console.WriteLine("Hit Enter to Exit"); Console.ReadLine(); } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); Console.WriteLine("Ensure you have the correct address for your instrument"); Console.WriteLine("Hit Enter to Exit"); Console.ReadLine(); } finally { try { ioobj.IO.Close(); } catch { } try { System.Runtime.InteropServices.Marshal.ReleaseComObject(ioobj); } catch { } try { System.Runtime.InteropServices.Marshal.ReleaseComObject(rm); } catch { } } } } }
请问如何找到对应Ivi.Visa.Interop命名空间的NuGet包?
解决方案
1. 明确:Ivi.Visa.Interop并非NuGet包提供
Ivi.Visa.Interop是VISA-COM库的COM互操作命名空间,这个库是Keysight IO Libraries Suite的组件之一,不会通过公开NuGet仓库分发。代码注释里已经明确提示了这一点:该程序依赖随Keysight IO Libraries Suite安装的VISA-COM库。
2. 正确的引用方式(无需NuGet)
- 安装Keysight IO Libraries Suite(需从Keysight官方渠道获取)
- 在Visual Studio中操作:
- 右键你的项目 → 选择「添加」→「引用」
- 切换到「COM」标签页
- 找到并勾选「VISA COM 3.0」(或更高版本,比如5.2+,取决于你安装的IO Suite版本)
- 点击「确定」完成引用添加
- 添加后,Visual Studio会自动生成
Ivi.Visa.Interop的互操作程序集,此时即可正常编译代码。
3. 为什么你找到的NuGet包不兼容?
你搜索到的Kelary.Ivi.Visa、IviFoundation.Visa等包都是VISA标准的.NET原生实现,它们的命名空间是Ivi.Visa,而非Ivi.Visa.Interop,和代码中基于COM的调用逻辑不兼容,因此无法直接替换使用。
4. 替代方案(改用.NET原生VISA)
如果不想依赖COM组件,可以选择使用IviFoundation.Visa这类NuGet包,重构代码为原生.NET调用。例如:
- 替换
Ivi.Visa.Interop.ResourceManager为Ivi.Visa.ResourceManager - 调整IO操作的API(比如用
MessageBasedSession替代FormattedIO488) - 适配仪器命令的发送和数据读取逻辑
内容的提问来源于stack exchange,提问作者alok
相关产品推荐
相关产品推荐

