C++与 Fluke5500A设备通过GPIB-USB-B通信的经验积累
===========以下内容来自:C++与 Fluke5500A设备通过GPIB-USB-B通信的经验积累 - J·Marcus - 博客园 (cnblogs.com)=======START============
1.需要安装NI-488.2.281,安装好了之后,GPIB-USB-B的驱动就自动安装好了
注意版本问题,之前安装了NI-488更高的版本,结果驱动安不上。
2.在C:\Program Files\IVI Foundation\VISA目录下,搜索visa32.lib和visa.h、visatype.h
将库和头文件拷贝到程序目录就可以引用了
#include "visa.h"
#pragma comment(lib, "visa32.lib")
3.常用的库函数:
/*- Resource Manager Functions and Operations -------------------------------*/
ViStatus _VI_FUNC viOpenDefaultRM (ViPSession vi);
ViStatus _VI_FUNC viFindRsrc (ViSession sesn, ViConstString expr, ViPFindList vi,
ViPUInt32 retCnt, ViChar _VI_FAR desc[]);
ViStatus _VI_FUNC viFindNext (ViFindList vi, ViChar _VI_FAR desc[]);
ViStatus _VI_FUNC viParseRsrc (ViSession rmSesn, ViConstRsrc rsrcName,
ViPUInt16 intfType, ViPUInt16 intfNum);
ViStatus _VI_FUNC viParseRsrcEx (ViSession rmSesn, ViConstRsrc rsrcName, ViPUInt16 intfType,
ViPUInt16 intfNum, ViChar _VI_FAR rsrcClass[],
ViChar _VI_FAR expandedUnaliasedName[],
ViChar _VI_FAR aliasIfExists[]);
ViStatus _VI_FUNC viOpen (ViSession sesn, ViConstRsrc name, ViAccessMode mode,
ViUInt32 timeout, ViPSession vi);
/*- Resource Template Operations --------------------------------------------*/
ViStatus _VI_FUNC viClose (ViObject vi);
ViStatus _VI_FUNC viSetAttribute (ViObject vi, ViAttr attrName, ViAttrState attrValue);
ViStatus _VI_FUNC viGetAttribute (ViObject vi, ViAttr attrName, void _VI_PTR attrValue);
ViStatus _VI_FUNC viStatusDesc (ViObject vi, ViStatus status, ViChar _VI_FAR desc[]);
ViStatus _VI_FUNC viTerminate (ViObject vi, ViUInt16 degree, ViJobId jobId);
ViStatus _VI_FUNC viLock (ViSession vi, ViAccessMode lockType, ViUInt32 timeout,
ViConstKeyId requestedKey, ViChar _VI_FAR accessKey[]);
ViStatus _VI_FUNC viUnlock (ViSession vi);
ViStatus _VI_FUNC viEnableEvent (ViSession vi, ViEventType eventType, ViUInt16 mechanism,
ViEventFilter context);
ViStatus _VI_FUNC viDisableEvent (ViSession vi, ViEventType eventType, ViUInt16 mechanism);
ViStatus _VI_FUNC viDiscardEvents (ViSession vi, ViEventType eventType, ViUInt16 mechanism);
ViStatus _VI_FUNC viWaitOnEvent (ViSession vi, ViEventType inEventType, ViUInt32 timeout,
ViPEventType outEventType, ViPEvent outContext);
ViStatus _VI_FUNC viInstallHandler(ViSession vi, ViEventType eventType, ViHndlr handler,
ViAddr userHandle);
ViStatus _VI_FUNC viUninstallHandler(ViSession vi, ViEventType eventType, ViHndlr handler,
ViAddr userHandle);
/*- Basic I/O Operations ----------------------------------------------------*/
ViStatus _VI_FUNC viRead (ViSession vi, ViPBuf buf, ViUInt32 cnt, ViPUInt32 retCnt);
ViStatus _VI_FUNC viReadAsync (ViSession vi, ViPBuf buf, ViUInt32 cnt, ViPJobId jobId);
ViStatus _VI_FUNC viReadToFile (ViSession vi, ViConstString filename, ViUInt32 cnt,
ViPUInt32 retCnt);
ViStatus _VI_FUNC viWrite (ViSession vi, ViConstBuf buf, ViUInt32 cnt, ViPUInt32 retCnt);
ViStatus _VI_FUNC viWriteAsync (ViSession vi, ViConstBuf buf, ViUInt32 cnt, ViPJobId jobId);
ViStatus _VI_FUNC viWriteFromFile (ViSession vi, ViConstString filename, ViUInt32 cnt,
ViPUInt32 retCnt);
ViStatus _VI_FUNC viAssertTrigger (ViSession vi, ViUInt16 protocol);
ViStatus _VI_FUNC viReadSTB (ViSession vi, ViPUInt16 status);
ViStatus _VI_FUNC viClear (ViSession vi);
/*- Formatted and Buffered I/O Operations -----------------------------------*/
ViStatus _VI_FUNC viSetBuf (ViSession vi, ViUInt16 mask, ViUInt32 size);
ViStatus _VI_FUNC viFlush (ViSession vi, ViUInt16 mask);
ViStatus _VI_FUNC viBufWrite (ViSession vi, ViConstBuf buf, ViUInt32 cnt, ViPUInt32 retCnt);
ViStatus _VI_FUNC viBufRead (ViSession vi, ViPBuf buf, ViUInt32 cnt, ViPUInt32 retCnt);
ViStatus _VI_FUNCC viPrintf (ViSession vi, ViConstString writeFmt, ...);
ViStatus _VI_FUNC viVPrintf (ViSession vi, ViConstString writeFmt, ViVAList params);
ViStatus _VI_FUNCC viSPrintf (ViSession vi, ViBuf buf, ViConstString writeFmt, ...);
ViStatus _VI_FUNC viVSPrintf (ViSession vi, ViBuf buf, ViConstString writeFmt,
ViVAList parms);
ViStatus _VI_FUNCC viScanf (ViSession vi, ViConstString readFmt, ...);
ViStatus _VI_FUNC viVScanf (ViSession vi, ViConstString readFmt, ViVAList params);
ViStatus _VI_FUNCC viSScanf (ViSession vi, ViConstBuf buf, ViConstString readFmt, ...);
ViStatus _VI_FUNC viVSScanf (ViSession vi, ViConstBuf buf, ViConstString readFmt,
ViVAList parms);
ViStatus _VI_FUNCC viQueryf (ViSession vi, ViConstString writeFmt, ViConstString readFmt, ...);
ViStatus _VI_FUNC viVQueryf (ViSession vi, ViConstString writeFmt, ViConstString readFmt, ...);
具体怎么调用百度可以搜到例程。
安装NI-488以后也会安装例程。
我的代码:
void c_gbip_demo_dlg::on_bn_clicked_conn()
{
ViStatus error = viOpenDefaultRM(&m_vi_session_rm);
if (error != VI_SUCCESS)
{
return;
}
error == viOpen(m_vi_session_rm, "GPIB0::4::INSTR", VI_EXCLUSIVE_LOCK, VI_NULL, &m_vi_session);
if (error== VI_SUCCESS)
{
char receiveBufferArrary[256] = { 0 };
viPrintf(m_vi_session, "*RST\n"); //发送复位命令
error = viPrintf(m_vi_session, "*IDN?\n"); //发送读取设备信息命令
viScanf(m_vi_session, "%t", &receiveBufferArrary);
UpdateData(FALSE);
}
else
{
//MessageBox("连接设备失败!", "提示", MB_OK | MB_ICONWARNING);
}
return ;
}
注意,viOpen的第二个参数我写的GPIB0::4::INSTR。这个参数,可以打开VISA Interactive Control查看到:
viOpen调用成功后,就连接成功了,之后就是命令发送、接收的问题了。
4.具体命令的写法,要依据具体设备的程序员手册来确定。
===========以上内容来自:C++与 Fluke5500A设备通过GPIB-USB-B通信的经验积累 - J·Marcus - 博客园 (cnblogs.com)=========END============