Author Topic: Exception thrown  (Read 1709 times)

bob1371

  • Newbie
  • *
  • Posts: 35
    • View Profile
Exception thrown
« on: November 30, 2017, 09:57:34 PM »
Hello,

Working on a new application for data collection. I've tried this a couple different times on 2 different computers and always get the same fault.

From my output screen.
Code: [Select]
About to read the data
Exception thrown: 'MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException' in MfgControl.AdvancedHMI.Drivers.dll

Here is the actual code. I've double checked my tags and looks like I have everything correct.
Any Idea's?
Thanks

Code: [Select]
  Private Sub DataSubscriber1_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataChanged
        If e.ErrorId = 0 AndAlso e.Values.Count > 0 AndAlso e.Values(0) = "True" Then
            Console.WriteLine("About to read the data")

            Dim MyValues0() As String = EthernetIPforCLXCom1.Read("look_doser_sn_pn_array[0]", 999)
            Dim MyValues8 As String = EthernetIPforCLXCom1.Read("MDY10")


            Console.WriteLine("All Data Read")

            '*Transfer the values to Excel

            '*Creates Excel file
            Using ExcelPackage As New OfficeOpenXml.ExcelPackage(New IO.FileInfo("C:\2220\Doser.xlsx"))
                ExcelPackage.Workbook.Worksheets.Add(MyValues8)
                Console.WriteLine("ws creation ok")

                '*Writes the Headers in Row 1
                ExcelPackage.Workbook.Worksheets(MyValues8).Cells("A1").Value = "...................................DOSER.................................."

                Console.WriteLine("header creation ok")

                ExcelPackage.Workbook.Worksheets(MyValues8).Cells("A1").AutoFitColumns()

                '*Loops to write data in correct columns
                For Index = 0 To MyValues0.Length - 1
                    Console.WriteLine("Element " & Index & "=" & MyValues0(Index))
                    Dim ws As OfficeOpenXml.ExcelWorksheet = ExcelPackage.Workbook.Worksheets(MyValues8)
                    Dim CellNum As String = "A" & (Index + 3)
                    ws.Cells(CellNum).Value = MyValues0(Index)
                Next
                Console.WriteLine("Doser OK")



                '*Saves.xlsl file
                ExcelPackage.Save()

            End Using
        End If
    End Sub


Godra

  • Hero Member
  • *****
  • Posts: 1436
    • View Profile
Re: Exception thrown
« Reply #1 on: December 01, 2017, 03:21:59 AM »
Archie, or somebody else, will probably have a better understanding of your code and possible cause for the exception.

For now, I would suggest that you try to catch that exception in a Try/Catch and display it, similar to this:

Code: [Select]
            Try
                Dim MyValues0() As String = EthernetIPforCLXCom1.Read("look_doser_sn_pn_array[0]", 999)
                Dim MyValues8 As String = EthernetIPforCLXCom1.Read("MDY10")
            Catch ex As Exception
                System.Windows.Forms.MessageBox.Show(ex.ToString)
            End Try

This might provide more info for the exception itself.
Breakpoints at the above two "Dim" lines would also work.

Could also place a BasicLabel on the form and set its PLCAddressValue to MDY10 and comment out the above two "Dim" lines.

« Last Edit: December 01, 2017, 03:31:32 AM by Godra »

bachphi

  • Hero Member
  • *****
  • Posts: 642
    • View Profile
Re: Exception thrown
« Reply #2 on: December 01, 2017, 12:19:53 PM »
999 may be too drastic, try changing to much less or different tag.
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

bob1371

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Exception thrown
« Reply #3 on: December 04, 2017, 10:53:59 PM »


Thanks guys.

Using the Try/Catch routine it showed PLC losing connection. I then took my array size down to 700 elements and all working good.