Author Topic: DataSubscriber2 and inital DataChanged event  (Read 1490 times)

boilerkdw

  • Newbie
  • *
  • Posts: 1
    • View Profile
DataSubscriber2 and inital DataChanged event
« on: September 16, 2016, 02:39:58 PM »
When the AHMI executable is started, it appears that the DataChanged event is fired, even if no data has changed in the PLC.  What would be a good way to catch this initial event, so that it could be handled differently than what one would want for an actual change in PLC data?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5323
    • View Profile
    • AdvancedHMI
Re: DataSubscriber2 and inital DataChanged event
« Reply #1 on: September 16, 2016, 03:13:46 PM »
By default on startup, the software has no reference to the value in the PLC, so the first read is a change in the eyes of AdvancedHMI. If you wanted to filter this, you would need to add some code to tell it to ignore the first DataChange of each PLCAddressItem.
Code: [Select]
    '* Make sure the array has the same amount of elements as the DataSubscriber has PLCAddressItems
    Private InitialReadComplete(10) As Boolean
    Private Sub DataSubscriber21_DataChanged_1(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
        Dim index As Integer
        While index < DataSubscriber21.PLCAddressValueItems.Count
            If e.PlcAddress = DataSubscriber21.PLCAddressValueItems(index).PLCAddress Then
                If Not InitialReadComplete(index) Then
                    InitialReadComplete(index) = True
                Else
                    '**** Perform the normal action here ************
                End If
                Exit While
            End If
            index += 1
        End While
    End Sub