DIAdem GPI驱动求助

quanercao 2018-08-17 02:52:34
先谢过各位大侠。

NI DIAdem软件是一个通用的测试测量数据、处理、分析工具,它支持VBS调用按GPI接口打包的c++dll。

由于不熟悉C++语法,一直未能实现获取GPI commands 返回值的需求,不清楚是GPI语法问题还是VBS调用问题。

求助各位帮忙看看,多谢!!
GPI开发工具在此下载: GPI Toolkit下载

以下为我修改后的Commands.cpp代码。

#include "stdafx.h"
#include "dataType.H"
#include "dataFct.H"
#include "Commands.h"
#include "Error/Error.h"
#include "Globals.h"

void getCommandInfo(
TGPIInPara commandNo,
TGPIInfo *commandInfo
)
{
switch (commandNo)
{
case 0:
// register the name of the command
strcpy_s(commandInfo->szName, "myCommand");
break;
case 1:
// register the name of the command
strcpy_s(commandInfo->szName, "myCommand2");
break;



default:
// There are more commands registered in DIAdem than
// supported by this function. Correct the NUM_COMMANDS constant defined
// in commands.h
ASSERT(false);
}
commandInfo->cType = eGPICOMMAND;
commandInfo->hHandle = MAKELONG(commandNo, eGPICOMMAND);
}

void getCommandProperties(
TGPILong commandNo,
TGPIProcProps *commandProperties
)
{
switch (commandNo)
{
case 0:
// register the name of the function to call
strcpy_s(commandProperties->szProcFctName, "myFunction");
// register function in scripts
commandProperties->cAutoseq = eGPIREGISTER;
// number of parameters
commandProperties->nParam = 3;
// 1st parameter is a data channel
commandProperties->aParam[0].cParamType = eGPIVARTYPEDATA;
// name of the data channel (for registration in DIAdem only)
strcpy_s(commandProperties->aParam[0].szParamName, "myData");
// 2nd parameter is a data channel
commandProperties->aParam[1].cParamType = eGPIVARTYPEDATA;
// name of the data channel (for registration in DIAdem only)
strcpy_s(commandProperties->aParam[1].szParamName, "myData");
// 3rd parameter is a result channel
commandProperties->aParam[2].cParamType = eGPIVARTYPEDATARES;
// name of the result channel (for registration in DIAdem only)
strcpy_s(commandProperties->aParam[2].szParamName, "myResult");
break;
case 1:
// register the name of the function to call
strcpy_s(commandProperties->szProcFctName, "MyFunction2");
commandProperties->cAutoseq = eGPIREGISTER;
commandProperties->nParam = 3;
commandProperties->aParam[0].cParamType = eGPIVARTYPEDOUBLE;
strcpy_s(commandProperties->aParam[0].szParamName, "myDouble");

commandProperties->aParam[1].cParamType = eGPIVARTYPEDOUBLE;
strcpy_s(commandProperties->aParam[1].szParamName, "myResult");

commandProperties->aParam[2].cParamType = eGPIVARTYPEDOUBLE;
strcpy_s(commandProperties->aParam[2].szParamName, "myDouble");
break;


default:
// There are more commands registered in DIAdem than
// supported by this function. Correct the NUM_COMMANDS constant defined
// in commands.h
ASSERT(false);
}
// We use this DLL to handle our commands, so we can
// set the DLL name "".
strcpy_s(commandProperties->szProcDLLName, "");
}

void initCommands(
)
{
}

void deinitCommands(
)
{
}

