通过USB从C#发送SCPI / GPIB命令

时间:2017-01-02 07:52:33

标签: c# usb visa gpib

我正试图通过SCPI与C#的一些测试设备进行通信。我设法通过使用this code example与通过TCP / IP连接的一台设备进行通信。

然而,我的其他设备是通过USB连接的,我还没有找到如何通过USB与他们通信。

BTW,我找到了this question,以及答案到IVI-COM programming examples in C#文档的链接,但我无法应用代码示例(例如在5.4节中)因为所有的IVI和VISA我找到的COM库(例如VisaComLib 5.5)里面只有接口和枚举,没有我可以使用的具体类......

2 个答案:

答案 0 :(得分:1)

如果您从NationalInstruments或Keysight安装签证驱动程序,他们会实现类:

来自NI的那个:

  1. FormattedIO488Class
  2. ResourceManagerClass
  3. VisaConflictTableManagerClass
  4. 要获得连接,您只需要1和2

    只要您尝试嵌入互操作类型,就需要删除“类”'后缀,如here

    所述

    以下是Keysight的示例代码段(应用说明:5989-6338EN)

    Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager();
    Ivi.Visa.Interop.FormattedIO488 ioobj = new Ivi.Visa.Interop.FormattedIO488();
    
    try
    {
    
        object[] idnItems;
    
        ioobj.IO = (Ivi.Visa.Interop.IMessage)rm.Open("GPIB2::10::INSTR",
        Ivi.Visa.Interop.AccessMode.NO_LOCK, 0, "");
    
        ioobj.WriteString("*IDN ?", true);
    
        idnItems = (object[])ioobj.ReadList(Ivi.Visa.Interop.IEEEASCIIType.ASCIIType_Any, ",");
    
        foreach(object idnItem in idnItems)
        {
            System.Console.Out.WriteLine("IDN Item of type " + idnItem.GetType().ToString());
            System.Console.Out.WriteLine("\tValue of item is " + idnItem.ToString());
        }
    
    }
    catch(Exception e)
    {
        System.Console.Out.WriteLine("An error occurred: " + e.Message);
    }
    finally
    {
    
        try { ioobj.IO.Close(); }
        catch { }
    
        try
        {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(ioobj);
        }
        catch { }
    
        try
        {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rm);
        }
        catch { }
    }
    

答案 1 :(得分:0)

我正在使用National Instruments VISA

向您的项目添加对NationalInstruments.VisaNSNationalInstruments.Common的引用。

创建MessageBasedSession,请参阅以下代码:

string resourceName = "USB0::0x0957::0x0118::US56070667::INSTR"; // See NI MAX for resource name
var visa = new NationalInstruments.VisaNS.MessageBasedSession(resourceName);
visa.Write("*IDN?"); // write to instrument
string res = visa.ReadString(); // read from instrument

另见https://stackoverflow.com/a/49388678/7556646