AdvancedHMI Software
General Category => Support Questions => Topic started by: PJonHar 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.
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
-
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.
-
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:
PLCConnection.BeginRead("WeldData.ChannelData[0].Data[0]", Samples)
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?
-
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
-
I do get an error, but it doesn't state what?
-
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,
-
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
-
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.
-
The limit is 124, at 125 it does not get into the DataReceived event.
Is it because they are REAL data types?
-
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.
-
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
-
Many thanks for confirming, I look forward to the release.