首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >GPIB-VC编程

GPIB-VC编程

作者头像
全栈程序员站长
发布2022-09-13 15:47:19
发布2022-09-13 15:47:19
1K0
举报

大家好,又见面了,我是你们的朋友全栈君。Compiling and Linking VISA Programs (C/C++) This section provides a summary of important compiler- specific considerations when developing Win32 applications. 1 . Linking to VISA Libraries Your application must link to the VISA import library as follows, assuming default installation directories and Microsoft compilers: C:\Program Files\VISA\winnt\lib\msc\visa32.lib The following steps will help you do this. This information is specific to your development

environment. Microsoft Visual C++ Version 6.0 Development Environment 1 Use the File menu to create a new project or open an existing project. 2 Select Project > Settings from the menu and click the C/C++ tab. 3 Select Code Generation from the Category list box and select Multi-Threaded using DLL from the Use Run-Time Libraries list box. (VISA requires these definitions for Win32.) Click OK to close the dialog box. 4 Select Project > Settings from the menu. Click the Link tab and add visa32.lib to the Object/Library Modules list box. Optionally, you may add the library directly to your project file. Click OK to close the dialog box. 5 You may want to add the include files and library files search paths. They are set as follows: • Select Tools > Options from the menu. • Click the Directories tab to set the include file path. • Select Include Files from the Show Directories For list box. • Click at the bottom of the list box and type: C:\Program Files\VISA\winnt\include (This assumes that you used the default installation location for VISA.) • Select Library Files from the Show Directories For list box. • Click at the bottom of the list box and type: C:\Program Files\VISA\winnt\lib\msc (This assumes that you used the default installation location for VISA.) 6 Add or create your C or C++ source files. For example, to build the sample described below, select Project > Add to Project > Files… and type or browse to C:\Program Files\Agilent\IO Libraries Suite\ ProgrammingSamples\C\VISA\idn.c. 7 Click Build > Rebuild All to build the VISA program.

示例:电源型号:Agilent GPIB线 开发环境为VS2010

1.首先安装GPIB驱动,驱动安装文件比较大,请自行下载安装,我用的NI驱动

2.编写一个Win32程序,实现打开和关闭电源的功能。 主要代码如下:

代码语言:javascript
复制
//包含VISA头文件和库文件
#include "WinNT//include//visa.h"                               
#pragma comment(lib, "WinNT//lib//msc//visa32.lib")

电源初始化函数

代码语言:javascript
复制
BOOL CXXXDlg::InitPower()
{
	
	char chStatusDesc[_MAX_DIR] = {0};
	int retCnt=0;	
	char instrDesc[100]={0};	
	ViFindList find_list;	
	float voltSetting, currSetting;
	voltSetting = atof(ini_powervolt);
	currSetting = atof(ini_powercurrent);
	VISAstatus=viOpenDefaultRM(&defrm);
	if (VISAstatus != VI_SUCCESS)
	{
		return FALSE;
	}
	VISAstatus = viFindRsrc(defrm,"GPIB?*INSTR",&find_list,(ViPUInt32)&retCnt, instrDesc);
	
	VISAstatus=viOpen(defrm,instrDesc, VI_NULL, VI_NULL, &session);


	if (VISAstatus!=VI_SUCCESS)
	{
		return FALSE;
	}
	//Set voltage
	viPrintf(session,"VOLT %f \n",voltSetting);


	//Set current level
	viPrintf(session,"CURR %f \n",currSetting);
	return TRUE;
}

打开电源

代码语言:javascript
复制
void CXXXDlg::OnBnClickedBtnPowerOn()
{
	if (!InitPower())
	{
		AfxMessageBox("Init Power Fail,Please Check the GPIB Connected!");
		return;
	}


	viPrintf(session,"OUTP ON \n");
}

关闭电源

代码语言:javascript
复制
void CXXXDlg::OnBnClickedBtnPoweroff()
{
	if (!InitPower())
	{
		AfxMessageBox("Init Power Fail,Please Check the GPIB Connected!");
		return;
	}


	viPrintf(session,"OUTP OFF \n");
}

上面的示例只是简单的展示了开启和关闭电源的基本功能,实际开始时需要根据具体需求来扩展。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/148878.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档