2-9
Sample Programs
C Programming Examples
Service Request Example
The sample C program, gen_srq.c, shows how to initialize the interface and instrument and
generate a service request. The init_IO() function initializes the instrument and interface and
sets up and generates a service request. In the initialize function, the *RST command is a
common command that resets the instrument to a known default configuration. Using this
command ensures that the instrument is in a known state before you configure it. *RST
ensures very consistent and repeatable results. Without *RST, a program may run one time,
but it may give different results in following runs if the instrument is configured differently.
*RST defaults the instrument to a set configuration so that the program can proceed from the
same state each time. The *CLS command clears the status registers and the output queue.
AUToscale finds and displays all signals that are attached to the instrument. You should pro-
gram the instrument's time base, channel, and trigger for the specific measurement to be
made, as you would do from the front panel, and use whatever other commands are needed
to configure the instrument for the desired measurement.
File: gen_srq.c
/* gen_srq.c */
/*
* This example programs initializes the Agilent 86100 scope, runs an
* autoscale, then generates and responds to a Service Request from the
* scope. The program assumes an Agilent 86100 at address 7, an interface card
* at interface select code 7, and a signal source attached to channel 1.
*/
#include <stdio.h> /* location of: printf ( ) */
#include "hpibdecl.h"
void initialize ( );
void setup_SRQ ( );
void create_SRQ ( );
void main ( void )
{
init_IO ( ); /* initialize interface and device sessions */
initialize ( ); /* initialize the scope and interface */
setup_SRQ ( ); /* enable SRQs on scope and set up SRQ handler */
create_SRQ ( ); /* generate SRQ */
close_IO ( ); /* close interface and device sessions */
} /* end main ( ) */
/*
* Function name: initialize
* Parameters: none
* Return value: none
* Description: This routine initializes the analyzer for proper acquisition of data.
* The instrument is reset to a known state and the interface is cleared.
* System headers are turned off to allow faster throughput and immediate access
* to the data values requested by queries. The analyzer performs an autoscale to acquire waveform data.