bool checkError(
TGPIReturn status,
CString functionName
)
{
CString errorMsg;

switch (status)
{
case DEM_STATUS_OK:
return(false);
break;

case DEM_STATUS_FAILED:
errorMsg.Format(
L"DEM_STATUS_FAILED?s", functionName);
break;

case DEM_STATUS_INVALID_CHANNEL:
errorMsg.Format(
L"DEM_STATUS_INVALID_CHANNEL?s", functionName);
break;

case DEM_STATUS_INVALID_INDEX:
errorMsg.Format(
L"DEM_STATUS_INVALID_INDEX?s", functionName);
break;

case DEM_STATUS_INVALID_CHANNEL_TYPE:
errorMsg.Format(
L"DEM_STATUS_INVALID_CHANNEL_TYPE?s", functionName);
break;

case DEM_Status_Invalid_Property:
errorMsg.Format(
L"DEM_Status_Invalid_Property?s", functionName);
break;

case DEM_Status_Invalid_Property_Type:
errorMsg.Format(
L"DEM_Status_Invalid_Property_Type?s", functionName);
break;

default:
errorMsg.Format(
L"DEM_STATUS_UNKNOWN?s", functionName);
break;
} // switch (status)
reportError(WEMICOMMANS, 1, errorMsg);
return(true);
}

GPIEXTERNC void DLLEXPORT
myFunction(
TGPIHandleV channel1,
TGPIHandleV channel2,
TGPIHandleV resultChannel
)
{
TGPIInt channel1Length;
TGPIInt channel2Length;
TGPIInt resultChannelLength;
TDataChannelParameterCheck channelParameter;
TGPIInt i;
TGPIDouble channel1Value;
TGPIDouble channel2Value;
TGPIDouble resultChannelValue;

if (checkError(getChannelPropertyInteger(channel1,
L"Length", &channel1Length), L"myCommand"))
{
return;
} // if (checkError(getChannelPropertyInteger(channel1,

if (checkError(getChannelPropertyInteger(channel2,
L"Length", &channel2Length), L"myCommand"))
{
return;
} // if (checkError(getChannelPropertyInteger(channel2,
resultChannelLength = channel1Length > channel2Length ?
channel2Length : channel1Length;

if (checkError(setChannelPropertyInteger(resultChannel,
L"Length", resultChannelLength), L"myCommand"))
{
return;
} // if (checkError(setChannelPropertyInteger(resultChannel,

if (checkError(initDoubleChannelParameter(&channelParameter), L"myCommand"))
{
return;
} // if (checkError(initDoubleChannelParameter(&channelParameter),

for (i = 1; i <= resultChannelLength; i++)
{
if (checkError(getDoubleChannelValue(channel1, i, &channel1Value),
L"myCommand"))
{
return;
} // if (checkError(getDoubleChannelValue(channel1, i, &channel1Value),

if (checkError(getDoubleChannelValue(channel2, i, &channel2Value),
L"myCommand"))
{
return;
} // if (checkError(getDoubleChannelValue(channel2, i, &channel2Value),
resultChannelValue = channel1Value + channel2Value;

if (checkError(setDoubleChannelValue(resultChannel, i, resultChannelValue),
L"myCommand"))
{
return;
} // if (checkError(setDoubleChannelValue(resultChannel, i,

if (checkError(checkDoubleChannelParameter(resultChannelValue,
&channelParameter), L"myCommand"))
{
return;
} // if (checkError(checkDoubleChannelParameter(resultChannelValue,
} // for (i = 1; i <= resultChannelLength; i++)

if (checkError(setDoubleChannelParameter(resultChannel, &channelParameter),
L"myCommand"))
{
return;
} // if (checkError(setDoubleChannelParameter(resultChannel,

if (checkError(setChannelPropertyString(resultChannel, L"unit_string",
L"m/s"), L"myCommand"))
{
return;
} // if (checkError(setChannelPropertyString(resultChannel, L"unit_string",

if (checkError(setChannelPropertyString(resultChannel, L"myDescription",
L"calculated sum of two channels"), L"myCommand"))
{
return;
} // if (checkError(setChannelPropertyString(resultChannel, L"myDescription",
}



//希望这个函数被GPI 通过VBS调用以后能通过参数返回值,但是未能成功
GPIEXTERNC void DLLEXPORT
MyFunction2(
TGPIDoubleP out1,TGPIDouble out2,TGPIDouble out3
)
{
*out1=10.0;
out2=11.0;
out3=3.0;
}

...全文
94 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

64,647

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