Author Topic: DataSubscriber2 values  (Read 1384 times)

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
DataSubscriber2 values
« on: February 19, 2018, 03:11:36 PM »
Hey Archie, can you tell me if I can access the two items in the collection of PLC addresses of the DS2 at the same time?  What I mean is I add addr 1-4 to the collection and I want to do some math of two of the elements such as addr1/addr2 on DS2 value change event.  Is this possible?  How do I access each element to do this?  Thank you.   

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5261
    • View Profile
    • AdvancedHMI
Re: DataSubscriber2 values
« Reply #1 on: February 19, 2018, 04:21:02 PM »
When you add multiple items to a DataSubscriber2 item list, they will each return on their own event. To perform math on multiple values, you will need to store them locally something like this:

Private Var1, Var2 as string
Private Sum as string

Private DataChangedEvent ..........
    If e.ErrorID= then
       If e.PLCAddress="40001" then
             Var1=e.Values(0)
       ElseIf e.PLCAddress="40001" then
              Var2=e.Value(0)
       End if
    End IF

    If NOT String.IsNullOrEmpty(Var1) and NOT String.IsNullOrEmpty(Var2) then
          Sum=Cint(Var1) + Cint(Var2)
    End If
End Sub

Katriel

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: DataSubscriber2 values
« Reply #2 on: March 13, 2018, 05:46:38 PM »
I am pretty new at this and have been setting up some plant area overviews and my boss requested some email alerts for certain events.  When the event was a specific alarm in the PLC, it was easy to set up about 100 DataSubscriber from the tool box, double click and have your auto code generated for data change to call a Private Sub SendEmailMessage("Event One Happened") so I used the same email sub for all the messages.  I should mention that this is currently 21 control logix PLCs for all of these connections and messages.  Now, I am wondering if I can consider using some more logic in my Subs so that perhaps I look at the status of two PLC tags and only alert when specific conditions occur.  I was wondering about grabbing multiple tags using DataSubscriber2 to get a few words and then trying to compare if tag[0].0 and tag[1].3 then SendEmailMessage("Nut 2 missing") and of course have multiple items considered (critical alarms for the station).  I have seen the examples of a popup to display the data from the DataSubscriber2 but not really an example of how to work with the values of multiple variables, at the same time.

Godra

  • Hero Member
  • *****
  • Posts: 1436
    • View Profile
Re: DataSubscriber2 values
« Reply #3 on: March 13, 2018, 09:08:10 PM »
The answer to your multiple tags inquiry seems to be in Archie's post prior to yours.

You can use as much logic as you want in your Subs (virtually until the point that your computer's performance starts degrading).

So, instead of doing the math as presented in Archie's post, just do the comparison of the values and send an e-mail if necessary.