3 Replies Latest reply on Aug 4, 2009 9:47 AM by andreas

    Visual C++ 2008 express with PITime

    jrlrwilson

      I am trying to create a new PITime object to be able to pass it to the PIData.TimedValues in an array.  I am getting the following error:

       

      1>.\PIAgent.cpp(852) : error C2079: 'ptf' uses undefined struct 'PITime'

       

      from the line of code: PITime ptf = new PITime();

       

      Has anyone used this or have a sample to look at.

       

       

        • Re: Visual C++ 2008 express with PITime

          The limited exposure I have had in projects using C++ I haven't created a new instance of PITime but used a pointer to existing PITime object:

           

          e.g.

          _PITimePtr ptm = pData->Snapshot->TimeStamp;

          • Re: Visual C++ 2008 express with PITime
            jrlrwilson

            I did not get the TimedValues to work wiht PITime but I did find something that works to move on. Just didn't want to leave this hanging out there.

             

             

             

            Created a list of piValues and passed it in.

             

            _PIValuesPtr piValuesPtrTimes(__uuidof(PIValues)); 
            piValuesPtrTimes->PutReadOnly(false);

             

            ...

             

                    for (i = 0; i < numTimes; i++)
                    {
                        double d = atof(stri);
                        piValuesPtrTimes->Add(d,NULL,NULL);
                    }

             

            piValuesPtrTimes->PutReadOnly(true);
            pValues = pData->TimedValues(&*piValuesPtrTimes, nullBSTR, fvRemoveFiltered, false, asynch);

              • Re: Visual C++ 2008 express with PITime
                andreas

                Hi Jeremy,

                 

                after having some conversation with the PI SDK team here is how you could use the PITime:

                 

                /* The SafeArray for the PItimes */
                SAFEARRAY * psaTimes;

                /* The bounds for the SafeArray */
                SAFEARRAYBOUND rgsabound[1];
                /* Set the bounds */
                rgsabound[0].lLbound = 0;

                rgsabound[0].cElements = iNumOfTimes;

                /* Create the SafeArray */
                psaTimes = SafeArrayCreate(VT_DISPATCH,1,rgsabound);

                if
                (!psaTimes)
                {
                    wprintf_s(L"Failed to create Safearray for times.\n");
                    return 1;
                }

                for(long i=0; i<iNumOfTimes; ++i)
                {
                    /* Create a piTime */
                    _PITimePtr piTime(__uuidof(PITime));

                    /* the index for the SafeArray */
                    long ix[1];
                    ix[0] = i;

                    /* Keep it simple, set the piTime with UTCSeconds :-) */
                    double d = 1249286400 + (60 * i);
                    piTime->UTCSeconds = d;

                    /* Assign the piTime to the array element */
                    HRESULT hr = SafeArrayPutElement(psaTimes,ix,piTime);
                    if(!SUCCEEDED(hr))
                    {
                        wprintf_s(L"Failed to access Safearray for times.");
                        SafeArrayDestroy(psaTimes);
                        return 1;
                    }
                }

                /*
                 * From the Documentation:
                 *    Variant containing a SAFEARRAY of localDates, a SAFEARRAY of PITime objects,
                 *    a SAFEARRAY of numerics interpreted as seconds since 1970 or a PIValues
                 *    collection where the times are used and the values are ignored. See the
                 *    settings section.
                 */
                /* The Variant */
                VARIANT vtTimeStamps;
                VariantInit(&vtTimeStamps);
                /* An Array of type VT_DISPATCH */

                vtTimeStamps.vt = VT_ARRAY | VT_DISPATCH;
                vtTimeStamps.parray = psaTimes;

                pPIValues = pPIPoint->Data->TimedValues(vtTimeStamps,"",fvShowFilteredState,false,NULL);

                 

                 

                hope this helps!