Appendix B: Programming Examples
Example 1
This example is written in the C programming language; TekVISA or NIVISA
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
PWS4205, PWS4305, PWS4323, PWS4602, and PWS4721 Power Supply Programmer Manual
B-1
Summary of Contents for PWS4205
Page 2: ......
Page 8: ...Preface iv PWS4205 PWS4305 PWS4323 PWS4602 and PWS4721 Power Supply Programmer Manual...
Page 9: ...Getting Started...
Page 10: ......
Page 61: ...Status and Events...
Page 62: ......
Page 75: ...Appendices...
Page 76: ......