What commands do you use to talk to a GPIB instrument in C#, visual studio? I need to be able to write commands to the instrument and read the output.
I'm using National Instruments VISA and NI 488.2.
First make sure that you checked the VisaNS.NET API
in the NI-VISA Setup, see the following figure:
Add a reference to NationalInstruments.VisaNS
and NationalInstruments.Common
to your project.
Create a MessageBasedSession
, see the following code:
string resourceName = "GPIB0::20::INSTR"; // GPIB adapter 0, Instrument address 20
var visa = new NationalInstruments.VisaNS.MessageBasedSession(resourceName);
visa.Write("*IDN?"); // write to instrument
string res = visa.ReadString(); // read from instrument
A MessageBasedSession
can be used to communicate with your instrument over GPIB, Ethernet or USB.
Update
Ivi.Visa
superseded NationalInstruments.VisaNS
. So you should add a reference only to Ivi.Visa
to your project.
The example would look like that:
string resourceName = "GPIB0::20::INSTR"; // GPIB adapter 0, Instrument address 20
var visa = GlobalResourceManager.Open(resourceName) as IMessageBasedSession;
visa.RawIO.Write("*IDN?\n"); // write to instrument
string res = visa.RawIO.ReadString(); // read from instrument
The benefit of using Ivi.Visa
is that it works with one of the following libraries: