Author Topic: Displaying Tag Description  (Read 1418 times)

cjmcc

  • Newbie
  • *
  • Posts: 4
    • View Profile
Displaying Tag Description
« on: December 01, 2020, 10:49:22 AM »
Hello!

I am trying to log some data and would like to include a description along with the tag name and value. I have tried a couple of ways with out any luck.

Currently I am stuck on Error BC30469 Reference to a non-shared member requires an object reference.

Does anyone have a better way to do this?

The text document is formated:

TagName,ScaleFactor,ScaleOfset,Description

Most of this code is from the documentation page under Configuring a DataSubscriber2 with a CSV file.

Code: [Select]
    Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
        DataSubscriber21.BeginInit()
        Using sw As New System.IO.StreamReader("MyConfigFile.txt")
            Dim LineFromFile As String
            Dim Settings() As String
            Dim NewPLCAddressItem As MfgControl.AdvancedHMI.Drivers.PLCAddressItem
            While Not sw.EndOfStream
                LineFromFile = sw.ReadLine
                Settings = LineFromFile.Split(",")
                NewPLCAddressItem = New MfgControl.AdvancedHMI.Drivers.PLCAddressItem
                NewPLCAddressItem.PLCAddress = Settings(0)
                If Settings.Length > 1 Then
                    NewPLCAddressItem.ScaleFactor = CDbl(Settings(1))
                End If
                If Settings.Length > 2 Then
                    NewPLCAddressItem.ScaleOffset = CDbl(Settings(2))
                End If
                If Settings.Length > 3 Then
                    NewPLCAddressItem.Description = Settings(3)
                End If
                DataSubscriber21.PLCAddressValueItems.Add(NewPLCAddressItem)
            End While
        End Using
        DataSubscriber21.EndInit()
        Using sw As New System.IO.StreamWriter("LogFile.txt", True)
            sw.WriteLine(Now & " - " & e.PlcAddress & " " & e.Values(0) & MfgControl.AdvancedHMI.Drivers.PLCAddressItem.Description)
        End Using
    End Sub

Thanks!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5270
    • View Profile
    • AdvancedHMI
Re: Displaying Tag Description
« Reply #1 on: December 01, 2020, 11:53:45 AM »
Form what I see in your code, you are re-adding subscriptions to a DataSubscriber every time a value changes. This will quickly run you out of memory after the subscription list reaches in the millions.

cjmcc

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Displaying Tag Description
« Reply #2 on: December 01, 2020, 12:54:00 PM »
Can you think of a better way to do this? Or point me in the right direction?

I need to monitor every INput or Output change on a PLC and then log them somewhere.

Thanks!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5270
    • View Profile
    • AdvancedHMI
Re: Displaying Tag Description
« Reply #3 on: December 01, 2020, 01:01:40 PM »
First off this code needs to be where it will only be executed once, such as a Load Event:
Code: [Select]
        DataSubscriber21.BeginInit()
        Using sw As New System.IO.StreamReader("MyConfigFile.txt")
            Dim LineFromFile As String
            Dim Settings() As String
            Dim NewPLCAddressItem As MfgControl.AdvancedHMI.Drivers.PLCAddressItem
            While Not sw.EndOfStream
                LineFromFile = sw.ReadLine
                Settings = LineFromFile.Split(",")
                NewPLCAddressItem = New MfgControl.AdvancedHMI.Drivers.PLCAddressItem
                NewPLCAddressItem.PLCAddress = Settings(0)
                If Settings.Length > 1 Then
                    NewPLCAddressItem.ScaleFactor = CDbl(Settings(1))
                End If
                If Settings.Length > 2 Then
                    NewPLCAddressItem.ScaleOffset = CDbl(Settings(2))
                End If
                If Settings.Length > 3 Then
                    NewPLCAddressItem.Description = Settings(3)
                End If
                DataSubscriber21.PLCAddressValueItems.Add(NewPLCAddressItem)
            End While
        End Using
        DataSubscriber21.EndInit()

To get the description you are assigning to the PLCAddressItem object, you will need to hunt to see which one has returned a data change. Something like this:

Code: [Select]
Dim index as integer
While index<DataSubscriber21.PLCAddressValueItems.Count  ANDALSO e.PLCAddress<>DataSubscriber21.PLCAddressValueItems(index).PLCAddres
   index++;
End While

Now you will have the index of the item that was returned where you can get the description

DataSubscriber21.PLCAddressValueItems(index).Description