|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
Layer: L7 Application ยท Build flags: PC_ENABLE_ADS
ADS (Automation Device Specification) is the protocol Beckhoff's TwinCAT PC-based control speaks - the most common way to read and write a Beckhoff PLC over the network. It rides on AMS (Automation Message Specification) over TCP port 48898. services/ads is a pure codec: pc_ads_build_* produce complete on-wire frames (AMS/TCP header + 32-octet AMS header + the command payload) and pc_ads_parse_* decode the replies. The sketch owns the socket (a plain WiFiClient) and runs a small sequence against a real router:
Reading a symbol by name is the two-step ADS idiom: ReadWrite the symbol name to index group 0xF003 to get a 4-octet handle, then Read the value from index group 0xF005 at that handle (and Write the handle back to 0xF006 to release it):
The codec also covers ReadDeviceInfo, Write, WriteControl, and device notifications (pc_ads_build_add_notification / pc_ads_parse_notification to subscribe to a symbol and walk the pushed samples).
An ADS target cannot be self-hosted from this library, so this example talks to a real PLC. Before it will connect:
PLC_IP and PLC_NET_ID (the router's AMSNetId, e.g. 5.18.30.40.1.1) and PLC_PORT (851 for the first TwinCAT 3 PLC runtime, 801 for TwinCAT 2)..1.1 appended). Add that AMSNetId as a static route on the PLC (TwinCAT: Router -> Edit Routes -> Add, or Tc3AmsRemoteMgr) - the router drops connections from an unknown AMSNetId.SYMBOL to an INT / DINT variable that exists in the PLC (MAIN.nCounter).Flash and watch Serial @ 115200:
The complete sketch is AdsClient.ino. The codec itself is in src/services/fieldbus/ads/ads.h; the AMS/ADS wire layout, command ids, and state flags are verified against the Beckhoff InfoSys specification.