曾经在如何使用VS2010调用visa进行程控中使用vs2010+visa 实现了程控最简单的Demo,现实现Qt实现visa的Demo
===== 本人诚接各种程控开发项目 =====
软件环境
- 系统: windows 10
- 开发环境: Qt 5.80
- visa库版本: visa 6.0
软件下载
步骤
1. 添加依赖库
在Demo.pro
中添加依赖
win32 {
INCLUDEPATH += "C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Include"
LIBS += "C:\Program Files (x86)\IVI Foundation\VISA\WinNT\lib\msc\visa32.lib"
}
2. Demo
#include <QCoreApplication>
#include <visa.h>
#include <iostream>
using namespace std;
#define MAX_SCPI_LEN 255
#define DEFAULT_TMO 5000
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
/* Visa Session*/
ViStatus nRetStatus;
ViSession rmSession = 0;
ViSession pInstrHandle;
/* Visa communicate buffer */
ViByte wrBuff[MAX_SCPI_LEN];
ViByte rdBuff[MAX_SCPI_LEN];
int retCount = 0;
/* open device and get visa Handle */
nRetStatus = viOpenDefaultRM( &rmSession);
nRetStatus = viOpen( rmSession, "TCPIP0::127.0.0.1::5000::SOCKET", VI_NULL, VI_NULL, &pInstrHandle);
/* set visa Format */
nRetStatus = viSetAttribute( pInstrHandle, VI_ATTR_TMO_VALUE, DEFAULT_TMO);
nRetStatus = viSetAttribute( pInstrHandle, VI_ATTR_SUPPRESS_END_EN, VI_FALSE);
nRetStatus = viSetAttribute( pInstrHandle, VI_ATTR_SEND_END_EN, VI_FALSE);
/* Query device IDN */
nRetStatus = viQueryf( pInstrHandle, "*IDN?\n", "%s", rdBuff);
cout << rdBuff << endl;
/* Close */
viClose( pInstrHandle);
viClose( rmSession);
return a.exec();
}