泰克-吉时利-2200-远程操作

泰克-吉时利-2200-远程操作

前言

以下是调试泰克吉时利2200直流电源远程操作的调试经验,有需要的可以参考。

一、VISA驱动安装

Visa驱动在NI官网下载,如下地址:
[https://www.ni.com/zh-cn/support/downloads/drivers/download.ni-visa.html#346210]

二、电流计设置

Shift–>Menu–>Communication–>USBTMC

三、Visa协议头文件,静态库

visa.h,visatype.h
64位Windows:
C:\Program Files (x86)\IVI Foundation\VISA\WinNT\include
C:\Program Files\IVI Foundation\VISA\Win64\include

32位Windows:
C:\Program Files\IVI Foundation\VISA\WinNT\include

visa32/64.lib
C:\Program Files\IVI Foundation\VISA\Win64\Lib_x64\msc

链接器–>常规–>附加目录库–>添加静态库地址(C:\Program Files\IVI Foundation\VISA\Win64\Lib_x64\msc)
链接器–>输入–>附加依赖库–>添加静态库名(visa64.lib/visa64.lib)

四、实现代码

//代码截取吉时利2200 spec
#define _CRT_SECURE_NO_WARNINGS
#include <C:\\Program Files\\IVI Foundation\\VISA\\Win64\\Include\\visa.h>
#include <C:\\Program Files\\IVI Foundation\\VISA\\Win64\\Include\\visatype.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <conio.h>
#include <stdlib.h>

ViSession defaultRM; //Resource manager id
ViSession PWS2200; //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()
{
	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(PWS2200, "VOLT %f\n", voltage); //set the output voltage
	CheckError("Unable to set voltage");
	ErrorStatus = viPrintf(PWS2200, "CURRENT %f\n", current);
	//set the output current
	CheckError("Unable to set current");
	ErrorStatus = viPrintf(PWS2200, "MEASURE:VOLTAGE?\n");
	//measure the output voltage
	CheckError("Unable to write the device");
	ErrorStatus = viScanf(PWS2200, "%f", &voltage); //retrieve reading
	CheckError("Unable to read voltage");
	ErrorStatus = viPrintf(PWS2200, "MEASURE:CURRENT?\n");
	//measure the output current
	CheckError("Unable to write the device");
	ErrorStatus = viScanf(PWS2200, "%f", &current); //retrieve reading
	CheckError("Unable to read current");
	printf("Measured voltage(V) & current(A): %f,%f \n",voltage, current);
	SendSCPI("OUTPUT 0"); //turn output off
	ClosePort();
	while (1);
	//return 0;
}
void OpenPort()
{
	//Open communication session with the power supply, and put the power supply in remote
	ErrorStatus = viOpenDefaultRM(&defaultRM);
	ErrorStatus = viOpen(defaultRM,"USB0::0x05E6::0x2200::9203766::INSTR", 0, 0, &PWS2200);
	CheckError("Unable to open the port");
	SendSCPI("SYSTEM:REMOTE");
}
void SendSCPI(char* pString)
{
	char* pdest;
	strcpy(commandString, pString);
	strcat(commandString, "\n");
	ErrorStatus = viPrintf(PWS2200, commandString);
	CheckError("Can't Write to Power Supply");
	pdest = strchr(commandString, '?'); //Search for query command
		if (pdest != NULL)
		{
			ErrorStatus = viBufRead(PWS2200, (ViBuf)ReadBuffer,sizeof(ReadBuffer), VI_NULL);
			CheckError("Can't read from driver");
			strcpy(pString, ReadBuffer);
		}
}
void ClosePort()
{
	viClose(PWS2200);
	viClose(defaultRM);
}
void CheckError(char* pMessage)
{
	if (ErrorStatus != VI_SUCCESS)
	{
		printf("\n %s", pMessage);
		ClosePort();
		exit(0);
	}
}
void delay(clock_t wait)
{
	clock_t goal;
	goal = wait + clock();
	while (goal > clock());
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值