Author Topic: Handling loss of ethernet communications with EthernetIPforCLXCom  (Read 5145 times)

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Using v3.83 and Visual Studio 2013.

How can I gracefully handle loss of ethernet communications with my plc?  When I unplug the ethernet cable, I got this unhandled exception. 

An unhandled exception of type 'System.NullReferenceException' occurred in AdvancedHMIDrivers.dll
Additional information: Object reference not set to an instance of an object.

Ideally, I would like to display a message that communications to the plc have been lost and then clear the message when communications have been reestablished.

Thanks

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #1 on: January 07, 2015, 06:07:25 PM »
I just tried this with version 3.97, that will be posted tonight, and it does not throw and exception when disconnecting the Ethernet cable.

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #2 on: January 08, 2015, 08:12:13 AM »
I have a huge program based on version 3.83 that has a couple dozen classes and forms.  What is the most effective way of upgrading to the 3.97 version?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #3 on: January 08, 2015, 08:39:20 AM »
You should be able to replace the AdvancedHMI directory in the new solution with your AdvancedHMI project directory. Then open the new Solution and Build->Clean and Build->Rebuild All

This works as long as your current project is newer than version 3.80

If you get any errors, let me know and I will guide you through them

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #4 on: January 08, 2015, 12:10:52 PM »
Thanks, I will give it a try today.

Is there a way to query EthernetIPforCLXCom to see if it is connected?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #5 on: January 08, 2015, 01:10:45 PM »
There is a Connected event and ConnectionClosed event that you can add handlers for.

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #6 on: January 08, 2015, 01:32:44 PM »
Scott,

I wanted to share an idea that I have used extensively in the past to handle this.
The reason that I like to do it this way is that there are many variables that can affect communications.
Trying to use one of these internal items can sometimes be questionable at best.

The concept is to build a timer driven function and read a constantly changing variable in the PLC.
Normally I like to set up a variable of the PLC's internal clock and map it to a seconds variable.
An alternate is just to use a 60 second counter and reset when the count is 60.

Inside the subroutine you create variable to saving the last seconds and a count of the missed changes.
When it executes it checks to see if the stored value for seconds matches the current seconds.
If so that save the current seconds into the saved value, reset a comm loss flag and exit.
If not then increment a missed counter and check if the values exceeds your miss maximum to declare comm loss.
If the maximum has occurred then set your comm loss flag and exit.

Now you are not depending upon anything other than the basic functionality or reading a tag.
Here is an example:
Code: [Select]
Public CommsOK As Boolean   ' Needs to be a global variable

Private Function CommsChkOK(Seconds As Integer) As Boolean

Static TIMER As Integer      ' Last Seconds storage
Static BadCount As Integer
Dim MaxBad As Integer

MaxBad = 10                   'Set your maximum seconds until failure here

If (TIMER <> Seconds) Then
    BadCount = 0              'Zero failed communication count
    TIMER = Seconds        'Save last Seconds
Else
    BadCount = BadCount + 1   'Add one to Failed Communication count
End If


If (BadCount >= MaxBad) Then
    BadCount = MaxBad        'Keeps BadCount from overflowing
    CommsChkOK = False       'Alarm Failed Communications
Else
    CommsChkOK = True        'Clear Alarm
End If

End Function

Private Sub Timer1_Timer()    ' Timer enabled and set to 1 sec (1000)

Debug.Print Second(Now())
' Call CommsChkOK(PLCSeconds) here

' Debug.Print CommsChkOK(Second(Now())) 'Demonstrate good
Debug.Print CommsChkOK(21)              'Demonstrate bad

End Sub

Let me know if you have any questions.

Doug Lyons
« Last Edit: January 08, 2015, 01:38:46 PM by DougLyons »

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #7 on: January 08, 2015, 05:30:44 PM »
I have successfully updated my AdvancedHMI from 3.83 to 3.97 using the method you described.

It no longer generates an exception if the ethernet to the plc is disconnected, and it does reconnect and update display values when plugged back in.

I do get an exception in my DataSubscriber changed event.   "Conversion from string "True" to type 'Double' is not valid."  This happens on read of a real tag data type.  This is probably not a big deal.

« Last Edit: January 08, 2015, 05:42:50 PM by scott.clark »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #8 on: January 08, 2015, 05:37:14 PM »
It should restart again. I will try it tonight.

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #9 on: January 08, 2015, 05:45:24 PM »
Archie,
sorry, I think I accidentally started up the old 3.83 version when I did the test.  I have now tested it several times with the 3.97 version it is working.  I re-edited my post to correct this error.
Thanks

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #10 on: January 08, 2015, 10:05:53 PM »
I do get an exception in my DataSubscriber changed event.   "Conversion from string "True" to type 'Double' is not valid."  This happens on read of a real tag data type.  This is probably not a big deal.
What is the data type of the tag you are subscribing to?

scott.clark

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #11 on: January 08, 2015, 11:52:06 PM »
I have a mixture of tags: 20 bools, 6 reals, 10 dints, a real array of 10 elements, and a dint array of 10 elements.  The exception was generated when the ethernet cable was disconnected from the pc running the 3.83 version.  The address of the the tag that was generated was of a single real tag being read.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5260
    • View Profile
    • AdvancedHMI
Re: Handling loss of ethernet communications with EthernetIPforCLXCom
« Reply #12 on: January 09, 2015, 04:39:54 AM »
It sounds like something was getting crossed up with BOOL data trying to be send back to a subscription for a Real tag. Does this still happen in V3.97?