Continuous Measurements (Ex. #5)
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <float.h>
#include <math.h>
#include <assert.h>
#include "visa.h"
// Write a null terminated string (ie, no binary data) to the
// instrument.
unsigned WriteDevice(ViSession Instr, const char *Str, int Line)
{
ViStatus Status;
int Length;
ViUInt32 RetLength;
assert(Str != NULL);
Length = strlen(Str);
Status = viWrite(Instr, (unsigned char *)Str, Length,
&RetLength);
if (Status != VI_SUCCESS) {
fprintf(stderr, "Write error: %x at line %d\n",
(unsigned)Status, Line);
return((unsigned)Status);
}
assert(Length == (int)RetLength);
return((unsigned)Status);
}
// Read data (may be binary) into the buffer.
unsigned ReadDevice(ViSession Instr, char *Buf, int BufLength,
ViUInt32 *pActualLength, int Line)
{
ViStatus Status;
assert(Buf != NULL);
assert(BufLength > 0);
assert(pActualLength != NULL);
Status = viRead(Instr, (unsigned char *)Buf, BufLength,
pActualLength);
if (Status != VI_SUCCESS) {
fprintf(stderr, "Read error: %x at line %d\n",
(unsigned)Status, Line);
}
Programming Examples
Continuous Measurements (Ex. #5) 4-13