通过USB从C#发送SCPI/GPIB命令 [英] Sending SCPI/GPIB commands over USB from C#
问题描述
我正在尝试通过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的一位:
- FormattedIO488Class
- ResourceManagerClass
- VisaConflictTableManagerClass
要建立连接,您只需要1和2
To get a connection, you only need 1 and 2
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屋!