Author Topic: EthernetIPforCLXCom Reading 5000+ array of REAL  (Read 3082 times)

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
EthernetIPforCLXCom Reading 5000+ array of REAL
« on: April 18, 2016, 07:17:17 AM »
Hi All,

I am using a PLC to log data (5000+ points of REAL values).

Currently I am reading in the data like below, a For Loop for each index in the array. This stops my application from being used as the GUI can't be updated.

Code: [Select]
            Dim NewWeldData As New WeldData

            For i = 0 To 2
                Dim NewChannelData As New ChannelData
                NewChannelData.Name = PLCConnection.Read("WeldData.ChannelData[" & i & "].Name")
                NewChannelData.Unit = PLCConnection.Read("WeldData.ChannelData[" & i & "].Unit")
                For j = 0 To NewWeld.Samples
                    StatusUpdate("Retrieving Weld Information [" & i & "],[" & j & "]")
                    Dim value As Double = 0.0
                    Try
                        value = Convert.ToDouble(PLCConnection.Read("WeldData.ChannelData[" & i & "].Data[" & j & "]"))
                    Catch ex As Exception
                        StatusUpdate("Retrieving Weld Information Error, Trying Again...")
                        value = Convert.ToDouble(PLCConnection.Read("WeldData.ChannelData[" & i & "].Data[" & j & "]"))
                    End Try
                    NewChannelData.Data.Add(value)
                    'Sleep(20)
                Next
                NewWeldData.Data.Add(NewChannelData)
            Next

Is there a better way to read in an array of 5000+ REAL values?
Should I perform the same code in a separate thread that I could start in the background?

Thanks,

Paul

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLXCom Reading 5000+ array of REAL
« Reply #1 on: April 18, 2016, 08:03:28 AM »
The Read method is synchronous and will hold the UI thread until the read completes, so it is not recommended for large amounts of data. BeginRead is asynchronous. It queues the request and immediately returns from the call. The data is then returned on the DataReceived event handler.

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: EthernetIPforCLXCom Reading 5000+ array of REAL
« Reply #2 on: April 18, 2016, 08:42:59 AM »
Hi,

Have looked at the following thread:
http://advancedhmi.com/forum/index.php?topic=940.msg4986#msg4986

I have changed my program to the following:

Code: [Select]
PLCConnection.BeginRead("WeldData.ChannelData[0].Data[0]", Samples)
Code: [Select]
Private Sub PLCConnection_DataReceived(sender As System.Object, e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs) Handles PLCConnection.DataReceived
        If e.PlcAddress.Contains("WeldData.ChannelData[") Then
            Dim id As Integer
            Dim stemp As String = e.PlcAddress.Replace("WeldData.ChannelData[", "")
            stemp = stemp.Replace("].Data[0]", "")
            id = Convert.ToInt16(stemp)

            Dim NewChannelData As New ChannelData
            NewChannelData.Name = PLCConnection.Read("WeldData.ChannelData[" & id & "].Name")
            NewChannelData.Unit = PLCConnection.Read("WeldData.ChannelData[" & id & "].Unit")

            For i = 0 To Samples
                NewChannelData.Data.Add(Convert.ToDouble(e.Values(i)))
            Next

            NewWeldData.Data.Add(NewChannelData)
            If id = 2 Then
                SQLDataAccess.InsertWeldData(NewWeldData)

                PLCConnection.Write("WeldTransferComplete", 1)
            End If
        End If
    End Sub

I have placed a break point in the in If statement of the DataReceived event, but it never gets inside it?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLXCom Reading 5000+ array of REAL
« Reply #3 on: April 18, 2016, 09:00:24 AM »
Add this to your code also:

   Private Sub EthernetIPforCLXCom1_ComError(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles PLCConnection.ComError
        MsgBox("ComError-" & e.ErrorMessage)
    End Sub
« Last Edit: April 18, 2016, 09:06:26 AM by Archie »

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: EthernetIPforCLXCom Reading 5000+ array of REAL
« Reply #4 on: April 18, 2016, 09:06:43 AM »
I do get an error, but it doesn't state what?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLXCom Reading 5000+ array of REAL
« Reply #5 on: April 18, 2016, 09:17:14 AM »
Try a low value of something like 10 in place of samples to see if that works. The RawData has over 2000 bytes which means it is reading multiple packets to get all of the data. Maybe it is trying to read beyond the end of the array,

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: EthernetIPforCLXCom Reading 5000+ array of REAL
« Reply #6 on: April 18, 2016, 09:58:06 AM »
So, setting the value as 10 worked.

Just to clarify the actual size of the array is set as 10000. The samples value for testing purposes is only ever between 500-1000. So it should not read beyond?

Thanks

Paul

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLXCom Reading 5000+ array of REAL
« Reply #7 on: April 18, 2016, 10:09:06 AM »
See if there is a breaking point. Try 100 which will require 2 packets to receive 100 DINTs.

Each packet should take less than 10ms unless you have an extremely loaded network, so it shouldn't be a timeout issue.

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: EthernetIPforCLXCom Reading 5000+ array of REAL
« Reply #8 on: April 18, 2016, 10:29:24 AM »
The limit is 124, at 125 it does not get into the DataReceived event.

Is it because they are REAL data types?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLXCom Reading 5000+ array of REAL
« Reply #9 on: April 18, 2016, 10:32:11 AM »
I'll setup and do some testing. 124 floats require 496 bytes which is about the size of a single packet. So it seems that when more than one packet is required, something causes an error.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: EthernetIPforCLXCom Reading 5000+ array of REAL
« Reply #10 on: April 18, 2016, 10:57:44 AM »
This is a confirmed bug in the driver. It will not fire the DataReceived if the amount of data exceeds a single packet (508 byte).

The work around is going to have to be multiple BeginReads

This will be fixed in the next release of 3.99e

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: EthernetIPforCLXCom Reading 5000+ array of REAL
« Reply #11 on: April 18, 2016, 11:44:55 AM »
Many thanks for confirming, I look forward to the release.