Skip navigation
All Places > PI Developers Club > General Programming Languages > Blog

I know a lot of customers use C# or VB instead of C++.

Though I had a chance to work with C++ and AFSDK.

I want to share the code as example

 

Visual Studio 2015

Create new projects > Visual C++ > CLR > CLR Console Application

Project > Add reference > OSIsoft.AFSDK

#include "stdafx.h"

using namespace System;
using namespace OSIsoft::AF;
using namespace OSIsoft::AF::PI;
using namespace OSIsoft::AF::Data;
using namespace OSIsoft::AF::Asset;
using namespace System;
using namespace OSIsoft::AF::Time;

int main(array<System::String ^> ^args)
{
    // Get tag snapshot value
    PIServers^ piServers = gcnew PIServers();
    PIServer^ piServer = piServers->DefaultPIServer;
    PIPoint^ pt = pt->FindPIPoint(piServer, "cdt158");
    AFValue^ snapval = pt->CurrentValue();
    Console::WriteLine("Tag = " + pt->Name + " Value : " + snapval->Value);

    // Get RecordedValue
    AFTime myTime = AFTime("*-5h");
    AFValue^ oldval = pt->RecordedValue(myTime, AFRetrievalMode::Before);
    Console::WriteLine("RecordedValue = " + myTime + " Value : " + oldval->Value);

    // Get RecordedValues
    AFTimeRange range = AFTimeRange("*-1h", "*");
    AFValues^ vals = pt->RecordedValues(range, AFBoundaryType::Inside, "", false, 1000);
    Console::WriteLine("RerocdedValues : ");
    for each (AFValue^ val in vals)
    {
        Console::WriteLine("TimeStamp : " + val->Timestamp + " Value : " + val->Value);
    }
    
    //Write Tag Value
    PIPoint^ writept = writept->FindPIPoint(piServer, "test999");
    AFValue^ writeval = gcnew AFValue(10,AFTime("*"));
    writept->UpdateValue(writeval, AFUpdateOption::Replace);
    Console::WriteLine("UpdateTag : " + writept->Name + " Timestamp : " + writeval->Timestamp + " Value : " + writeval->Value);
    
    // Get AF attribute snapshot value
    PISystems^    piSystems = gcnew PISystems();
    PISystem^    piSystem = piSystems["localhost"];
    AFDatabase^ DB = piSystem->Databases["PIBigTiresCo"];
    AFElement^ Elem = DB->Elements["Houston"];
    AFNamedCollection<AFAttribute^>^    atrs = Elem->Attributes;
    AFAttribute^    atr = atrs["Total Good Production"];
    Console::WriteLine(atr->Name + " : " + atr->GetValue()->Value);

    //Disconnect
    piServer->Disconnect();
    piSystem->Disconnect();

    Console::Read();
    return 0;
}



It shows following results.

Filter Blog

By date: By tag: