2017-01-02 598 views
0

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

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

BTW,我发现this question,从答案IVI-COM programming examples in C#文件的链接,但我不能申请代码的样本(如第5.4节),因为所有的IVI和VISA COM库,我发现(如VisaComLib 5.5),只有接口,在它枚举,并没有我可以使用混凝土类...

回答

1

如果安装无论从美国国家仪器公司或Keysight签证司机,他们实现类:

来自NI的一个:

  1. For: mattedIO488Class
  2. ResourceManagerClass
  3. VisaConflictTableManagerClass

为了得到一个连接,你只需要1和2

只要你尝试嵌入interoptypes,你需要删除“类后缀,如所描述的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 { } 
}