Author Topic: Comm loss/Updating data message  (Read 1119 times)

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Comm loss/Updating data message
« on: December 17, 2014, 09:46:28 AM »
I am wanting to add a indication that data is being updated when a form is opened so that the user only sees valid data.  Also this indication would serve as a "loss of comms" indicator.  I added a basiclabel to my form that is present for 3 seconds and reads a register in the controller that holds the month.  If this value is greater than zero then hide the message else show the BasicLabel64. Code below

 Private Sub DGC1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        BasicButton1.Hide()
        BasicButton2.Hide()
        BasicLabel64.Show()
        Timer2.Enabled = True

    End Sub

 Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        If ModbusTCPCom1.Read(40700) > 0 Then ' read month from controller
            BasicLabel64.Hide()
        Else : BasicLabel64.Show()
        End If
    End Sub

This seems to work great until I actually get a loss of comms then I get the attached exception.  what am I doing wrong? Thanks

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Comm loss/Updating data message
« Reply #1 on: December 18, 2014, 12:06:13 AM »
After a bunch of messing around, I found this to be a working solution.  I use a basicLabel and set the text to "COMMS UPDATING" then use this code below.  My concern was that values would still display even if comms was lost to the controller thus leading to invalid conclusions by the operator.  This atleast gives the indication that comms is lost.  Hope its helpful to someone else too :)

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        Try
            If ModbusTCPCom1.Read(40700) > 0 Then 'read month from controller
                BasicLabel64.Hide()
            End If
        Catch ex As Exception
            BasicLabel64.Show()
        End Try