NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Change Prototype Parameter from a TestStand DLL Module Programmaticaly

Solved!
Go to solution

Hi.

I started this post inside the LabWindows section, but had no replies there.

Hope I can get some help here.

 

Please see the follwing link

http://forums.ni.com/ni/board/message?board.id=180&message.id=46129&query.id=804485#M46129

 

Thanks in advance.

Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
0 Kudos
Message 1 of 9
(3,955 Views)

Here's where I'm at:

 

void __declspec(dllexport) GetControlarParameters(CAObjHandle seqContextCVI)

//seqContextCVI has ThisContext reference object
{
 char   strItemLabel2[1024] = "";
 CAObjHandle  module     = 0;
 ERRORINFO errorInfo;
 CAObjHandle parameters = 0;
 CAObjHandle parameter = 0;
 VARIANT varParmIndex;

 

 TS_StepGetModule %d\n", TS_StepGetModule (seqContextCVI, &errorInfo, &module);
 TS_CVIModuleGetParameters %d\n", TS_CVIModuleGetParameters(module, &errorInfo, &parameters); 
 sprintf(strItemLabel2, "\"%s\"", "TEST");

 CA_VariantSetInt(&varParmIndex, 1);
 TS_CVIParametersGetItem %d\n", TS_CVIParametersGetItem(parameters, &errorInfo, varParmIndex, &parameter);
 TS_CommonCParameterSetValueExpr %d\n", TS_CommonCParameterSetValueExpr(parameter, &errorInfo, strItemLabel2);

 CA_DiscardObjHandle (parameter);
 CA_DiscardObjHandle (parameters);
 CA_DiscardObjHandle (module);
}

Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
0 Kudos
Message 2 of 9
(3,933 Views)

a sequence context is not a step, so cannot be used with TS_Step_GetModule(). Where do you want to get the step from? There are several possibilities, one is that the sequence file in which the step exists could be passed in as a parameter, another is that you could use the sequence file that was initially selected when your execution was started (generally for tool menu items), and really there are many more possibilities, please explain exactly what you are trying to do (i.e. where you are getting the sequence file from, why you are wanting to do this, etc.).

 

-Doug

0 Kudos
Message 3 of 9
(3,929 Views)

Thank you for your reply Doug.

 

I've created a type pallete in TestStand. One of the functions (Controlar) of my pallete creates an action as a C/C++ DLL Adapter (6 parameters apear with no values).

This step creates an "Edit" button that opens a user interface if you click on it.

Inside the UI the user selects the avalilable data to be inserted in each parameter.

So, when I click "OK", I want to directly write the data in each of the DLL parameters.

 

Instead of using ThisContext, I used Step or ThisContext.Step but I still can write the data.

 

I apreciate your help.

Message Edited by Daniel Coelho on 03-30-2010 09:33 AM
Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
Download All
0 Kudos
Message 4 of 9
(3,922 Views)

Ah ok, for an edit substep you should edit the step located at ThisContext.Step. You should still pass in the sequence context though because you will need other things on it too (see example code below).

Your function should look more like the following (also added error handling which will help you better diagnose any problems since you will get an error message rather than it failing silently like it will without error handling):

#include "tsutil.h" // use tsutil.fp as well as tsapicvi.fp

