Author Topic: How To Determine If Last PLC Tag Read Was Not Successful  (Read 1034 times)

usapatriotforlife

  • Newbie
  • *
  • Posts: 39
    • View Profile
How To Determine If Last PLC Tag Read Was Not Successful
« on: August 26, 2017, 08:12:09 PM »
Hello, Archie,

When using an AdvancedHMIControls.BasicLabel attached to an AdvancedHMIDrivers.EthernetIPforCLXcom using version AHMI 3.99e over an unreliable Ethernet connection, I sometimes see in the BasicLabel a message about "Timed Out reading ...." or "Unable to connect to ....". 

I understand that I can suppress these messages by setting the BasicLabel object property "SuppressErrorDisplay" to true, but what I'm looking for is a way to know that an error occurred when reading the PLC tag the last time around.  From my testing, it appears that during these errored times, if I were to check the value of the BasicLabel in question, it would be the value of the last successful read.  I do not see a property or event helping me to know that an error occurred during the last PLC tag read attempt.  I feel that I must be overlooking something because this would be such a basic thing to have and to know.

So, the question is, how can I tell when the last read of a tag failed?

Just a bit more info:  I have multiple BasicLabels that read various tags from the PLC.  Not all will fail, just some based on I guess some sort of randomness in the poll rate cycles.  I'm interested in knowing when a specific object, in this case a BasicLabel, was unable to read the tag at the last poll time.

Thanks!

Ken Sumrall

« Last Edit: August 26, 2017, 08:13:51 PM by usapatriotforlife »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: How To Determine If Last PLC Tag Read Was Not Successful
« Reply #1 on: August 26, 2017, 08:43:43 PM »
You could handle the TextChanged event like this:
Code: [Select]
   Private Sub BasicLabel1_TextChanged(sender As Object, e As EventArgs) Handles BasicLabel1.TextChanged
        Dim bl As AdvancedHMIControls.BasicLabel = DirectCast(sender, AdvancedHMIControls.BasicLabel)
        If bl.Text.IndexOf("Timed out", 0, StringComparison.CurrentCultureIgnoreCase) >= 0 Then
            MsgBox(bl.Name & " errored")
        End If
    End Sub

usapatriotforlife

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: How To Determine If Last PLC Tag Read Was Not Successful
« Reply #2 on: August 27, 2017, 07:37:47 PM »
Hi, Archie,

Thank you for that idea.  Going off of what you suggested, since I have a timer that runs every 5 seconds to poll the values of each basiclabel for a particular PLC, can I assume that each and every time I check a basiclabel that value and text would be equal if the PLC was read successfully and not equal if there was an error reading the PLC tag?  Following this train of thought, maybe I should just read the text property and perform error checking.  What do you suggest?  I will run some tests to see if value = text on good reads, but your insight in to whether this is consistent or advisable to do would be greatly appreciated.

Thanks for this awesome product and the time you put in to it.

Ken Sumrall

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: How To Determine If Last PLC Tag Read Was Not Successful
« Reply #3 on: August 27, 2017, 09:39:42 PM »
Comparing Value and Text could be a good way of doing it. This will only work if you are not using Prefix and suffix. So to modify the code snippet:
Code: [Select]
Private Sub BasicLabel1_TextChanged(sender As Object, e As EventArgs) Handles BasicLabel1.TextChanged
        Dim bl As AdvancedHMIControls.BasicLabel = DirectCast(sender, AdvancedHMIControls.BasicLabel)
        If bl.Text <> bl.Value Then
            MsgBox(bl.Name & " errored")
        End If
    End Sub

usapatriotforlife

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: How To Determine If Last PLC Tag Read Was Not Successful
« Reply #4 on: September 04, 2017, 04:30:05 PM »
Hi, Archie,

I have determined through testing that when a BasicLabel loses connection to a PLC that its displayed text alternates between the last value it was able to read and an error messages such as "Unable to connect to xxx".  I never implemented the textchanged event, I just watched the basiclabel displayed text switch back and forth in my program.  So, if what is visually changing on the screen is truly just a "display" and not the underlying value in the text property then comparing value to text would work.

The PLC programmer is going to design an incrementing counter for me to check.  If I read the counter and see that it isn't incrementing then I'll know that the PLC is offline or having issues.  I've also built a timer to ping the PLC every 30 seconds.  If the code can ping the plc, the timer sets DisableSubscriptions to False.  If not, it sets DisableSubscriptions to true.

My two cents are that I feel like the BasicLabel "knows" when it can't read data and ought to be able to set a property indicating no value was read last time, but I'm not complaining because AHMI already does so much and is so awesome.


Any and all advice is very much appreciated. 

Ken Sumrall

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: How To Determine If Last PLC Tag Read Was Not Successful
« Reply #5 on: September 04, 2017, 07:30:58 PM »
My two cents are that I feel like the BasicLabel "knows" when it can't read data and ought to be able to set a property indicating no value was read last time, but I'm not complaining because AHMI already does so much and is so awesome.
Technically speaking from an AdvancedHMI perspective, the Basiclabel doesn't actually "read" data. Instead it requests a subscription from the driver which in turn supplies the values when returned from the PLC. If there is an error such as no connection, the driver will fire an event to indicate this. The BasicLabel creates a handler for this event. If you look at the code in BasicLabel.vb at about line 765, you will see the handler:

Code: [Select]
   Private Sub DisplaySubscribeError(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        DisplayError(e.ErrorMessage)
    End Sub

The DisplayError routine will set the Text property to the error and set a timer. After the timer expires it will revert the text back to its previous value.