NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Arrays to Operator Interfaces using UI Message

Hi all,

I made a custom user interface using CVI, and on the GUI I want to display graphicaly some measurements. The measurements are stored in Testand in some Arrays. I know that User UI Messages, can pass an ActiveX References as parameter, my question is how do I link my array with the ActiveX Reference, and how I extract the Array from the UI Message in CVI.

Many thanks
0 Kudos
Message 1 of 6
(3,505 Views)
miniMe,

The best way to get data in a UI Message that is not either a single numeric or a single string is to use the ActiveX parameter to pass the sequence context. Once you have this sequence context, you can use it as you would use the context in any code module. Therefore, you can use the Get Property Value functions to get the numeric array for which you are looking. The only caveat to keep in mind is that the ActiveX data will come in as a variant and you will have to to let CVI know that the information coming in is a Sequence Context. Hopefully this gets you on your way, but please let me know if you have any further questions. Thanks and have a good one.

Adam B.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 6
(3,489 Views)
Hi,

If you are only passing a single array, you can pass the array in the ActiveX field.

So you can use the API method "Post UI Message", and pass the array directly into the ActiveX field. (Locals.MyArray for example).

In your callback function for getting your UI message, here is the code you want to use:

HRESULT CVICALLBACK ApplicationMgr_OnUserMessage(CAObjHandle caServerObjHandle,
void *caCallbackData, TSUIObj_UIMessage uiMsg)
{
LPUNKNOWN tempActiveXRef;
VARIANT tempTSWaveform;
VARIANT tempVariant = CA_VariantEmpty();
CAObjHandle TSWaveform = 0;
double * measurementData;
ERRORINFO errorInfo;

//Get waveform ActiveX data
TS_UIMessageGetActiveXData (uiMsg, NULL, &tempActiveXRef);

//Convert LPUNKNOWN to Variant
tempTSWaveform = CA_VariantIUnknown (tempActiveXRef);

//Convert variant to object handle
CA_VariantConvertToType (&tempTSWaveform, CAVT_OBJHANDLE, &TSWaveform);

//Get contents of waveform
TS_PropertyGetValVariant (TSWaveform, &errorInfo, "", 0, &tempVariant));

// Convert the one-dimensional Safe Array passed in the Variant parameter
// into a dynamically allocated C-style array.
CA_VariantGet1DArray (&tempVariant, CAVT_DOUBLE, measurementData, NULL);

// Frees the memory
CA_VariantClear(&tempTSWaveform);
CA_VariantClear(&tempVariant);
CA_FreeMemory(measurementData);

}


Hope this helps!

Allen P.
TestStand R&D
0 Kudos
Message 3 of 6
(3,482 Views)
Adam,
Many thanks for info, I'll try your suggestion.
0 Kudos
Message 4 of 6
(3,467 Views)
Hi AllenP,

I tried the code that you proposed, but if I used in the function call, "measurementData" as parameter, the code can be compiled, but I will get runtime errors. Finaly, I managed to make it run with a small change that is quit puzzling, instead of

CA_VariantGet1DArray (&tempVariant, CAVT_DOUBLE, measurementData, NULL);

I had to use

CA_VariantGet1DArray (&tempVariant, CAVT_DOUBLE, &measurementData, NULL);

So now it works fine ! Many thanks for info !

If you happen to find the explanation about why it works with the "&measurementData" instead of "measurementData" I would be very interested to understand also.

Best Regards
0 Kudos
Message 5 of 6
(3,467 Views)
Good eye!

I did make that typo. I was converting it from some existing code that had a fixed array and missed that change.

The reason this is working is because it needs to pass the pointer to the array, not the actual array. measurementData is allocated properly inside of this function CA_VariantGet1DArray (and set with the correct new pointer for the allocated memory).
0 Kudos
Message 6 of 6
(3,455 Views)