Author Topic: Error at form Load  (Read 1269 times)

chunt

  • Newbie
  • *
  • Posts: 14
    • View Profile
Error at form Load
« on: June 18, 2014, 08:53:58 AM »
This is the code for my start screen which is the first screen to load when the program is started. Occasionally I get and error that shuts down the program. I have the error information paste bellow as well.  You can see in my code that I am looking for my heartbeat that is being generated by the PLC so that I can confirm communication. Are there other ways to do that? What is the best way to confirm that I have comms with the PLC before my code begins to execute, such as waiting until I have communications until the timer starts. I know that there is a CommunicationEstablished event for the ethernet driver but I had no success with that. Thanks in advance for the help.
 
Public Class StartScreen

    Private Sub StartScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Threading.Thread.Sleep(1000)
        Timer1.Start()
    End Sub
    Private Sub BevelButtonDisplay1_Click(sender As Object, e As EventArgs) Handles BevelButtonDisplay1.Click
        ShuttleScreen.Show()
    End Sub
    Private Sub BevelButtonDisplay3_Click(sender As Object, e As EventArgs) Handles BevelButtonDisplay3.Click
        InkDelivery.Show()

    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        Dim A As Integer = EthernetIPforCLXCom1.Read("HeartBeatTimer1.ACC")
        If A >= 500 Then
            HeartBeatIndicator.Show()
        Else
            HeartBeatIndicator.Hide()
        End If
    End Sub
 
End Class



This is the error that I get occassionaly when my form loads:
An unhandled exception of type 'MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException' occurred in MfgControl.AdvancedHMI.Drivers.dll

'This line of code is highlighted in the Ethernet driver code:
DLL(MyDLLInstance).ReadTagValue(PLCAddressByTNS(SequenceNumbershort), numberOfElements, CUShort(SequenceNumber))

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5271
    • View Profile
    • AdvancedHMI
Re: Error at form Load
« Reply #1 on: June 18, 2014, 09:01:40 AM »
You should always wrap your reads/writes in a Try-Catch block. Any communication fault will throw and exception.
Code: [Select]
Dim A As Integer
Try
  A = EthernetIPforCLXCom1.Read("HeartBeatTimer1.ACC")
Catch ex as Exception
  msgbox ex.message
End Try

chunt

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Error at form Load
« Reply #2 on: June 18, 2014, 11:12:11 AM »
Excellent, thanks. I will start using the recommended Try/catch. Thanks for the quick response and great product.