Instruction manual
Chapter 3 Programming Your Counter for Remote Operation
Programming Examples
3-58 Programming Guide
3
Making a Frequency Measurement (C)
/* This program configures the instrument to make 10 frequency measurements
on channel 1 followed by 10 frequency measurements on channel 2 and 10
power measurements.
The results are displayed on the computer monitor.
The program comments discuss the meaning of each command.
ASCII result format is used to preserve resolution. */
#include <stdio.h
#include <string.h
#include "CGPIB.H"
#include "CFUNC.H"
void sendhp(char *); /* function to send command to instrument */
/* global data */
long ctr=703; /* instrument is at address 03. GPIB is at select code 7 */
int error;
void main()
{
long isc=7; /* Select code 7 */
int state=1; /* Used in IOEOI */
int i; /* Used for loop instrument */
int samples=10; /* Number of measurements to take */
int length=23; /* Max number of bytes per measurements */
char freq[23]; /* Array to hold frequency string */
IORESET(isc); /* Clear the GPIB interface */
sendhp("*RST"); /* Reset the instrument */
sendhp("*CLS"); /* Clear event registers and error queue */
sendhp("*SRE 0"); /* Clear service request enable register */
sendhp("*ESE 0"); /* Clear event status enable register */
sendhp(":STAT:PRES"); /* Preset enable registers and transition
filters for operation and questionable
status structures */
IOEOI(isc,state); /* Enable use of EOI */
/* Function to send command to Agilent 5315xA */
void sendhp(gpib_cmd)
char *gpib_cmd;
{
char hpcmd[80]; /* Variables used by function */
int length;
strcpy(hpcmd, gpib_cmd);
length=strlen(hpcmd);
error=IOOUTPUTS(ctr, hpcmd, length); /* Send command to Agilent 5314xA */
if (error!=0)
printf("Error during GPIB: %d Command %s\n",error,hpcmd);
}
Sendhp( ":CONF:FREQ DEFAULT,DEFAULT,(@1)"); /* Set to Band 1 */
Sendhp( "INIT:IMM"); /* Trigger new measurement */
Sendhp( "READ?") /* Get measurement */
IOENTERS(ctr,freq,&length); /* Fetch the data */
length=strlen(freq);
freq[length-1]=’\0’ ;
printf ("Frequency in Band 1 = %s Hz\n",freq);
printf("Press a key to continue\n");
getch();