Connecting a TwinCAT PLC over ADS

The simulator can read and write a TwinCAT 3 PLC's variables by name over ADS, Beckhoff's own protocol. Each part's tag is the PLC's name for the variable, like MAIN.Eye, so nothing is mapped to an address. Your program runs on the PLC.

ADS goes through the TwinCAT router, and the simulator uses the router on its own computer. So TwinCAT has to be installed on the computer running the simulator, and a PLC on another computer has to be reachable through a route, exactly as TwinCAT XAE reaches it. Part A uses the runtime on the same computer; part B adds the route to a PLC elsewhere.

You need

1. Build the scene

In the desktop app, start a new scene and place three parts from the library:

  1. A Belt Conveyor.
  2. A Box, sitting on the belt near the end it starts from.
  3. A Photo Eye beside the belt, about two thirds of the way along, facing across it.

Select each part, and in the Inspector's Comms group type the PLC's name for its variable:

PartFieldType inThe PLC's variable
Photo EyePresence TagMAIN.EyeThe simulator writes it
Belt ConveyorRun TagMAIN.RunThe simulator reads it
The Inspector's Comms group for the Photo Eye, with Presence Tag set to MAIN.Eye.
The photo eye's Comms group, wired by name to MAIN.Eye.

A tag is the variable's full symbol path, starting with the program or global variable list it is declared in: MAIN.Eye for a variable of MAIN, GVL.Run for a global. BOOL, the integer types, REAL and LREAL travel. A structure, a STRING or a 64-bit integer does not, and the dialog says which.

Part A. The runtime on this PC

A1. The PLC program

PROGRAM MAIN
VAR
  Eye : BOOL;
  Run : BOOL;
END_VAR

Run := NOT Eye;
END_PROGRAM

Eye is a plain variable, not an input linked to I/O, because the simulator writes it. TwinCAT publishes every variable over ADS, so nothing needs to be exported.

A2. Build it and run it in TwinCAT

Put the program above into a PLC project in TwinCAT's engineering tool, give the runtime a license, put it in Run mode, then download the program and start it. Beckhoff's own documentation walks through each of those steps. Without a license the runtime stays in Config mode, and the simulator has nothing to connect to.

A3. Point the simulator at the runtime

Open Simulation > PLC Controllers… and set:

  1. Runs on: An external PLC.
  2. Under it, how the PLC connects: ADS, tags by name.
  3. AMS Net ID: leave it empty, which means the TwinCAT runtime on this PC.
  4. Port: 851, the first PLC project in the runtime. A second one is 852.

A4. Press Play

The status line says Reading and writing the PLC's tags at this PC's TwinCAT runtime, AMS port 851, the dialog lists each tag with the type the PLC gave it (MAIN.Eye written to the PLC and MAIN.Run read from it, both BOOL), and the PLC stops the box at the sensor.

Press Play before the PLC is running and the simulator waits, trying again every second: target port not found: TwinCAT is not running there, or the AMS port is wrong (851 is the first PLC). Start the PLC and it connects, without pressing Play again.

Part B. A PLC on another computer

The simulator's requests leave this PC through its own TwinCAT router, which forwards them only to a computer it has a route to. The PLC's router answers only a computer it has a route back to. So both ends need a route, one on each router.

On this PC, the simulator hands its requests to the TwinCAT router, whose route to the PLC's AMS Net ID carries them over TCP port 48898 to the PLC's router. That router has a route back to this PC's AMS Net ID, and passes the requests to the PLC runtime on AMS port 851. Both routers need a route to the other This PC Simulator TwinCAT routerroute to the PLC PLC TwinCAT routerroute back to this PC Runtime, AMS port 851 TCP 48898

B1. Add the routes in TwinCAT

Add a route from this PC to the PLC, and one from the PLC back to this PC, with TwinCAT's own tools. Beckhoff's documentation on ADS routes says how. Note the PLC's AMS Net ID while you do. Once TwinCAT on this PC can reach the PLC, so can the simulator: it uses the same router and the same routes.

Firewalls between the two have to let ADS through: TCP port 48898, and UDP port 48899 for the broadcast search.

B2. Point the simulator at the PLC

  1. AMS Net ID: the PLC's, like 192.168.1.20.1.1. It often starts with the PLC's IP address, but not always.
  2. Port: 851, as before.

The first time you press Play, the app asks whether to allow the connection: Allow Open Industry Project to connect to the TwinCAT runtime 192.168.1.20.1.1 (AMS port 851) over ADS? Choose Allow. The app remembers it for that PLC.

Without a route, the status line says target machine not found: add a route to this PC on the PLC, or check its AMS Net ID, then This PC's AMS Net ID is ...: the Net ID the PLC's route back has to name.

Troubleshooting

The connection options are greyed out.
You are in a browser tab. Connecting to a PLC needs the desktop app.
"ADS needs TwinCAT's router on this PC, and TwinCAT is not installed"
Install TwinCAT 3 on the computer running the simulator, even when the PLC is elsewhere. The ADS setup alone is enough.
"... is the TwinCAT system service running?"
TwinCAT is installed but its system service is stopped. Start it, or restart the PC.
"target port not found ..."
Nothing is running on that AMS port: the runtime is in Config mode, the PLC is not started, or the port is wrong. If the runtime keeps falling back to Config mode, check the license (A2).
"target machine not found ..."
No route to that AMS Net ID, or the Net ID is mistyped. See part B.
"the PLC has no symbol named ..."
The tag does not match a variable in the running PLC. Check the spelling and that it starts with its program or list, like MAIN.Eye, then download the program if you changed it.