Following on from
converting a PIModuleDB to AF Elements & Attributes, here are some code snippets to show how to achieve in AF what you used to do in PIModule Database.
Connecting to the PIModuleDB
Code:
' PISDK
Dim PIMDB As PISDK.PIModuleDB = New PISDK.PISDK().Servers.DefaultServer.PIModuleDB
' AFSDK - PISDK.PIModuleDB = AFSDK.AFDatabase
Dim AFMDB As OSIsoft.AF.AFDatabase = New OSIsoft.AF.PISystems().DefaultPISystem.Databases.DefaultDatabase
Retrieving a PIModule
Code:
' PISDK
Dim PIMod As PISDK.PIModule = PIMDB.PIModules("ModuleName").PIModules("1").PIModules("2").PIModules("3")
' AFSDK - PISDK.PIModule = AFSDK.Asset.AFElement
Dim AFEmnt As OSIsoft.AF.Asset.AFElement = AFMDB.Elements("ModuleName").Elements("1").Elements("2").Elements("3")
Retrieving a PIProperty
Code:
' PISDK
Dim PIProp As PISDK.PIProperty = PIMod.PIProperties("Property1")
Dim sPIProp As String = PIProp.Value().ToString()
' AFSDK - PISDK.PIProperty = AFSDK.Asset.AFAttribute
Dim AFAtt As OSIsoft.AF.Asset.AFAttribute = AFEmnt.Attributes("Property1")
Dim sAFAtt As String = AFAtt.GetValue().ToString()
Retrieving a PIAlias
Code:
' PISDK
Dim PIAls As PISDK.PIAlias = PIMod.PIAliases("MyPIAlias")
Dim oPIAls As PISDK.PIValue = CType(PIAls.DataSource.Data.Snapshot.Value(), PISDK.PIValue)
' AFSDK - PISDK.PIAlias = AFSDK.Asset.AFAttribute using PI Point Data Reference
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
This is only a small set of what can be achieved using the PI Analysis Framework and RJK Solutions actively encourage you to get using AF as soon as possible!
Principal Consultant
Real-Time Data Management @ Wipro Technologies