通过USB从C#发送SCPI/GPIB命令 [英] Sending SCPI/GPIB commands over USB from C#

查看:1126
本文介绍了通过USB从C#发送SCPI/GPIB命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过SCPI与C#中的某些测试设备进行通信.通过使用此代码示例.

I'm trying to communicate with some test equipment from C# over SCPI. I managed to communicate with one device that is connected through TCP/IP by using this code example.

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

However, my other devices are connected through USB and I haven't find how to communicate with them over USB.

顺便说一句,我发现了这个问题,以及答案中的链接到 C#中的IVI-COM编程示例文档,但是我无法应用代码示例(例如在5.4节中),因为我发现的所有IVI和VISA COM库(例如VisaComLib 5.5)都只有接口和枚举,而没有可以使用的具体类.../p>

BTW, I found this question, and the link from the answer to the IVI-COM programming examples in C# document, but I couldn't apply the code samples (e.g. in section 5.4) because all of the IVI and VISA COM libraries I found (e.g. VisaComLib 5.5) has only interfaces and enums in it, and no concrete class that I can use...

推荐答案

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

If you install the visa driver from either NationalInstruments or Keysight, they do implement classes:

NI的一位:

  1. FormattedIO488Class
  2. ResourceManagerClass
  3. VisaConflictTableManagerClass

要建立连接,您只需要1和2

To get a connection, you only need 1 and 2

一旦尝试嵌入互操作类型,就需要删除'Class'后缀,如

As soon as you try to embed the interoptypes, you need to remove the 'Class' suffix, as described here

这里是Keysight的示例代码片段(应用笔记:5989-6338EN)

Here comes a sample snippet from Keysight (Application Note: 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 { }
}

这篇关于通过USB从C#发送SCPI/GPIB命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