Author Topic: Loss of Comms indication  (Read 1207 times)

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Loss of Comms indication
« on: December 07, 2015, 07:41:15 PM »
Archie, I know this may have come up in previous post but I didn't find one to solve my issue.  I want to show a BasicLabel when comms is lost to a Modbus device.  I know others have used a timer in a PLC and were able to do this but my installation does not use a PLC, just a Modbus controller with no clock or timers.  I am able to accomplish this now by using Modbus.Read(40001) and look at some random register with a value.  This method works great when comms is ok ....but this locks up the Application when comms is lost and makes the screens unresponsive.  I want to use the Synchronous controls to do this to prevent this freeze-up(datasubscriber etc..).  I understand the ConnectionEstablished & ComError event handlers do not work in 3.99a.  How can I accomplish this in 3.99a?  Thank you!   

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Loss of Comms indication
« Reply #1 on: January 03, 2016, 02:17:07 PM »
So I took a crack at this and came up with a very crude but effective solution that I hope others can use.  My basic goal was to indicate when comms to a device is lost without locking up the application.  This solution flashes a Label that I put "Loss of Comms" in the text field and works in conjunction with a BasicLabel control and Timer.  I point the BasicLabel to a register that I expect only an integer and triggers on the presence of text from Archie's error messages.  Please let me know if you have a better or simpler solution.  Thanks

  Private Sub CommLossLabel_TextChanged(sender As Object, e As EventArgs) Handles CommLossLabel.TextChanged 'initiates Loss of Comms display by looking for any text in label value
        If Integer.TryParse(CommLossLabel.Text, Nothing) Then
            CommLossTimer.Enabled = False
            Label2.Visible = False
        Else : CommLossTimer.Enabled = True
            Label2.Visible = True
        End If

    End Sub

    Private Sub CommLossTimer_Tick(sender As Object, e As EventArgs) Handles CommLossTimer.Tick  'handles Loss of Comms display interval
        If Label2.Visible = True Then
            Label2.Visible = False
        ElseIf Label2.Visible = False Then
            Label2.Visible = True
        End If
    End Sub