Live streams
Collector: Beckhoff ADS
Read TwinCAT 2/3 PLC variables by symbol name, on change or on a timer, with the AMS route set up.
Beckhoff TwinCAT (ADS)
Beckhoff TwinCAT PLCs (machine builders, test benches, packaging and motion) publish their variables over ADS. The collector is an ADS client: it reads variables by their symbol name (MAIN.fTemp) and, by default, asks the PLC to send each value when it changes (an ADS device notification), stamped with the PLC's own clock. Variables you prefer to sample on a timer are polled instead. It supports TwinCAT 3 and TwinCAT 2, and uses the pyads library (MIT).
Configuration
sources:
- name: Packaging machine
type: ads
ams_net_id: 192.168.1.10.1.1 # the PLC's AMS Net Id
host: 192.168.1.10 # its IP address
ams_port: 851 # 851 TwinCAT 3, 801 TwinCAT 2
tags: ads_tags.csv
- name: Test bench (everything numeric)
type: ads
ams_net_id: 10.0.0.5.1.1
host: 10.0.0.5
local_ams_net_id: 10.0.0.77.1.1 # Linux: this PC's Net Id (the PLC route points to it)| Name | Type | Description |
|---|---|---|
ams_net_idrequired | string | The PLC's AMS Net Id: six numbers, usually its IP address plus .1.1. Shown in the TwinCAT system tray icon (About TwinCAT) or in XAE under SYSTEM, Route Settings. |
host | string | The PLC's IP address. Required outside Windows; on Windows the TwinCAT router uses its own route table. |
ams_port | numberDefault: 851 | The PLC runtime: 851 for the first TwinCAT 3 runtime (852, 853... for more), 801 for TwinCAT 2. |
local_ams_net_id | string | Linux and macOS only: the Net Id this collector announces (any free one, such as this PC's IP address plus .1.1). The route on the PLC must point to it. Ignored on Windows. |
tags | path | The tag list below, relative to collector.yaml. Omit it to collect every numeric symbol the PLC lists. |
mode | notify | pollDefault: notify | Default for tags that leave the mode column empty. |
poll_ms | numberDefault: 1000 | Interval of poll tags that leave cycle_ms empty. |
max_delay_ms | numberDefault: 100 | For notifications: the PLC may hold a change this long to send several together. 0 sends each at once. Timestamps stay the PLC's. |
max_tags | numberDefault: 2000 | Upper limit on tags (each notification uses PLC and router resources). |
timeout_s | numberDefault: 5 | Per ADS request. A call that outlasts it is abandoned and the source reconnects. |
discover_timeout_s | numberDefault: 120 | For the symbol upload and for registering all notifications on a large PLC. |
The tag list
name,symbol,type,unit,scale,offset,mode,cycle_ms,max_delay_ms,description
Oven temperature,MAIN.fTemp,,degC,,,,,,
Line speed,GVL.rSpeed,,m/min,,,notify,10,0,Every PLC cycle
Part count,MAIN.nParts,,,,,,,,
Fault code,GVL.eFault,INT,,,,,,,Enum stored as INT
Zone temps,MAIN.aZones,,degC,,,,,,Array of 8 REAL: becomes Zone temps[0] to [7]
Slow pressure,MAIN.fPressure,,bar,,,poll,5000,,Read every 5 sOnly symbol is required. The collector reads each variable's type from the PLC.
| Name | Type | Description |
|---|---|---|
symbolrequired | string | The variable as TwinCAT names it: MAIN.fTemp, GVL.nCount, MAIN.fbPump.rFlow. |
name | stringDefault: the symbol | The channel name in Kymoscope. Unique within the source. |
type | BOOL BYTE SINT USINT WORD INT UINT DWORD DINT UDINT LINT ULINT REAL LREAL | Only for variables whose PLC type is none of those, such as an enum or alias: say which number it is stored as. ARRAY [lo..hi] OF <number> also works. |
unit, description | string | Shown on the channel. Discovery fills description from the PLC comment. |
scale, offset | numberDefault: 1, 0 | value = raw x scale + offset. |
mode | notify | poll | This tag's mode. |
cycle_ms | number | poll: the interval. notify: how often the PLC checks for a change (empty or 0: every PLC cycle). |
max_delay_ms | number | notify: this tag's delay before sending. |
Arrays of numbers become one tag per element, named name[0], name[1]... (multi-dimensional arrays name[1,0]); arrays above 1024 elements are refused. Strings, structures and function-block instances are not collected as a whole: list the numeric members you want (MAIN.stDrive.rSpeed). With no tag list, discovery uploads the PLC's symbol table and keeps the numeric variables and arrays.
$ kymoscope-collector discover --config collector.yaml --source "Test bench" --out ads_tags.csvA notification delivers the current value once at start and then only changes, so a variable that never changes yields one sample per connection; use mode: poll for a steady rate. Notification samples carry the PLC timestamp; poll samples carry the collector's clock.
Connecting: the AMS route
On the PLC (or from your engineering PC) add a route to the machine that runs the collector:
- Open the TwinCAT XAE, SYSTEM, Route Settings (TwinCAT 3), or the TwinCAT system manager (TwinCAT 2) and add a static route: the collector PC's name or IP address and its AMS Net Id.
- Linux or macOS collector: the Net Id is
local_ams_net_id. Pick any unused one (for example the PC's IP address plus.1.1), put it in the PLC's route with the PC's IP, and set the same value in collector.yaml. No Beckhoff software is needed on the collector PC: the library speaks ADS over TCP port 48898 by itself. Open that port from the collector to the PLC. - Windows collector: the library needs the ADS router. Install TwinCAT, or the free Beckhoff TwinCAT 3 ADS package (it provides TcAdsDll.dll and the router), then add a route to the PLC in the router's settings with the PLC's IP and Net Id, and a route on the PLC back to this PC. The router's own Net Id is used;
local_ams_net_idis ignored. If the collector runs on the PLC itself (a TwinCAT PC), use its own Net Id and no route. - Check with
kymoscope-collector discover: it lists the variables when the route and port are right.
Install
pip install "kymoscope-collector[ads]"On Linux the library is built when pip installs it, so a C++ compiler and make must be present (Debian and Ubuntu: apt install build-essential). On Windows it installs everywhere but loads only where the TwinCAT router is installed; otherwise the configuration check says so.
Health
connected, notifications_active, values_per_s, reconnects, ads_state (5 is RUN), bad_tags, polls, poll_errors, threads_abandoned, threads_hung and one counter per ADS error code, ads_errors_<code>. If the PLC leaves RUN (stop, config mode, a download) or stops answering, the collector reconnects with backoff (1 s, doubling to 60 s; it only drops back to 1 s after a connection that stayed up for a minute, so a flapping PLC is not hammered with symbol uploads) and registers the notifications again. A poll tag whose symbol no longer exists becomes a gap.
A call the PLC never answers is abandoned after timeout_s (threads_abandoned); the old connection and its notifications are closed as soon as that call returns, and nothing it still sends is stored. While 3 abandoned calls are still stuck (threads_hung) the source waits, up to 10 minutes, before trying again.
Troubleshooting
| Symptom | Likely cause |
|---|---|
ads_errors_7, never connects | No route on the PLC for this PC, or the wrong ams_net_id (see the route steps). |
ads_errors_6 | The runtime is not on this port: 851 (TwinCAT 3 runtime 1), 801 (TwinCAT 2), or the PLC is in config mode. |
ads_errors_1861 | Timeout: a firewall blocking TCP 48898, the wrong host, or an overloaded PLC. Raise timeout_s. |
ads_errors_1808 | Symbol not found: check the spelling, and that the project on the PLC is the one you expect. |
| Tag skipped: type is not a number | An enum, alias, string or structure: set the type column (INT for most enums) or list its numeric members. |
| Connects, but few samples | Notification tags only send changes: a constant gives one sample. Use mode: poll for a steady rate. |
| The configuration says it needs TcAdsDll.dll | Windows without TwinCAT: install the Beckhoff ADS package, or run the collector on Linux. |