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

Rapid PI - ProcessBook Enums to AF Enumeration Sets Options · View
RJK Solutions
#1 Posted : Monday, August 03, 2009 8:48:10 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 409
Location: Cheshire, United Kingdom.
Ever wanted the Enums used in ProcessBook to be available in AF for your custom applications? Well RJK Solutions wanted the exact same thing and have the following solution for you to use...we did the hard work so you don't have to!

Firstly some small pre-work has to be done.
The type libraries for the ProcessBook Object and Symbol libraries need to become an assembly so we can use Reflection to load them in our .Net code. Once we have the assembly then we can look for the Enums and parse them.
To create the assemblies we are going to use the tool tlbimp (which as the name suggests is a type library importer) - you can read more about it on MSDN.

Simply run a command that imports the relevant library and output to an assembly. In this example our PI Home directory is "C:\Program Files\PIPC\" so we run:
Code:

tlbimp "C:\Program Files\PIPC\ProcBook\PISymLib.tlb" /out:"C:\PISymLib.dll"
tlbimp "C:\Program Files\PIPC\ProcBook\PIObjLib.tlb" /out:"C:\PIObjLib.dll"


There we have it, 2 assemblies that we can load using Reflection in .Net. The following code demonstrates how to do exactly that:

Code:

Private Sub Enums()
    Dim PBSymLibDLL As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile("C:\Pbsymlib.dll")
    For Each oTyp As Type In PBSymLibDLL.GetTypes()
        Try
            If oTyp.IsEnum Then
                ParseEnums(oTyp.Name, oTyp)
            End If
        Catch ex As Exception
        End Try
    Next
End Sub

Private Sub ParseEnums(ByVal sEnum As String, ByVal oEnum As System.Type)
    Dim ES As OSIsoft.AF.Asset.AFEnumerationSet = myAFDB.EnumerationSets(sEnum)
    If ES Is Nothing Then
        ES = myAFDB.EnumerationSets.Add(sEnum)
        Dim n As Object
        For Each n In System.Enum.GetValues(oEnum)
            Try
                ES.Add(System.Enum.GetName(oEnum, n), n)
            Catch ex As Exception
            End Try
        Next
        ES.CheckIn()
    End If
End Sub


The variable "myAFDB" is an AFDatabase object.

What you end up with is something like the following:



OSIsoft PI System Specialists
PI consultancy on PI Systems, PISDK, AFSDK, OLEDB etc and PI custom developments. Well pretty much anything to do with PI!


Sponsor  
 
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.