
3020-XX-UM
ProDAQ 3020 USB2.0 VXIbus Slot-0 Interface User Manual
Page 46 of 60
Copyright, © 2003 Bustec Production Ltd.
4.2 Reading and Writing Messages to/from a GPIB Device
The following example shows how to connect to a GPIB device and how to write and read
messages to/from the device:
Figure 37
– Reading and writing messages to/from a GPIB device
As explained in 3.1 - Connecting to a Device, the first step in a program using the VISA
library is always to open a session to the default resource manager (
). It provides
connectivity to all VISA resources registered with it and gives applications control and
access to individual resources.
The next step is to open a session to the instrument (
) using a resource name as
explained above. Once the session is established, the standard functions viPrintf (
) and
viScanf (
) can be used to write messages to the device and read the response.
As a last step the sessions to the device and to the default resource manager need to be
closed (
).
#include <visa.h>
main (int argc, char **argv)
{
ViStatus status;
ViSession rm_session;
ViSession instr_session;
ViChar descr[256];
/* open a session to the resource manager */
if ((status = viOpenDefaultRM (&rm_session)) != VI_SUCCESS)
{
/* error handling as shown in the previous examples !*/
}
/* open a session to the instrument */
if ((status = viOpen (rm_session, “VXI0::2::INSTR”,
VI_NULL, VI_NULL, &instr_session)) != VI_SUCCESS)
{
/* error handling as shown in the previous examples !*/
}
/* reset the device */
if ((status = viPrintf (vi, “*RST\n”)) != VI_SUCCESS)
{
/* error handling as shown in the previous examples !*/
}
/* ask the device for its identification */
if ((status = viPrintf (vi, “*IDN?\n”)) != VI_SUCCESS)
{
/* error handling as shown in the previous examples !*/
}
/* read the identification sent back */
if ((status = viScanf (vi, “%256t”, descr)) != VI_SUCCESS)
{
/* error handling as shown in the previous examples !*/
}
printf (“Device Identification: %s\n”, descr);
/* close the sessions to the instrument and the resource manager */
viClose (instr_session);
viClose (rm_session);
}
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com