void __declspec(dllexport) __stdcall GetControlarParameters(CAObjHandle seqContext)
{
    int error = 0;
    ErrMsg errMsg = {'\0'};
    ERRORINFO errorInfo;
    char strItemLabel2[1024] = "";
    CAObjHandle step = 0;
    CAObjHandle seqFile = 0;
    CAObjHandle module = 0;
    CAObjHandle parameters = 0;
    CAObjHandle parameter = 0;

    tsErrChk(TS_SeqContextGetStep (seqContext, &errorInfo, &step));
    tsErrChk(TS_StepGetModule(step, &errorInfo, &module));
    tsErrChk(TS_CVIModuleGetParameters(module, &errorInfo, &parameters));
    tsErrChk(TS_CVIParametersGetItem(parameters, &errorInfo, CA_VariantInt(1), &parameter));
    sprintf(strItemLabel2, "\"%s\"", "TEST");
    tsErrChk(TS_CommonCParameterSetValueExpr(parameter, &errorInfo, strItemLabel2));

    // NOTE: After making an edit to a step you need to mark the file as modified by
    // incrementing the file's change count. This is also necessary for the change to show

    // up in the sequence editor imediately.

    tsErrChk(TS_SeqContextGetSequenceFile (seqContext, &errorInfo, seqFile));
    tsErrChk(TS_SeqFileIncChangeCount(seqFile, &errorInfo));

Error: 

    CA_DiscardObjHandle(step);
    CA_DiscardObjHandle(seqFile);
    CA_DiscardObjHandle(module);
    CA_DiscardObjHandle(parameters);
    CA_DiscardObjHandle(parameter);

    // If an error occurred, set the error flag to cause a run-time error in TestStand.
    if (error < 0)

        TS_SetStepError(seqContext, error, errMsg);
}

 

Hope this helps,

-Doug

Message 5 of 9
(3,900 Views)

You were very helpul, I understand a bit better what I was doing wrong.

Stiil, I'm getting Error -2147467262 "No such interface supported" at TS_CVIModuleGetParameters()

 

Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
0 Kudos
Message 6 of 9
(3,887 Views)

That will happen if the step does not currently have a CVI module specified (i.e. the module is for a different adapter so does not implement the CVIModule interface). Please make sure that the step actually has a CVI module specified.

 

-Doug

0 Kudos
Message 7 of 9
(3,867 Views)
Solution
Accepted by topic author Daniel Coelho

Hi Doug.

I'm sorry for the delay.

 

Here's how I solved the problem: I changed from CVI module to DLL module.

Here's a sample of my code:

 

//I changed from CVIModuleGetParameters() and CVIParametersGetItem() to TS_DllModuleGetParameters() and TS_DllParametersGetItem and now it works fine.
//seqContextCVI = ThisContext reference object
void __declspec(dllexport) __stdcall GetControlarParameters(CAObjHandle seqContext)
{
    int error = 0;
    ErrMsg errMsg = {'\0'};
    ERRORINFO errorInfo;
    char strItemLabel2[1024] = "";
    CAObjHandle step = 0;
    CAObjHandle seqFile = 0;
    CAObjHandle module = 0;
    CAObjHandle parameters = 0;
    CAObjHandle parameter = 0;

    tsErrChk(TS_SeqContextGetStep (seqContext, &errorInfo, &step));
    tsErrChk(TS_StepGetModule(step, &errorInfo, &module));
    tsErrChk(TS_DllModuleGetParameters (module, &errorInfo, &parameters));
    tsErrChk(TS_DllParametersGetItem (parameters, &errorInfo, CA_VariantInt(1), &parameter));
    sprintf(strItemLabel2, "\"%s\"", "TEST");
    tsErrChk(TS_CommonCParameterSetValueExpr(parameter, &errorInfo, strItemLabel2));

    // NOTE: After making an edit to a step you need to mark the file as modified by
    // incrementing the file's change count. This is also necessary for the change to show
    // up in the sequence editor imediately.
    tsErrChk(TS_SeqContextGetSequenceFile (seqContext, &errorInfo, seqFile));
    tsErrChk(TS_SeqFileIncChangeCount(seqFile, &errorInfo));

Error: 

    CA_DiscardObjHandle(step);
    CA_DiscardObjHandle(seqFile);
    CA_DiscardObjHandle(module);
    CA_DiscardObjHandle(parameters);
    CA_DiscardObjHandle(parameter);

    // If an error occurred, set the error flag to cause a run-time error in TestStand.
    if (error < 0)

        TS_SetStepError(seqContext, error, errMsg);
}

Thank you for all the help.

My best regards.

Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
0 Kudos
Message 8 of 9
(3,828 Views)

You must be using the DLL adapter then and not the CVI adapter. Glad you got it working.

 

-Doug

0 Kudos
Message 9 of 9
(3,822 Views)