YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Accessing PI tags using AFSDK Options · View
Kittu_Th
#1 Posted : Tuesday, June 30, 2009 10:55:14 PM
Rank: Newbie
Groups: Member

Joined: 6/30/2009
Posts: 4
Location: USA
Hi,

I am new to PI, I have to update the PI tag value using AFSDK in .net. not directly using PI sdk.
Is it possible to do it? If yes, how?.
I tried this, but now don't know how to proceed further...

DateTime dtQueryDate = dtGetDatePicker.Value;
PISystems myAFSystems = new PISystems();
myAFSystem = myAFSystems[txbPISystem.Text];
myAFDB = myAFSystem.Databases[databasename];
AFDatabase queriedAFDB = myAFDB.ApplyQueryDate(dtQueryDate);
Int32 intElements;
AFNamedCollectionList<AFElement> AFElementsList
= AFElement.FindElements(queriedAFDB,
null,
"*",
AFSearchField.Name,
true,
AFSortField.Name,
AFSortOrder.Ascending,
1000);
lstElements.Items.Clear();
foreach (AFElement item in AFElementsList)
{
lstElements.Items.Add(item.Name);
AFAttributes itemAttr = item.Attributes;
foreach (AFAttribute attr in itemAttr)
{
AFValue val = attr.GetValue();

/*AFDataReference reff = attr.DataReference;
//if (reff.IsConfigured())
if (reff != null)
{
AFPlugIn plg = reff.PlugIn;
}*/

/* How can I get the PIPoint object here */
}

}

Thanks,
Sponsor  
 

OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System.
We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ  or contact OSIsoft vCampus for more details.
RJK Solutions
#2 Posted : Wednesday, July 01, 2009 9:15:42 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
Hi Kittu_Th,

Welcome to the forum.

You can simply use the AFValue.ToPIValue method to retrieve a PISDK.PIValue object. From here you can get to the PISDK.PIPoint object and update the data. Alternatively, you can use the AFValue.FromPIValue method to update the AFValue from a PISDK.PIValue object.

Rhys.
Principal Consultant
Real-Time Data Management @ Wipro Technologies
Kittu_Th
#3 Posted : Wednesday, July 01, 2009 8:13:12 PM
Rank: Newbie
Groups: Member

Joined: 6/30/2009
Posts: 4
Location: USA
Thanks for your reply, It would be nice if you can post the code also.

RJK Solutions
#4 Posted : Wednesday, July 01, 2009 11:00:39 PM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
Sure...take a look at this thread also.

Code:

Dim AFAls As OSIsoft.AF.Asset.AFAttribute = AFEmnt.Attributes("MyPIAlias")
If AFAls.DataReference.Name = "PI Point" Then ' Important to check the AF DataReference
    Dim vAFAls As OSIsoft.AF.Asset.AFValue = AFAls.GetValue()
    Dim oAFAls As PISDK.PIValue = CType(vAFAls.ToPIValue(), PISDK.PIValue)
End If
Principal Consultant
Real-Time Data Management @ Wipro Technologies
Kittu_Th
#5 Posted : Thursday, July 09, 2009 7:53:38 PM
Rank: Newbie
Groups: Member

Joined: 6/30/2009
Posts: 4
Location: USA
Thanks a lot for all your help.
One more question, can we update the value of the PI tag from AFSDK.
I tried below code sometime it works but some time it is giving null pointer exception at 'SelPIPoint.Data line.
Am I doing something wrong here? Would appreciate your help.

AFAttribute attr = AFelem.Attributes("BHT");
if (attr.DataReference.Name =="PI Point) then
{
PIPoint SelPIPoint = (PISDK.PIPoint)attr.RawPIPoint;
PISDK.PIData ptData = SelPIPoint.Data;
ptData.UpdateValue(newValue, 0, PISDK.DataMergeConstants.dmInsertDuplicates, null);
}
RJK Solutions
#6 Posted : Monday, July 20, 2009 8:47:46 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
If the security context you connect to AF with has write permission and your PI Point Data Reference for your AFAttribute is not read only then you can update PI using the SetValue() method of an AFAttribute.

Example:

Dim AV As New Asset.AFValue(newValue, New Time.AFTime("*"))
attr.SetValue(AV)

Principal Consultant
Real-Time Data Management @ Wipro Technologies
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.