【发布时间】:2015-11-05 13:57:08
【问题描述】:
我正在尝试使用 Ivi.Visa.Interop .dll 通过 USB 与 Voltech PM1000+ 功率计进行通信。我对 C# 比较陌生,不知道从哪里开始。我正在使用 Visual Studio 2015 社区。我已经与使用 GPIB 的不同工具进行了交谈,这里是代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Ivi.Visa.Interop;
namespace commOverIP
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void InitiateIOBtn_Click(object sender, EventArgs e)
{
///testing out excel
InitiateIOBtn.Text = "Initializing";
try
{
// resource manager and message-based session manager
Ivi.Visa.Interop.ResourceManager mngr = new Ivi.Visa.Interop.ResourceManager();
// GPIB address
string srcAddress = "GPIB::27::INSTR"; // GPIB address of data acquisition
//setting up communication
Ivi.Visa.Interop.FormattedIO488 instrument = new Ivi.Visa.Interop.FormattedIO488();
Ivi.Visa.Interop.IMessage Imsg = (mngr.Open(srcAddress, Ivi.Visa.Interop.AccessMode.NO_LOCK, 1000, "") as IMessage);
instrument.IO = Imsg;
instrument.IO.Clear();//clear io buffer
instrument.WriteString("*RST", true);//send RST? command to instrument
instrument.WriteString("*IDN?", true);//send IDN? command to instrument
returnOfCommand.Text = instrument.ReadString();//read IDN? result
//close communication
instrument.IO.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(instrument);
System.Runtime.InteropServices.Marshal.ReleaseComObject(mngr);
InitiateIOBtn.Text = "Initialize I/O";
//*/
}
catch(Exception exp)
{
MessageBox.Show(exp.Message);
}
InitiateIOBtn.Text = "Initialize I/O";
}
}
}
这工作正常,但 USB 似乎是一个不同的野兽。我发现的唯一真正的线索是在 .dll 中: IUsb.Init(字符串,Ivi.Visa.Interop.AccessMode,int,字符串) 我尝试实现这一点,但我真的不知道从哪里开始。
谁能给我一个如何查询“*IDN”的示例?命令会很棒。或者,即使有比通过 Ivi.Visa.Interop dll 更好的方法。
提前致谢
【问题讨论】:
-
看到这对于我们 99.9% 没有的设备来说是非常具体的,你可能在这里得不到很多帮助。我建议联系发布 API 的人并直接寻求帮助。
-
我不是在寻找特定的代码集。我正在寻找如何打开、写入、读取和关闭 USB 端口。 “*国际化域名?”只是您发送到仪器以读取仪器身份的标准命令。我不是在寻找确切的命令,我在寻找方向。
标签: c# initialization usb communication