PI VC开发代码实例

#include <atlbase.h>
#import "pisdkcommon.dll" no_namespace
#import "piTimeServer.dll" no_namespace
#import "pisdk.dll" no_namespace


//获取点的描述
void GetTagDescriptor(_bstr_t bServer, _bstr_t bTagName, _variant_t &vDesc)

{

try

{

// navigate through the PISDK

IPISDKPtr pSDK(__uuidof(PISDK));

ServersPtr pServs = pSDK->GetServers();

ServerPtr pServ = pServs->GetItem(bServer);

PIPointsPtr pPts = pServ->GetPIPoints();

PIPointPtr pPt = pPts->GetItem(bTagName);

PointAttributesPtr pAtts = pPt->GetPointAttributes();

PointAttributePtr pDesc = pAtts->GetItem(_bstr_t("descriptor"));

vDesc = pDesc->GetValue();

}

// Check for errors thrown by smart pointers

catch(_com_error e)

{

_tprintf(_T("Error %x occurred. Message was %s\n"), e.Error(), (char *)e.Description());

}

// Check for non COM errors being thrown

catch(...)

{

_tprintf(_T("Non-COM error"));

}

}
//获取点的值
void GetTagValue(_bstr_t bServer, _bstr_t bTagName, _variant_t &vValue)

{

try

{

CTime dtStart,dtEnd;
//BoundaryTypeConstants btType;


// navigate through the PISDK

IPISDKPtr pSDK(__uuidof(PISDK));

ServersPtr pServs = pSDK->GetServers();

ServerPtr pServ = pServs->GetItem(bServer);

PIPointsPtr pPts = pServ->GetPIPoints();

PIPointPtr pPt = pPts->GetItem(bTagName);

_PIDataPtr pData = pPt->GetData();

_PIValuePtr pValue = pData->GetSnapshot();

vValue = pValue->GetValue();

}

// Check for errors thrown by smart pointers

catch(_com_error e)

{

_tprintf(_T("Error %x occurred. Message was %s\n"), e.Error(), (char *)e.Description());

}

// Check for non COM errors being thrown

catch(...)

{

_tprintf(_T("Non-COM error"));

}

}

你可能感兴趣的:(vc++)