1412
Keysight InfiniiVision M9241/42/43A PXIe Oscilloscopes SCPI Programmer's Guide
40
Programming Examples
/*
* Keysight VISA Example in C
* ------------------------------------------------------------------
* This program illustrates a few commonly-used programming
* features of your Keysight oscilloscope.
*/
#include <stdio.h>
/* For printf(). */
#include <string.h>
/* For strcpy(), strcat(). */
#include <time.h>
/* For clock(). */
#include <visa.h>
/* Keysight VISA routines. */
#define VISA_ADDRESS "TCPIP0::10.112.94.136::hislip9-0.0::INSTR"
#define IEEEBLOCK_SPACE 5000000
/* Function prototypes */
void initialize(void);
/* Initialize to known state. */
void capture(void);
/* Capture the waveform. */
void analyze(void);
/* Analyze the captured waveform. */
void do_command(char *command);
/* Send command. */
int do_command_ieeeblock(char *command); /* Command w/IEEE block. */
void do_query_string(char *query);
/* Query for string. */
void do_query_number(char *query);
/* Query for number. */
void do_query_numbers(char *query);
/* Query for numbers. */
int do_query_ieeeblock(char *query);
/* Query for IEEE block. */
void check_instrument_errors();
/* Check for inst errors. */
void error_handler();
/* VISA error handler. */
/* Global variables */
ViSession defaultRM, vi;
/* Device session ID. */
ViStatus err;
/* VISA function return value. */
char str_result[256] = {0};
/* Result from do_query_string(). */
double num_result;
/* Result from do_query_number(). */
unsigned char ieeeblock_data[IEEEBLOCK_SPACE];
/* Result from
do_query_ieeeblock(). */
double dbl_results[10];
/* Result from do_query_numbers(). */
/* Main Program
* --------------------------------------------------------------- */
void main(void)
{
/* Open the default resource manager session. */
err = viOpenDefaultRM(&defaultRM);
if (err != VI_SUCCESS) error_handler();
/* Open the session using the oscilloscope's VISA address. */
err = viOpen(defaultRM, VISA_ADDRESS, VI_NULL, VI_NULL, &vi);
if (err != VI_SUCCESS) error_handler();
/* Set the I/O timeout to fifteen seconds. */
err = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 15000);
if (err != VI_SUCCESS) error_handler();
/* Initialize - start from a known state. */
initialize();