C # Visual Studio GPIB Commands

What commands do you use to communicate with the GPIB tool in C #, visual studio? I need to be able to write commands to the instrument and read the result.

+6
source share
5 answers

I am using Agilent IO Library Suite .

Here is a guide to using it in C #: Examples of I / O programming in C #

However, in my company, we had problems with the stability of the VISA-COM implementation, so we wrote our own shell for visa32.dll (also included in the IO library) using P / Invoke.

(Disclosure: I work for a company that heavily uses GPIB tools)

+4
source

National Instruments VISA NI 488.2.

, VisaNS.NET API NI-VISA, . :

enter image description here

NationalInstruments.VisaNS NationalInstruments.Common .

MessageBasedSession, . :

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

MessageBasedSession GPIB, Ethernet USB.

Ivi.Visa NationalInstruments.VisaNS. , Ivi.Visa .

:

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

Ivi.Visa , :

+1

LangInt. GPIB. ( , "dev" );

dev.ibwrt(deviceHandle, "*IDN?", "*IDN?".Length);

dev.ibrd(deviceHandle, out Value, Arraysize);

. , , , .

SCPI; .

deviceHandle = ibdev(GPIBINDEX, GPIBADDRESS, SECONDARYADDRESS, TIMEOUT, EOTMODE, EOSMODE);

. GPIB .

, , NationalInstruments.NI4882 LangInt.dll .

0

NI Visa. Vb #, Visa32.bas Visa32.cs

int DefaultSessionId= 0;
int SessionId= 0;
int LastStatus = 0;
string Address = "GPIB0::6" ; //any address

//Session Open
LastStatus = visa32.viOpenDefaultRM(out DefaultSessionId);

//Connection Open
LastStatus = visa32.viOpen(DefaultSessionId, Address + "::INSTR", 0, 0, out sessionId);
LastStatus = visa32.viSetAttribute(SessionId, visa32.VI_ATTR_TERMCHAR, 13);// Set the termination character to carriage return (i.e., 13);
LastStatus = visa32.viSetAttribute(SessionId, visa32.VI_ATTR_TERMCHAR_EN, 1);// Set the flag to terminate when receiving a termination character
LastStatus = visa32.viSetAttribute(SessionId, visa32.VI_ATTR_TMO_VALUE, 2000);// Set timeout in milliseconds; set the timeout for your requirements

//Communication
LastStatus = visa32.viPrintf(SessionId, command + "\n");//device specific commands to write
StringBuilder message = new StringBuilder(2048);
LastStatus = visa32.viScanf(SessionId, "%2048t", message);//Readback

//Session and Connection Close
visa32.viClose(SessionId);
visa32.viClose(DefaultSessionId);

0

.

. Microsoft COM-.

-1

All Articles