首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从C#通过USB发送SCPI/GPIB命令

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

Stack Overflow用户
提问于 2017-01-02 15:52:33
回答 2查看 7.8K关注 0票数 1

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

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

顺便说一句,我找到了this questionIVI-COM programming examples in C#文档答案中的链接,但我不能应用代码示例(例如在5.4节中),因为我找到的所有IVI和VisaComLib库(例如VisaComLib 5.5)中只有接口和枚举,没有我可以使用的具体类……

EN

回答 2

Stack Overflow用户

发布于 2017-01-12 00:32:49

如果您从NationalInstruments或Keysight安装visa驱动程序,它们确实实现了类:

来自NI的那个:

  1. FormattedIO488Class
  2. ResourceManagerClass
  3. VisaConflictTableManagerClass

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

一旦您尝试嵌入interoptype,就需要删除'Class‘后缀,如here所述

以下是来自Keysight的示例代码片段(应用笔记: 5989-6338EN)

代码语言:javascript
运行
复制
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
EN

Stack Overflow用户

发布于 2018-03-21 00:01:31

我使用的是National Instruments VISA

将对NationalInstruments.VisaNSNationalInstruments.Common的引用添加到项目中。

创建一个MessageBasedSession,请参见以下代码:

代码语言:javascript
运行
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41423094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档