GPIB-VC编程

桃扇骨 2022-07-15 01:45 235阅读 0赞

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程序,实现打开和关闭电源的功能。
主要代码如下:

  1. //包含VISA头文件和库文件
  2. #include "WinNT//include//visa.h"
  3. #pragma comment(lib, "WinNT//lib//msc//visa32.lib")

电源初始化函数

  1. BOOL CXXXDlg::InitPower()
  2. {
  3. char chStatusDesc[_MAX_DIR] = {0};
  4. int retCnt=0;
  5. char instrDesc[100]={0};
  6. ViFindList find_list;
  7. float voltSetting, currSetting;
  8. voltSetting = atof(ini_powervolt);
  9. currSetting = atof(ini_powercurrent);
  10. VISAstatus=viOpenDefaultRM(&defrm);
  11. if (VISAstatus != VI_SUCCESS)
  12. {
  13. return FALSE;
  14. }
  15. VISAstatus = viFindRsrc(defrm,"GPIB?*INSTR",&find_list,(ViPUInt32)&retCnt, instrDesc);
  16. VISAstatus=viOpen(defrm,instrDesc, VI_NULL, VI_NULL, &session);
  17. if (VISAstatus!=VI_SUCCESS)
  18. {
  19. return FALSE;
  20. }
  21. //Set voltage
  22. viPrintf(session,"VOLT %f \n",voltSetting);
  23. //Set current level
  24. viPrintf(session,"CURR %f \n",currSetting);
  25. return TRUE;
  26. }

打开电源

  1. void CXXXDlg::OnBnClickedBtnPowerOn()
  2. {
  3. if (!InitPower())
  4. {
  5. AfxMessageBox("Init Power Fail,Please Check the GPIB Connected!");
  6. return;
  7. }
  8. viPrintf(session,"OUTP ON \n");
  9. }

关闭电源

  1. void CXXXDlg::OnBnClickedBtnPoweroff()
  2. {
  3. if (!InitPower())
  4. {
  5. AfxMessageBox("Init Power Fail,Please Check the GPIB Connected!");
  6. return;
  7. }
  8. viPrintf(session,"OUTP OFF \n");
  9. }

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

发表评论

表情:
评论列表 (有 0 条评论,235人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Socket编程——UDP编程

    UDP协议(用户数据协议) 是无连接、不可靠的、无序的 特点在于速度比较快 UDP协议以数据报作为数据传输的载体 进行数据传输时,首先需要将要传输的数据定义成数据报(

    相关 编程编程思想

    \[TIP\]什么是编程思想?答案可能很会复杂,但也可以很简单。一句话来讲就是,用计算机来解决人们实际问题的思维方式,即编程思想。    ![2011121411044659

    相关 编程编程语言

    转自计蒜客 编程就是人类让计算机为解决某个问题而使用某种程序设计语言编写程序代码,并最终得到结果的过程。为了使计算机能够理解人的意图,人类就必须要将解决的问题的