Troubleshooting
Read PLC tag arrays in one block request
Short answer
Reading the start tag with an element count returns the whole array in one request: Read("Test[0]", 201) gives Test[0] through Test[200], repeatable at least every 500 ms per the driver's guidance. The count is a quantity, not a final index, and the DataReceived handler must iterate e.Values rather than use only e.Values(0). Update past driver 3.41, whose AsyncMode reads can drop data, to the 3.5 series Read and BeginRead calls.
On this page
One request can carry the whole array. values = EthernetIPforCLXCom1.Read("Test[0]", 201) returns Test[0] through Test[200] as one string array, and the driver's guidance is that this read can repeat at least every 500 ms, depending on network speed and processor. Three faults make the block read look broken on an AdvancedHMI form: the element count gets treated as a final index instead of a quantity, the DataReceived handler uses only e.Values(0), and driver 3.41's asynchronous reads can return nothing or a sequence number under load. Fix those three and 201 ReadAny calls per controller collapse into one request per cycle.
Why only the first element comes back #
Test[0] through Test[200] spans 200 - 0 + 1 = 201 elements. A request for 200 elements beginning at Test[0] stops at Test[199] and never reaches Test[200]. The count argument is a quantity of elements, not the last index.
A block read arrives as one event: e.PlcAddress holds the start address you requested, and e.Values holds every element that came back. A handler written for one-element reads, which parses the index out of e.PlcAddress and then writes e.Values(0), fills exactly one grid row no matter how many elements the controller sent.
Driver 3.41 adds a third fault on the asynchronous path. With many code-driven reads running alongside controls on the same form, reads sometimes returned no data and sometimes returned the sequence number in place of the data. That is a documented fault of that driver generation, not a PLC or network problem.
Check these before touching the PLC program or the Ethernet hardware:
- The returned length, straight after the call, or e.Values.Length inside the handler.
- Whether the handler iterates e.Values or reads only e.Values(0).
- The installed driver assembly version, because 3.41 carries the asynchronous fault above.
Match the call to the installed driver generation #
The 3.41 driver exposes ReadAny with an AsyncMode property toggled around the calls. The 3.5 rewrite removed AsyncMode and split the interface: Read is the synchronous read, BeginRead the asynchronous one. An AsyncMode assignment no longer compiles after the rewrite, so drop those lines when moving forward.
The release numbering jumped from 3.43 to 3.5.1, with fixes running through 3.5.8. The block-read guidance came from version 3.58, whose Ethernet/IP drivers were revamped for speed and stability; the user who moved to it reported a dramatic performance improvement and the element-count read working. Read the assembly version your project references rather than parsing the abbreviated numbering, back up the application, update through the driver's official distribution channel, then retest with the form's other polling controls inactive before enabling them.
Swapping a switch or retuning a controller timer is wasted while the form still calls the affected 3.41 implementation. Fix the API generation first.
Read the array in one call #
The documented call takes a start address and an element count and returns a string array:
Dim compactValues() As String = Nothing
Dim microValues() As String = Nothing
compactValues = EthernetIPforCLXCom1.Read("Test[0]", 201)
microValues = EthernetIPforPLCSLCMicroCom1.Read("N223:0", 201)
If compactValues Is Nothing Then
Throw New InvalidOperationException("CompactLogix block read returned nothing")
End If
If compactValues.Length <> 201 Then
Throw New InvalidOperationException(
"CompactLogix block read short: expected 201, got " &
compactValues.Length.ToString())
End If
In the result, values(0) is Test[0], values(1) is Test[1], and values(200) is Test[200]; the MicroLogix result maps N223:0 upward the same way. EthernetIPforCLXCom1 and EthernetIPforPLCSLCMicroCom1 are the component names from the working examples, so use the names on your own form. One call returning one array is what your code sees; whether the driver splits a large read into protocol-sized transfers internally does not change the array you validate.
Fill the grid from the validated result, with all 201 rows created before the loop:
For i As Integer = 0 To 200
dgvCompactLogix.Item(0, i).Value = "Test[" & i.ToString() & "]"
dgvCompactLogix.Item(1, i).Value = compactValues(i)
dgvMicroLogix.Item(0, i).Value = "N223:" & i.ToString()
dgvMicroLogix.Item(1, i).Value = microValues(i)
Next
The test that proves the read: compactValues.Length equals 201, compactValues(0) shows the value of Test[0], and compactValues(200) shows Test[200]. When you need an independent check on what the controller holds, reading Logix tags from CODESYS with CIP GenericService covers the same controller-side tag read from a second client.
Consume every returned value in the handler #
For asynchronous acquisition on the rewritten driver, start the block with BeginRead and validate the result in the completion handler:
Private Sub EthernetIPforCLXCom1_DataReceived(ByVal sender As Object,
ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
Handles EthernetIPforCLXCom1.DataReceived
If e.Values Is Nothing OrElse e.Values.Length <> 201 Then
Exit Sub ' log start address, requested 201, returned length
End If
For i As Integer = 0 To e.Values.Length - 1
dgvCompactLogix.Item(1, i).Value = e.Values(i)
Next
End Sub
For a block that begins at index 0, position i is Test[i]. For a block that begins elsewhere, carry the base index with the request: e.PlcAddress carries only the start address, so an index parsed from it is always the base, never the position within the block.
The synchronous Read is the simplest call, but it ties up the UI thread and leaves the form unresponsive until the controller answers. On a 500 ms cycle with an operator watching, use BeginRead or run the synchronous read on a background thread.
Replace the empty exception handler with logging that records the start address, the requested count, the returned count and the exception details. A Catch block that swallows its own exception turns a one-line programming error into what looks like an intermittent PLC fault.
Fix the subscription callback that will not compile #
The compile error names the mismatch: the method "does not have a signature compatible with 'Delegate Sub ReturnValues(values() as String)'". The installed Subscribe callback wants a string array, not a sender-and-EventArgs pair:
Private Sub SubscribedDataReturned(ByVal values() As String)
TextBox1.Text = values(0)
End Sub
The documented usage keeps the subscription identifier and releases it on form closing:
SubscriptionID = EthernetIPforCLXComm1.Subscribe("MyTag", 1, 250, AddressOf SubscribedDataReturned)
EthernetIPforCLXComm1.UnSubscribe(SubscriptionID)
The sender-and-PlcComEventArgs signature belongs to the DataReceived event, not to the Subscribe callback. Subscription array handling is not planned until version 4, so on this generation a 250-element array means 250 separate subscriptions, exactly the load the block read removes.
Diagnose the read that fails at index 82 #
The report: values1 = EthernetIPforPLCSLCMicroCom1.Read("N50:0", 200) returned, and the display loop for indices 0 to 199 threw at iLoop = 82. That observation alone does not establish a MicroLogix transfer limit. Work the layers in order:
- Comment out the grid loop and run the read alone; record whether it returns normally.
- Inspect values1.Length immediately after the assignment. Declaring
Dim values1(300) As Stringfirst preserves nothing: the returned array replaces the variable, so its length is whatever the driver delivered. - Count the grid rows. dgvMicroLogix.Item(0, 82) throws when row 82 does not exist; add the rows before the loop.
- Record the exception type instead of swallowing it, because an index fault at the grid and a communication fault during the read have different fixes.
- Confirm the file: this test reads N50:0 where the original polling read N223:0, and a successful read from the wrong file still returns the wrong process values.
The working reported configuration used two reads of 101 elements: Read("N50:0", 101) covers N50:0 through N50:100, and Read("N50:100", 101) covers N50:100 through N50:200, overlapping at N50:100. A non-overlapping equivalent of the full range is 101 elements from N50:0 (indices 0 to 100) plus 100 from N50:101 (indices 101 to 200): 101 + 100 = 201 elements, matching the single request element for element. Map each chunk's result index 0 to that chunk's start address.
Decision: run the single 201-element read and validate its length first. Chunk only when your installation demonstrably returns a short array, and validate every chunk's length before combining.
Choose the polling method and the rate #
The arithmetic, per controller:
- Old scheme: 201 ReadAny calls every 5.0 s is 201 divided by 5.0 s = 40.2 requests per second.
- Block read: one request every 0.5 s is 1 divided by 0.5 s = 2.0 requests per second.
- Reduction: 40.2 divided by 2.0 = 20.1 times fewer requests, with all 201 values still arriving.
The 500 ms floor is the driver's own guidance, conditioned on network speed and processor; treat it as the starting point and measure the achieved cycle before shortening it. Two controllers double the counts, 80.4 requests per second before and 4.0 after, on the same wire.
Decide by method:
- A 201-element block read through BeginRead on a 500 ms timer: the choice for this installation.
- Synchronous Read: background thread or quick tests only, because it freezes the form while it waits.
- Subscribe: single tags only on this driver generation; array subscriptions wait for version 4.
Values that arrive on a 500 ms poll are display data: interlocks and shutdown logic stay in the controller, never in the PC that polls it. And when a polling change leaves only some controllers updating, the station itself is the next suspect, the failure shape of a SCADA PC station that reaches only one S7-1500.
Questions asked
Is the number after the tag the last index or the element count?
It is the count of elements to read, beginning at the address you pass. Read("Test[0]", 201) returns Test[0] through Test[200]; asking for 200 stops at Test[199]. For any range the count is last index minus first index plus one: Test[20] through Test[45] is 45 - 20 + 1 = 26 elements. A read that lands one element short is usually this off-by-one, not a driver fault.
Why does the grid show only the first value after a block read?
The DataReceived handler still parses its index from e.PlcAddress and writes e.Values(0), which worked for one-element ReadAny calls. A block arrives as one event whose PlcAddress is the start address, so the parsed index never advances past the base. Loop over e.Values and use position as the index; when two blocks share one handler, pass the base index along with each request so the handler fills the right rows.
Should I subscribe to each array element instead of polling?
Not on this driver generation: subscription array handling is not planned until version 4, so every element needs its own Subscribe call. The documented example polls one tag every 250 ms, so 250 subscriptions generate 1000 reads per second, against 2 per second for one 201-element block read every 500 ms. Subscribe for a handful of tags; block-read arrays.
How do I tell which driver generation the project uses?
Look at the communication assembly the project references, not the PLC firmware. Code that sets AsyncMode around ReadAny calls is the 3.41 generation; a driver exposing Read and BeginRead with no AsyncMode is the rewritten 3.5 series. The numbering jumped from 3.43 to 3.5.1 and 3.58 abbreviates a release in that line, so read the assembly version directly instead of counting releases.
How fast can the block-read cycle really go?
At least every 500 ms is the driver's guidance for a 201-element read, conditioned on network speed and processor: a floor, not a guarantee. Timestamp successive DataReceived events and compare the span of the returned values to confirm the achieved cycle. Shorten the interval only after the measured rate is stable, and treat the data as operator display values, never as a control update.