Chapter 2 111
Programming Examples
RS-232 Programming Examples
// the signal generator.
//
// Connect the computer to the signal generator using the RS-232 serial cable
// and enter the following code into the project .cpp source file.
// The program queries the signal generator ID string and sets and queries the power
// level. Query results are printed to the screen. The default attributes e.g. 9600 baud,
// parity, 8 data bits,1 stop bit are used. These attributes can be changed using VISA
// functions.
//
// IMPORTANT: Set the signal generator BAUD rate to 9600 for this test
//************************************************************************************
#include <visa.h>
#include <stdio.h>
#include "StdAfx.h"
#include <stdlib.h>
#include <conio.h>
#define MAX_COUNT 200
int main (void)
{
ViStatusstatus; // Declares a type ViStatus variable
ViSessiondefaultRM, instr;// Declares type ViSession variables
ViUInt32retCount; // Return count for string I/O
ViCharbuffer[MAX_COUNT];// Buffer for string I/O
status = viOpenDefaultRM(&defaultRM);// Initializes the system
// Open communication with Serial Port 2
status = viOpen(defaultRM, "ASRL2::INSTR", VI_NULL, VI_NULL, &instr);