4 Replies Latest reply on Nov 19, 2013 10:07 AM by cfaure

    Annotations issue

    cfaure

      Hello,

       

      I tried to follow an example (KB00338) to write an annotation to an existing PI Archive value using PI-SDK but with C++ language.

       

      Here is the code I wrote:

       

      bool pi_server::addData(std::string pointName, std::string value, std::string timestamp, _bstr_t &errorDescr, HRESULT &errorNb)

       

      {

       

             _PIDataPtr pData;

       

             bool ret = TRUE;

       

             _NamedValuesPtr myValAttr(__uuidof(NamedValues));

       

             _variant_t vtTemp, vtTemp2;

       

              _PIAnnotationsPtr myAnns(__uuidof(PIAnnotations));

       

             PIAnnotationPtr myAnn;

       

             _PITimePtr valTim(__uuidof(PITime));

       

             _PIValuePtr myVal(__uuidof(PIValue));

       

             _PIValuesPtr myVals(__uuidof(PIValues));

       

       

       

             try

       

             {

       

                   pPoint = pServer->PIPoints->Item[pointName.c_str()];

       

                   pData = pPoint->GetData();

       

                   pData->UpdateValue(value.c_str(), timestamp.c_str(), dmReplaceDuplicates, NULL);

       

       

       

                   valTim->SetToCurrent();

       

                   myVal->TimeStamp = valTim;           

       

                   myAnn = myAnns->Add("myAnn", "myAnn", "Annotation1", false, "String");           

       

                   vtTemp = myAnns;           

       

                   myValAttr->Add("Annotations", &vtTemp);           

       

                   myVal->ValueAttributes = myValAttr;

       

                   vtTemp = myVal;

       

                   vtTemp2 = valTim;

       

                   pData->UpdateValue(&vtTemp, timestamp.c_str(), dmInsertDuplicates, NULL);           

       

             }

       

             catch(_com_error Err)

       

             {

       

                   errorDescr = Err.Description();

       

                   errorNb = Err.Error();

       

                   ret = FALSE;

       

             }

       

             return ret;

       

      }

       


       

      The result is that I have two values with the same timestamp, the good value and  -1 but no annotations.

       

      Could you help me to know what is wrong?

       

       

       

      Thank you

       

      Regards,

       

      Cyril Faure

       


       

       

        • Re: Annotations issue

          Hello Cyril,

           

          Cyril Faure

          The result is that I have two values with the same timestamp, the good value and  -1 but no annotations.

           

          I understand that you would like to annotate an existing event. Sorry but reading C++ code feels painful. Are you setting the value equal the value attribute (annotation)? Also you are using the current timestamp but as far as I can see not with the UpdateValue method.

           

          Andreas wrote a blog post titled C++ and PI - PI SDK - UpdateValues last year. Can you please see if it helps you sorting your issue?

            • Re: Annotations issue

              You can try the following modification of your code;

               

               

               
                           PIPointPtr pPoint = pServer->PIPoints->Item[_bstr_t(pointName.c_str())];
                           pData = pPoint->GetData();
                           pData->UpdateValue(value.c_str(), timestamp.c_str(), dmReplaceDuplicates, NULL);
               
                           valTim->SetToCurrent();
                           myAnn = myAnns->Add(_bstr_t("myAnn"), _bstr_t("myAnn"), _bstr_t("Annotation1"), false, "String");            
                           _variant_t vtTemp((IDispatchPtr)myAnns, true);
                           myValAttr->Add("Annotations", &(vtTemp.GetVARIANT()));
                           myVals->ReadOnly = false;
                           myVal = myVals->Add(_variant_t((IDispatchPtr)valTim, true), _variant_t(101), myValAttr);
                           pData->UpdateValue(_variant_t((IDispatchPtr)myVal, true), _variant_t(0), dmInsertDuplicates, NULL);
              

               

              • Re: Annotations issue
                cfaure

                Hello Gregor,

                 

                thank you very much for your help. I used the example from Andreas and it works fine.

                 

                Have a good day.

                 

                Cyril