Filtering the numeric attribute in PI-OPCHDA

Discussion created by yaochen on Jul 19, 2012
Latest reply on Jul 21, 2012 by Ahmad Fattahi
I am writing an OPCHDA client in C language to access PI-OPCHDA server through OPCHDA spec 1.2 I have a question to do filter on the numeric attribute. The OPCHDA attribute with VT_BSTR (string type) which is working fine to me most of the time except some wild card on some special string attribute. However, for the numeric attribute,  the PI-OPCHDA server was always returned me all the tags without errors or warnings regardless the filter looks like. For example, the createBrowse API on page 49 in the OPCHDA Spec 1.2 is required to pass three input parallel arrays in order to handle "AND" the specified OPCHDA ATTRIBUTE The first array is  input DWORD *pdwAttrID  (attributes array were used in the filter strings) The 2nd array is inputOPCHDA_OPERATORCODES *pOperator (Operator arrays used in the filter strings) The 3rd array is VARIANT *vFilter (Filter values array with VARIANT type in the filter strings) Here are my code look like pdwAttrID[ANDIndex] = attrTreeNode->ppdwAttrID; // THis value is OPCHDA attributeID  pOperator[ANDIndex] = currentAND->sourceOper;   // This value is something like OPCHDA_EQUAL // Set the VARIANT type // ???? Does PI OPCHDA need to set a generic numeric type in the VARIANT structure  ??????? // I currently set each of the attribute type based on the attribute defined. attrDataType = attrTreeNode->ppvtAttrDataType; vFilter[ANDIndex].__VARIANT_NAME_1.__VARIANT_NAME_2.vt = attrDataType; // find the attribute type to set the value into VARIANT structure if(attrDataType == VT_BSTR) {      // NOTE: String attribute always working fine      bstr = SysAllocString(stringToWideString(getFilterStringValue(...));      vFilter[ANDIndex].__VARIANT_NAME_1.__VARIANT_NAME_2.__VARIANT_NAME_3.bstrVal = bstr; } else if (attrDataType == VT_R4 /* 4 */) {      double fltVal;      fltVal = getFiterValue(....);      vFilter[ANDIndex].__VARIANT_NAME_1.__VARIANT_NAME_2.__VARIANT_NAME_3.fltVal = fltVal; } else if (attrDataType == VT_I4 /* 3 */) {      INT32 i32;      i32 = getFilterValue(...);      vFilter[ANDIndex].__VARIANT_NAME_1.__VARIANT_NAME_2.__VARIANT_NAME_3.lVal = i32; } else if (attrDataType == VT_I2 /* 2 */) {      int i2;      i2 = getFilterValue(....);      vFilter[ANDIndex].__VARIANT_NAME_1.__VARIANT_NAME_2.__VARIANT_NAME_3.iVal = i2; } else       ........ Does anybody see anything wrong in the above VARIANT code which I used for the numeric attribute because I have no problem to access the string attribute. ???? Does PI OPCHDA server need a generic VARIANT type for the numeric attribute ????? All the case VT_R4 or VT_I4 or VT_I2 have the same problem to received all the tags just like the the string attribute wildcard * to receive all the values. Even one string attribute and one numeric attribute AND together, I still received all the tags    From the C language debugger, I did not see the correct fltVal, i32, and i2 passing into VARIANT. THere is no error or waring to create the filter and return the valid and correct browser. Here is the code to create browser hr = (*iOPCHDA_Server->lpVtbl->CreateBrowse)                 (                   iOPCHDA_Server,                  dwCount,                  pdwAttrID,                  pOperator,                  vFilter,                  &pphBrowser,                  &ppErrors                ); The next API which I used was GetEnum method from the page 50 under OPCHDA Spec 1.2 which returned       [out] LPENUMSTRING **ppIEnumString The browse type which I used was OPCHDA_FLAT. Here was the code   hr = (*iOPCHDA_Browser->lpVtbl->GetEnum )(iOPCHDA_Browser,                                             dwBrowseType,                                            &ppIEnumString); There is no error or warning to use this GetEnum method. I then used the GetItemID API to get the rgelt array and number of items from pceltFetched             hr = (*iOPCHDA_Browser->lpVtbl->GetItemID )(iOPCHDA_Browser,                                                  &rgelt,                                                  &pceltFetched); THis method also show no error or warning from the debugger. Does anybody experience the similar problem before and how do you bypass this numeric attributes which return all tags regardless the filter being specified ?