Series 2200 Programmable DC Power Supplies Reference Manual
Section 4: Command reference
2200S-901-01 Rev. C / March 2016
4-41
Example 1
This example is written in the C programming language, the Virtual Instrument Software Architecture
(VISA) standard can be used. It demonstrates basic communication with the power supply and error
checking. The program establishes communication with the power supply, and puts it into remote
mode. It then initializes the voltage and current and turns the output on. It sends new values for the
voltage and current, and reads back the actual meter values before turning off the power supply
output and closing communications.
// pws_visa.cpp
//
#include "stdafx.h"
#include <visa.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <conio.h>
#include <stdlib.h>
ViSession defaultRM; //Resource manager id
ViSession PWS4000; //Identifies the power supply
long ErrorStatus;
char commandString[256];
char ReadBuffer[256];
void OpenPort();
void SendSCPI(char* pString);
void CheckError(char* pMessage);
void delay(clock_t wait);
void ClosePort();
int main(int argc, _TCHAR* argv[])
{
double voltage;
char Buffer[256];
double current;
OpenPort();
//Query the power supply id, read response and print it
sprintf(Buffer, "*IDN?");
SendSCPI(Buffer);
printf("Instrument identification string:%s \n", Buffer);
SendSCPI("*RST"); //reset the power supply
SendSCPI("CURRENT 0.1A"); //set the current to 0.1A
SendSCPI("VOLTAGE 3V"); //set the voltage to 3V
SendSCPI("OUTPUT 1"); // turn output on
voltage=5.0;
current=0.2;
printf("Setting voltage(V) & current(A): %f,%f \n",
voltage, current);
ErrorStatus = viPrintf(PWS4000,"VOLT %f\n",voltage); //set
the output voltage
CheckError("Unable to set voltage");
ErrorStatus = viPrintf(PWS4000,"CURRENT %f\n",current);
//set the output current
CheckError("Unable to set current");
ErrorStatus = viPrintf(PWS4000,"MEASURE:VOLTAGE?\n");
//measure the output voltage
CheckError("Unable to write the device");
ErrorStatus = viScanf(PWS4000,"%f",&voltage); //retrieve