我正在尝试通过SCPI与来自C#的一些测试设备通信。我设法使用this code example与一台通过TCP/IP连接的设备通信。
然而,我的其他设备都是通过USB连接的,我还没有找到如何通过USB与它们通信。
顺便说一句,我找到了this question和IVI-COM programming examples in C#文档答案中的链接,但我不能应用代码示例(例如在5.4节中),因为我找到的所有IVI和VisaComLib库(例如VisaComLib 5.5)中只有接口和枚举,没有我可以使用的具体类……
发布于 2017-01-12 00:32:49
如果您从NationalInstruments或Keysight安装visa驱动程序,它们确实实现了类:
来自NI的那个:
要获得连接,您只需要1和2
一旦您尝试嵌入interoptype,就需要删除'Class‘后缀,如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 { }
}
发布于 2018-03-21 00:01:31
我使用的是National Instruments VISA。
将对NationalInstruments.VisaNS
和NationalInstruments.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/questions/41423094
复制相似问题