VC VISA

常用的GPIB仪表控制模块,整理好了放在下面,用的自取,我只是新手,肯定能用,但是不完善,然后顺便说下,还没写完。

GPIB.h

#pragma once
#include "visatype.h"
#include "visa.h"
#include 
#include "vector"
#include "map"
#include "stdlib.h"
#pragma comment (lib,"C:\\Program Files\\IVI Foundation\\VISA\\Win64\\Lib_x64\\msc\\visa32.lib")
#pragma comment (lib,"C:\\Program Files\\IVI Foundation\\VISA\\Win64\\Lib_x64\\msc\\visa64.lib")
#pragma comment (lib,"C:\\Program Files\\IVI Foundation\\VISA\\Win64\\Lib_x64\\msc\\nivisa64.lib")

class GPIB
{
public:

	GPIB();
	~GPIB();
	//    std::vector listResource();
	int Open(char * lpsession);

	int Write(char * command);
	int Read(ViBuf retVal, unsigned int nBufCount);
	int Query(char * command, ViBuf retVal, unsigned int nBufCount);
	int Close();

private:
	int OpenDM();
	static bool DMOpend;
	ViSession m_viSession;
	ViStatus  m_ViStatus;
	ViSession m_vistr;
};

 

GPIB.cpp

//
// Created by Adair on 2018/6/15.
//
#include "GPIB.h"
#include "iostream"
GPIB::GPIB() :m_viSession(0), m_ViStatus(0), m_vistr(0) {


}

GPIB::~GPIB() {

}

int GPIB::OpenDM() {
	return (VI_SUCCESS == viOpenDefaultRM(&m_viSession));
}
// I found these things will cuz issues, then I toggled these line for further use
// std::vector GPIB::listResource() {
// 	std::vector retVal;
// 	return retVal;
// }

int GPIB::Open(char *lpsession) {
	this->OpenDM();
	return (VI_SUCCESS == viOpen(m_viSession, lpsession, VI_NULL, VI_NULL, &m_vistr));
}

int GPIB::Write(char *command) {
	ViUInt32 iretcount = 0;
	char pBuffer[16640] = { 0 };
	strcpy_s(pBuffer, command);
	if (pBuffer[strlen(pBuffer)] != '\n') {
		strcat_s(pBuffer, "\n");
	}
	return (VI_SUCCESS == viWrite(m_vistr, (ViBuf)pBuffer, (unsigned int)strlen(pBuffer), &iretcount));
}

int GPIB::Read(ViBuf lpVisaString, unsigned int nBufCount) {
	ViUInt32 vicount = 0;
	return (VI_SUCCESS == viRead(m_vistr, lpVisaString, nBufCount, &vicount));
}

int GPIB::Query(char *command, ViBuf retVal, unsigned int nBufCount) {
	if (this->Write(command)) {
		return this->Read(retVal, nBufCount);
	}
	else {
		return _VI_ERROR;
	}
}

int GPIB::Close() {
	return  viClose(m_vistr) && viClose(m_viSession);
}

首先先去NI官网上下载VISA,NI488.2,NIDAQ,装完再用这个文件。

你可能感兴趣的:(C++)