LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

NI CW Automation Symbo! Can not change the value of CWVESSEL ???

Hi all,

I am very new to ActiveX controls so when i used CWVESSEL for simulation the change of the liquid level in a tank , i got stuck.

I just can change some of its properties like caption or enabled ...

My code follows

static int panelHandle;
CAObjHandle Tank=0;
....

GetObjHandleFromActiveXCtrl (panelHandle, PANEL_CWVESSEL, &Tank);
CWASControlsLib_SetProperty (tank, NULL, CWASControlsLib__DCWVesselCaption, CAVT_CSTRING,
                             "TANK"); // this one is ok
CWASControlsLib_SetProperty (tank, NULL, CWASControlsLib__DCWVesselValue, CAVT_VARIANT, 400);// it doesnot work
...

One more, As i read the value of CWVESSEL , it always be 5 , i dont understand .

Can U help me ?
Thanks!
           
0 Kudos
Message 1 of 4
(3,296 Views)

Hi,

This ActiveX control must be from an extremely old version of our software - it is deprecated now.  However, from the name and your description, I think is replaced with a native CVI control - a tank. 

I think the problem with your code snippet is that you have selected the type VARIANT, instead of a LONG or DOUBLE.  Here is the list of possible data types, found in the CVI help:

Data Types for Variants, Safe Arrays, and Properties

A set of fundamental data types exists that is valid for variants, safe arrays, and properties. You can apply a set of modifiers to these fundamental data types to create more data types. Not all combinations of data types and modifiers are valid in all cases. The function descriptions specify which data types are valid in particular contexts. The following table shows the fundamental data types.

Fundamental Data Types for Variants, Safe Arrays, and Properties

Defined Constant Data Type or Meaning
CAVT_EMPTY Variant contains nothing
CAVT_NULL Variant contains NULL value
CAVT_SHORT short
CAVT_LONG long
CAVT_INT int (same as CAVT_LONG)
CAVT_FLOAT float
CAVT_DOUBLE double
CAVT_CY CURRENCY (Windows SDK data type)
CAVT_DATE DATE (Windows SDK data type)
CAVT_BSTR BSTR (Windows SDK data type)
CAVT_DISPATCH LPDISPATCH (ActiveX data type for an ActiveX object interface)
CAVT_ERROR SCODE (Windows SDK data type)
CAVT_BOOL VBOOL, which maps to VARIANT_BOOL (ActiveX data type)
CAVT_VARIANT VARIANT (ActiveX data type)
CAVT_UNKNOWN LPUNKNOWN (ActiveX data type for an unknown interface)
CAVT_UCHAR unsigned char
CAVT_CSTRING char * (null-terminated string)
CAVT_OBJHANDLE CAObjHandle, which maps to void *

Cheers,

David Goldberg
National Instruments
Software R&D
0 Kudos
Message 2 of 4
(3,270 Views)
Thanks, Smiley Happy

It works very well.However, I still wonder about  data types  , especially the type Variant!

In my understanding, i suppose all data types in the list " Fundamental Data Types for Variants,Safe Arrays, and Properties" are some types of data  which related to Active X.

If one of Active X object's properties  varies from 0 to 100 , i should pass CAVT_INT to that parameter. Is that right?
However, according to the definition of the type Variant in CVI Help "
The VARIANT data type is a structure that can hold a value of any valid ActiveX data type" and "ActiveX server functions declare a parameter as a VARIANT when the parameter can take a value of more than one data type" . I still can not figure out how it works.Can U show me some examples?

And one more thing, what does " CA "  stand for? and
"CAVT" stand for?  is that Constant ActiveX and Constant ActiveX VarienT ? or some thing elses?

Thanks again,



0 Kudos
Message 3 of 4
(3,232 Views)

Hi,

I just wanted to add a couple of pieces of information to the post. First off, CA stands for CVI automation (of course it used to be referred to as C automation). 

To set the Vessel Value property, you could have done something like:

-
CWASControlsLib_SetProperty (tank, NULL, CWASControlsLib__DCWVesselValue, CAVT_SHORT, 10);   // You could have also done CAVT_LONG, CAVT_DOUBLE (of course with double, you would need to say 10.0 for the value)

Or if you wanted to use a straight-up variant, you could have said
CA_VariantSetShort (&jonathan, 10);   // Storing a short integer of 10 into a variant
 
CWASControlsLib_SetProperty (tank, NULL, CWASControlsLib__DCWVesselValue, CAVT_VARIANT, jonathan);
           
It is true that the Variant data type (basically just a universal data type) can store different data types. A Variant in itself is basically two parts which consist of the actual data value and a section that describes the type of data it is storing.  Now, those defined constants like CAVT_SHORT. CAVT_LONG are used to help indicate the type of data that is being stored in that variant. So for example, the CA_VariantSet1DArray function takes some native array like an array of longs, double, floats, etc and converts that over to a safe array to be stored in a variant. You specify the variants data type by using one of defined constants like CAVT_LONG, CAVT_DATE, etc.

To find some examples that use any of those functions or constants, what I like to do is do a Ctrl+F on the
<CV>\samples\ directory, search for All files and folders, and the type for example, "CA_VariantSet1DArray" in the "a word or phrase in the file:" option. This will bring up all examples that use that word. If you type CA_VariantSet1DArray in, you will find several examples come up like the 3DGraphContours example located in the <CVI81>\samples\userint\activex

A couple helpful documents include What Are the Variant, SafeArray, and BSTR Data Types and Why Are They Needed? KnowledgeBase and the Working with Variants in Visual Basic tutorial.

Hope that helps,

Jonathan N.
National Instruments
0 Kudos
Message 4 of 4
(3,182 Views)