DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with GPI command & function

Solved!
Go to solution

Hi,everyone.I am learning about how to build a GPI dll. And I am Not familiar with how to create commands.

I have finished some work on commands/step_1 of demos , which has shown as below

// register the name of the command
strcpy_s(commandInfo->szName, "IF2");

// register the name of the function to call
strcpy_s(commandProperties->szProcFctName, "TC2");
commandProperties->cAutoseq = eGPIREGISTER;
commandProperties->nParam = 1;
commandProperties->aParam[0].cParamType = eGPIVARTYPEDOUBLE;
strcpy_s(commandProperties->aParam[0].szParamName, "myResult");

And

GPIEXTERNC void DLLEXPORT  TC2(TGPIDouble out1)
{

out1=10.0;
}

After registration of the dll,When I am trying to call TC2 in Scripts like below ,I get nothing on X.

DIM X
IF2(X)

 

Many thx for any help or hints!!
Best regards ,Q

0 Kudos
Message 1 of 5
(2,740 Views)
Solution
Accepted by topic author quanercao

Hello Quanercao,

I had a look through your code and found some mistakes in your code.

In Commands.cpp line 68 you set the type of the parameter to eGPIVARTYPEDOUBLE and in the next line you define the name of the parameter to "myResult". The variable "myResult" however is defined as a variable of type eGPIVARTYEDATARES. So the data types of the parameter and the associated variable don't match. DIAdem uses the associated variable to do some parameter checking (data type, range, etc.). If the data types of the parameter and the associated variable don't match, the result is undefined. So make sure that the data types of the parameter and the associated variable matches (in your example you may choose "myDouble" which is defined as a variable of data type eGPIVARTYPEDOUBLE).

The next mistake is your assumption that you may be able to return data through the parameter you have passed into the function. That is not true. The funktion does not have any return values. The correct declaration of your function is

 

GPIEXTERNC void DLLEXPORT
TC2(
  TGPIDoubleV out1
)

The parameter you pass from DIAdem to your function comes by value and not by reference. If you want to return a value from your function, you have to assign this value to a variable.

 

Hope this helps.

 

Best Regards

Rainer

Message 2 of 5
(2,683 Views)

 

Hi Rainer,

 

Sorry about my mistakes and thank you very much. Your reply helps a lot.


@RainerH

The parameter you pass from DIAdem to your function comes by value and not by reference. If you want to return a value from your function, you have to assign this value to a variable.

 I have try many times to pass parameters by reference in C++. But it doesn't work at all.

And I don't know how to set/get value to variable in a GPI command-function.Could you please give me some advice or a demo?

 

 

Best Regards,

Quanercao

  

 

0 Kudos
Message 3 of 5
(2,672 Views)
Solution
Accepted by topic author quanercao

Hi Quanercao,

 

variables are defined similar to commands in the GPICallback() function in DIAdem. There is one example in the GPI-package that deals with variables. You may use this as a base for defining your own variables. In general for every variable you define as a DIAdem GPI-Variable, you have to define one global variable in your code. This way you can access this variable from both sides, from DIAdem via script and from your code (e.g. your command). So if you want to return some values from your command, just write the value(s) to your global variable(s) and read out these variable(s) in a DIAdem script.

 

Best Regards,

Rainer

Message 4 of 5
(2,640 Views)

Hi Rainer, I know how to do it now. Thanks a lot !!!

0 Kudos
Message 5 of 5
(2,585 Views)