IMDHMIControls LibraryShop main store

Troubleshooting

Why ADS PollValues stops after a PLC program download

PLC programming Published 4 min read By IMDHMI controls team

Short answer

PollValues in TwinCAT.Ads.Reactive v4.4.0 holds one ADS symbol handle for the life of the observable, and a PLC program download invalidates that handle, so polling keeps throwing errors even when the link is healthy. Route failed reads through the error-handler overload so the stream survives, and rebuild the observable on the SymbolVersionChanged event.

On this page
  1. Where the read path actually breaks
  2. Worked example: one struct polled every second
  3. Why ConnectionStateChanged stays quiet
  4. Rebuild the observable on SymbolVersionChanged
  5. Decision
  6. Questions asked

When PollValues stops after a PLC program download, the transport is usually fine: the observable is still holding the ADS symbol handle it created when you called PollValues, and the download invalidated that handle on the PLC side. TwinCAT.Ads.Reactive v4.4.0 does not recreate handles automatically, so reads keep failing until you dispose the observable and build a new one. Treat the two failure modes separately: keep the stream alive through transport errors with the PollValues overload that takes a Func<Exception, T> error handler, and recreate the observable when SymbolVersionChanged fires on your TcAdsClient or AdsConnection.

Where the read path actually breaks #

A PollValues request travels three steps: the polling timer triggers a read, the ADS client sends it over the configured route and Ethernet path, and the PLC resolves the symbol handle to its current variable storage. A cable interruption breaks step two. A program download changes the symbol context in step three while the transport stays up, so restoring the cable or rebooting the PLC does not repair the old handle.

The deciding check is a real ADS request. Confirm the physical link and the route, then read the PLC state with a call that does not throw on failure. Once requests reach the PLC again, look at symbol validity rather than repeatedly calling Connect.

Worked example: one struct polled every second #

Say the application polls a custom ModuleStateData struct from the symbol named in Cfg.ModuleStateTag, with a one-second period, after connecting successfully and loading the symbol tree through SymbolLoaderFactory with SymbolLoaderSettings.Default:

_client.PollValues<ModuleStateData>(
    Cfg.ModuleStateTag,
    TimeSpan.FromSeconds(1.0),
    e =>
    {
        Debug.WriteLine($"Error reading status {Cfg.Name} - {e.Message}");
        return new ModuleStateData { Faulted = true };
    });

Timeline of what each interruption does to this stream:

  • Ethernet unplugged: the read selector throws; with the error handler the stream emits the fallback value each second and keeps running. Without the handler the exception rethrows and the observable terminates with OnError, which the subscriber's error callback logs without restarting anything.
  • Program download while the link is up: the PLC changes its symbol version, all open handles are invalidated, and the next read fails. The error handler returns the fallback again, but the following reads use the same stale handle and keep failing, because the library builds a handle bag once when PollValues is called and reuses its handle on every trigger.
  • Program download with the handler plus SymbolVersionChanged registered: the event fires after the download, your handler disposes the old subscription and constructs a fresh PollValues observable, which acquires a new handle against the new symbol version. Reads succeed again on the next tick.

By contrast, WhenValueChanged and WriteValues renew themselves internally and recover through both interruptions in the same scenario, which is why only polling breaks. Recovery observed on those two operations does not establish behavior for PollValues; verify each operation during commissioning, especially before recovered writes influence machine behavior.

Why ConnectionStateChanged stays quiet #

ConnectionStateChanged fires only when your code calls Connect or Disconnect; it does not track a cable pulled out of a live session. Do not wait for it. Use request success and failure as the communication-health signal: log every read exception, record the last successful read timestamp, and let consuming logic judge staleness against your own limit rather than treating the one-second polling period as a timeout policy.

Carry fault state separately from the returned structure. A default ModuleStateData can resemble a legitimate machine state, so set a fault flag in the handler, keep the last good values available, and clear the flag only on a subsequent successful read.

Rebuild the observable on SymbolVersionChanged #

Register the symbol-version event as part of the connection lifecycle, before polling starts, then rebuild handle-dependent observables in its handler:

  1. Connect the client and load the symbol tree.
  2. Subscribe to SymbolVersionChanged on the TcAdsClient or AdsConnection.
  3. Create the PollValues observable with the symbol name, the one-second period and the error handler, and store the disposable from Subscribe.
  4. On the event, dispose the stored disposable, construct a new observable for the same symbol, and subscribe again.

Resubscribing to the same observable object is not enough: the handle bag is created when PollValues is called, so the observable itself must be reconstructed to get a fresh handle. If you need an alternative pattern, read by symbol name with a handle created and deleted per request; that costs extra ADS transactions each cycle but never depends on a long-lived handle. For how symbol visibility changes on the server side, see the article on why PLC symbol changes break SCADA tags in OFS, and for a related ADS transport failure see why TwinCAT FB_MBReadRegs fails with ADS error 1794.

Decision #

  • Transport interruption only: use the PollValues overload with the Func<Exception, T> handler so the stream survives, and return fault-flagged fallback data, never a bare default structure that reads as machine state.
  • Program download or PLC restart: the handler alone does not fix it. Register SymbolVersionChanged, and on that event dispose and rebuild the observable so a new handle is acquired.
  • Both conditions in one application, which is the normal case: run the error-handler overload and the SymbolVersionChanged rebuild together. Keep the cached-handle polling pattern, coordinate disposal, and verify recovered behavior on every operation you rely on before it reaches live equipment.

One safety note: gate any recovered write path behind a fresh successful read of machine state, so a reconnect after a download never resumes outputs based on stale or fallback values.

Questions asked

Why does ConnectionStateChanged not fire when the Ethernet cable is unplugged?

On TcAdsClient that event tracks the client lifecycle you drive yourself: it fires when your code calls Connect or Disconnect, not when the transport path fails underneath an established session. Treat request success and failure as your communication-health signal, and log the exception from each failed read instead of waiting for a state event that will not come.

Does an online change also invalidate the PollValues handle?

No. The symbol-version counter does not change on an online change of the PLC program on the runtime ports, so the existing handle stays usable. A full download or a restart of the ADS server changes the version, invalidates all open symbol handles, and is the case where you must dispose and rebuild the polling observable.

Can I just return a default structure from the error handler and keep polling?

That keeps the stream alive after a transport failure, but after a symbol-version change the same stale handle is used again and every read still fails. A default structure can also look like legitimate machine state to consuming logic, so carry a fault flag and the last successful read timestamp alongside it, and clear the fault only when a real read succeeds.

Keep reading

  • Troubleshooting

    Fix block format not recognised when uploading an S7-200 program

    A completed upload that Micro/WIN V4.0 cannot display means the transfer worked and the parser failed: the block in the CPU belongs to an older toolchain generation. Save the upload untouched, open the original project in the Micro/DOS or Micro/WIN release that created it, and convert a copy in V4.0. Download nothing until the recovered project opens, compiles and matches the block inventory you recorded.

    PLC programming

  • How-to

    How to compare two CLICK PLC programs for differences

    CLICK Programming Software has no built-in project compare, and the vendor has said none exists in the current release. The working method is to upload each machine's running program as a dated baseline, compare hardware, field assignments, configuration and logic in six passes, classify every mismatch, and load one merged program only after every difference has an owner.

    PLC programming

  • Troubleshooting

    Software you need to download a MicroLogix 1400 program

    You need RSLogix 500 to open and download the program, and RSLinx to provide the communication path; the RSLinx Lite edition installed with RSLogix 500 is enough. RSLogix 5000 and Studio 5000 cannot download to a MicroLogix 1400 because they target the ControlLogix and CompactLogix families.

    PLC programming