Example Program
/* status2.c *
*The following program provides an interactive command line interface
*to send SCPI commands to SCPI compatible instruments.
*This utilizes the MAV bit of the Status Byte in order to determine if
*the instrument is returning any output. It also automatically
*displays any error conditions that may result by querying the Standard
*event status register. */
#include <sicl.h> #include <stdio.h>
/* Theses are Masks for the Status Byte */ |
|
| ||
/* all bits start at | bit 0 | */ |
|
|
#define MAV_MASK 0x10 |
| /* MAV - bit 4 | */ |
|
#define ESR_MASK 0x20 |
| /* ESR summary | - bit 5 | */ |
/* These are Masks for the | Standard Event | Status Register */ | ||
/* all bits start at | bit 0 | */ |
|
|
#define QRY_ERR_MASK | 0x04 | /* query error | - bit 2 | */ |
#define DEV_ERR_MASK | 0x08 | /* device dependent error - bit 3 */ | ||
#define EXE_ERR_MASK | 0x10 | /* execution error - bit 4 */ | ||
#define CMD_ERR_MASK | 0x20 | /* command error - bit | 5 */ |
/* This is the SRQ handler to check for Message Available (MAV)
*or any error conditions */ void srq_hdlr( INST id)
{
unsigned char stb; char buf[255]; int esr;
int errnum;
char errmsg[100];
/* read the status byte to determine what caused the SRQ.
*Note: use ireadstb instead of *STB? because we want to
*clear RQS instead of reading the MSS bit in the status byte. */ ireadstb(id, &stb);
/* check if MAV caused the SRQ */ if( MAV_MASK == (stb & MAV_MASK))
{
/* message is available so read in the result */ iscanf( id, "%t", buf);
printf("%s", buf);
}
else /* check if Standard Event Status */ if( ESR_MASK == (stb & ESR_MASK))
{
/* read the standard event register to determine
*what caused the ESR summary bit to be set. This
*is necessary in order to get future SRQ’s from
*the Standard Event status group. */
ipromptf(id, "*ESR?\n", "%d\n", &esr);
/* check if an error caused the summary bit to get set */ if( (CMD_ERR_MASK == (esr & CMD_ERR_MASK ))
(EXE_ERR_MASK == (esr & EXE_ERR_MASK )) (DEV_ERR_MASK == (esr & DEV_ERR_MASK ))
Chapter 2 | Programming the Status System 19 |