WARNING: Please be gentle, very much a NOOOOOOOB. Sorry for the long post.
Archie, this product is sheer brilliance.
I have a Compact Logix L32E and a Micrologix1400 SerB.
The code in both PLC's is to put the accumulator of a timer into array "Test[0]" till "Test[200]" for the Compact Logix and "N223:0" till N223:200" for the MicroLogix as fast as possible.
I can connect to both PLC's and receive the tag name and the tag data into 2 separate data grids. I read 201 integers per PLC.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I currently run off a timer executing every 5 Seconds which calls ReadCompactLogix() and ReadMicroLogix()
Private Sub ReadCompactLogix()
Dim sTemp As String
Dim iLoop As Integer
EthernetIPforCLXComm1.AsyncMode = True
For iLoop = 0 To 200
sTemp = "Test[" + iLoop.ToString + "]"
EthernetIPforCLXComm1.ReadAny(sTemp, 1)
Next
EthernetIPforCLXComm1.AsyncMode = False
End Sub
Private Sub ReadMicroLogix()
Dim sTemp As String
Dim iLoop As Integer
EthernetIPforPLCSLCMicroComm1.AsyncMode = True
For iLoop = 0 To 200
sTemp = "N223:" + iLoop.ToString
EthernetIPforPLCSLCMicroComm1.ReadAny(sTemp, 1)
Next
EthernetIPforPLCSLCMicroComm1.AsyncMode = False
End Sub
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I then use the DataReceived event handler as follows:
Private Sub EthernetIPforCLXComm1_DataReceived(ByVal sender As Object, ByVal e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforCLXComm1.DataReceived
Dim sTemp As String
Dim iLoop As Integer
Try
sTemp = e.PlcAddress
Dim iLength As Integer = sTemp.Length
Dim sLoop As String = Mid(sTemp, 6, iLength - 6)
iLoop = CInt(sLoop)
dgvCompactLogix.Item(0, iLoop).Value = e.PlcAddress
dgvCompactLogix.Item(1, iLoop).Value = e.Values(0)
'Calculate the time to return all the variables
If iLoop = 200 Then
If dgvCompactLogix.Item(1, 200).Value > dgvCompactLogix.Item(1, 0).Value Then
txtCompactLogix.Text = dgvCompactLogix.Item(1, 200).Value - dgvCompactLogix.Item(1, 0).Value
Else
txtCompactLogix.Text = dgvCompactLogix.Item(1, 200).Value - dgvCompactLogix.Item(1, 0).Value + 9999
End If
End If
Catch ex As Exception
End Try
End Sub
Private Sub EthernetIPforPLCSLCMicroComm1_DataReceived(ByVal sender As Object, ByVal e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforPLCSLCMicroComm1.DataReceived
Dim sTemp As String
Dim iLoop As Integer
Dim iStringLength As Integer
Dim iStringPosition As Integer
Try
sTemp = e.PlcAddress
iStringLength = sTemp.Length
iStringPosition = InStr(sTemp, ":")
Dim sLoop As String = Mid(sTemp, iStringPosition + 1, iStringLength - iStringPosition)
iLoop = CInt(sLoop)
dgvMicroLogix.Item(0, iLoop).Value = e.PlcAddress
dgvMicroLogix.Item(1, iLoop).Value = e.Values(0)
'Calculate the time to return all the variables
If iLoop = 200 Then
If dgvMicroLogix.Item(1, 200).Value > dgvMicroLogix.Item(1, 0).Value Then
txtMicroLogix.Text = CInt(dgvMicroLogix.Item(1, 200).Value) - CInt(dgvMicroLogix.Item(1, 0).Value)
Else
txtMicroLogix.Text = CInt(dgvMicroLogix.Item(1, 200).Value) - CInt(dgvMicroLogix.Item(1, 0).Value) + 32765
End If
End If
Catch ex As Exception
End Try
End Sub
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Data is returned to the respective grids.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Question 1: NumberOfElements
I was hoping to address the array by using the 200 value below. By doing this, it only returns "Test[0]" and "N50:0" only. How do I correctly address NumberOfElements?
Private Sub cmdCompactLogixArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCompactLogixArray.Click
EthernetIPforCLXComm1.AsyncMode = True
EthernetIPforCLXComm1.ReadAny("Test[0]", 200)
EthernetIPforCLXComm1.AsyncMode = False
End Sub
Private Sub cmdMicroLogixArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMicroLogixArray.Click
EthernetIPforPLCSLCMicroComm1.AsyncMode = True
EthernetIPforPLCSLCMicroComm1.ReadAny("N50:0", 200)
EthernetIPforPLCSLCMicroComm1.AsyncMode = False
End Sub
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Question 2: Subscribe method
In another post, Archie gives an example.
Public Class frmSubscribe
Private SubscriptionID As Integer
Private Sub frmSubscribe_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
EthernetIPforCLXComm1.UnSubscribe(SubscriptionID)
End Sub
Private Sub frmSubscribe_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
EthernetIPforCLXComm1.IPAddress = "192.168.101.253"
SubscriptionID = EthernetIPforCLXComm1.Subscribe("MyTag", 1, 250, AddressOf SubscribedDataReturned)
End Sub
'* Show the value when it is returned
Private Sub SubscribedDataReturned(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
'Me.Text = e.Values(0)
TextBox1.Text = e.Values(0)
End Sub
End Class
Modifications Made to Archies code was EthernetIPforCLXCom1 replaced with EthernetIPforCLXComm1 (Running Ver 3.41 of driver)
There is an error and I do not know how to fix it.
SubscribedDataReturned has a blue squiggle under it and the error is:
Method "Private Sub SubscribedDataReturned(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)" does not have a signature compatible with 'Delegate Sub ReturnValues(values() as String)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Question 3: Performance
In my real life application, I need to read 250 integers as quickly as possible (i.e. every 2 seconds would be great).
What is the best way to handle this? As per timer above OR to use the Subscribe method OR
??