AnsweredAssumed Answered

Guidance required on PIDataPipe GetObserverEvents method (AF SDK)

Question asked by amitpatil.vit on Apr 10, 2019
Latest reply on Apr 14, 2019 by John Messinger

Hi All,

 

I am currently testing datapipes with a simple vb.net console application using 2 methods (GetUpdateEvents and GetObserverEvents). GetUpdatedEvents worked fine for me but I am struggling with GetObserverEvents method.

 

I have referred a blog from 2015 on datapipes. Link is specified below.

How to use the PIDataPipe or the AFDataPipe

 

I referred c# program and tried implementing in vb.net program but I am struggling with subscribe method (even after adding a derived class for iObserver).

Can someone please guide me on the last piece (subscribe and print results)?

 

    Private Sub Test_PI_Datapipe()

         

        Try

            Dim temp_srv, temp_tag As String

            Dim temp_option As Int16

            Dim myPIServer As PIServer

            Dim pipoint1, pipoint2 As PIPoint

 

            Dim _piDataPipe As PIDataPipe

            Dim pointList1 As IList(Of PIPoint)

            Dim AF_Errors_Value As AFErrors(Of PIPoint)

 

            Dim DPType As AFDataPipeType

            Dim DataPipeEvent As AFDataPipeEvent

 

            Console.WriteLine() 'Blank line

            Console.WriteLine("Test PI Data Pipe")

            Console.Write("Enter  PI Server name to be connected: ")

            temp_srv = Console.ReadLine()

            myPIServer = g_PIServers.Item(temp_srv)

 

            Console.Write("Enter PI Tag name: ")

            'Add tag to be monitored and get AF errors if any

            temp_tag = Console.ReadLine()

            pipoint1 = PIPoint.FindPIPoint(myPIServer, temp_tag)    'One tag entered by user

            pipoint2 = PIPoint.FindPIPoint(myPIServer, "ba:temp.1") '2nd hardcoded tag for testing

 

            pointList1 = New PIPointList From {pipoint1} 'Important to initialize, use from method to initiate while instantiating

            pointList1.Add(pipoint2)   'Alternate method of initializing (if not used with from)

 

            DPType = Data.AFDataPipeType.Snapshot          'Choose type as Snapshot or Archive or Timeseries

            _piDataPipe = New PIDataPipe(DPType)  'alternate option is to pass the type directly

            AF_Errors_Value = _piDataPipe.AddSignups(pointList1)

 

            Console.Write("Enter 1 for GetUpdatedEvents, Enter2 for GetObserverEvents : ")

            temp_option = Convert.ToInt16(Console.ReadLine())

 

            Dim i As Int16

            Dim temp_bool As Boolean

 

            Select Case temp_option

                Case 1

                    'Method1 GetUpdatedEvents

                    While i <= 10

                        Dim UEvents = _piDataPipe.GetUpdateEvents(100)

                        For Each DataPipeEvent In UEvents.Results

 

                            Console.WriteLine("PIDataPipe Event - {4} - Tag Name: {0}, Action Type: {1}, Value {2}, TimeStamp: {3}", DataPipeEvent.Value.PIPoint.Name, DataPipeEvent.Action.ToString(), DataPipeEvent.Value.Value, DataPipeEvent.Value.Timestamp.ToString(), DPType.ToString())

                        Next

                    End While

                Case 2

                    'Method2 GetObserverEVensts (Required derived class references)

                    '_piDataPipe.Subscribe(New PIConsoleDataReceiver(AFDataPipeType.Snapshot))

                    Dim iobserver1 As New PIConsoleDataReceiver

                    iobserver1.PIConsoleDataReceiver(AFDataPipeType.Snapshot)

                    'Subscribe

                    _piDataPipe.Subscribe(iobserver1)

                    'Use Get Observer events

                    _piDataPipe.GetObserverEvents(100, temp_bool)

 

            End Select

 

            '_piDataPipe.Dispose()   'Release resources

 

        Catch ex As Exception

            Console.WriteLine(ex.Message)

        End Try

    End Sub

 

 

Public Class PIConsoleDataReceiver

    'How to use the PIDataPipe or the AFDataPipe (PI Square ref)

 

 

    Implements IObserver(Of AFDataPipeEvent)

 

 

    Private _dataPipeType As AFDataPipeType

    'Private _datapipeevent As AFDataPipeEvent

    Public Sub PIConsoleDataReceiver(afDataPipeType As AFDataPipeType)

        _dataPipeType = afDataPipeType

    End Sub

 

 

    Public Sub OnNext(value As AFDataPipeEvent) Implements IObserver(Of AFDataPipeEvent).OnNext

        'Throw New NotImplementedException()

        Console.WriteLine("PIDataPipe event - {4} - Tag Name: {0}, Action Type: {1}, Value {2}, TimeStamp: {3}", value.Value.PIPoint.Name, value.Action.ToString(), value.Value.Value, value.Value.Timestamp.ToString(), _dataPipeType)

    End Sub

 

    Public Sub OnError([error] As Exception) Implements IObserver(Of AFDataPipeEvent).OnError

        'Throw New NotImplementedException()

        Console.WriteLine("Provider has sent an error.")

       

    End Sub

 

    Public Sub OnCompleted() Implements IObserver(Of AFDataPipeEvent).OnCompleted

        'Throw New NotImplementedException()

        Console.WriteLine("Provider has terminated sending data.")

    End Sub

End Class

Outcomes