Application Programs 107
/* APPLICATION #3: CONTROLLING VOLTAGE RAMP UP AT TURN ON,
FOR MICROSOFT C AND THE NATIONAL INSTRUMENTS GPIB-PC INTERFACE CARD
PROGRAM: N3.C
Configure the GPIB.COM handler for the following: EOl enabled for both read and write
#include <stdio.h> Disable auto serial poll */
#include <stdlib.h>
#include <string.h>
#include "decl.h”
#define ERR (1<<15) /* Error detected as bit 15 of ibsta. */
#define NUM_PTS 20 /* The number of points in the voltage List. */
#define MAX_LEN 255 /* Maximum length of a string = 255 characters.*/
#define SMALL_STRING 15 /* When you need a small string of 15 characters. */
#define WTG 32 /* Waiting for Trigger (WTG) = bit 5 = value 32 */
int slot0; /* Device number of module in slot 0. Slot0 is configured in GPIB.Com as
GPIB address 5, secondary address 96. */
main( )
{char *cmd; /* Used to hold command strings sent to the module. */
char cmd_buff[MAX_LEN]; /* Used to hold command strings during string manipulations. */
char vpoint[SMALL_STRING]; /* Used to hold the string equivalent of one voltage ramp step. */
char vlist[MAX_LEN]; /* Used to hold the entire voltage List command header and points. */
char condition_data[SMALL_STRING]; /* Reserve space for reading back status conditions. */
int i; /* Loop counter. */
float vstart = 2.0; /* Start voltage for the ramp. */
float vstop = 10.0; /* Stop voltage for the ramp. */
float ramptime = 0.5; /* Transition time for the ramp. */
float dwell; /* Dwell time for each ramp step. */
dwell = ramptime / 19.0; /* Since the output stays at the last voltage point after its
dwell expires, the dwell time of the last point is not part of the
transition time. Therefore, divide the total time by 19 points, not 20.
You want the same dwell time for every point in the List, so only
download 1 dwell time. */
if ((slot0 = ibfind(“SLOT0”)) < 0) /* Assign unique identifier to the device slot0 and store in */
finderr( ); /* variable slot0. Error = negative value returned. */
cmd = "*RST;*CLS;STATUS:PRESET”; /* Reset and clear module. */
ibwrt(slot0, cmd, strlen(cmd));
if (ibsta & ERR)
error(cmd);
sprintf(cmd_buff , "VOLT %f”, vstart); /* Start ramp at vstart. Use number to string conversion to send */
/* real numbers over the bus as part of the command string. */
ibwrt(slot0, cmd_buff, strlen(cmd_buff));
if (ibsta & ERR)
error(cmd_buff);
cmd = "CURR .1”;
ibwrt(slot0, cmd, strlen(cmd));
if (ibsta & ERR)
error(cmd);
cmd = "OUTPUT ON"; /* Enable output */
ibwrt(slot0, cmd, strlen(cmd));
if (ibsta & ERR)
error(cmd);