【问题标题】:Sending SCPI/GPIB commands over USB from C#从 C# 通过 USB 发送 SCPI/GPIB 命令
【发布时间】:2017-05-16 08:09:47
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# usb visa gpib


    【解决方案1】:

    我正在使用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

    【讨论】:

      【解决方案2】:

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

      来自 NI 的那个:

      1. 格式化IO488类
      2. 资源管理器类
      3. VisaConflictTableManagerClass

      要获得连接,只需要1和2

      一旦您尝试嵌入互操作类型,您需要删除“类”后缀,如 here 所述

      这是来自是德科技的 sn-p 示例(应用说明: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 { }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-14
        • 1970-01-01
        • 1970-01-01
        • 2013-02-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多