How-to
How to run two TwinCAT PLC programs on one laptop
Short answer
Merge both PLC projects into one TwinCAT XAE system configuration and activate it once. The XAE assigns each PLC project its own ADS port (851 to the first, 852 to the next by default numbering), and both programs reach RUN on the local runtime. Changing the port in one of two separate XAE projects does not work, because one activation replaces the other.
On this page
Run both programs from one TwinCAT XAE project: add the second PLC project into the first project's system configuration, let the XAE assign it the next ADS port, and activate that one configuration. Two separate XAE projects cannot share the local runtime, because a TwinCAT target holds exactly one active configuration and activating the second project replaces the first — renumbering a port does not change that behavior. Merged, the first PLC project keeps ADS port 851, the second takes 852 by default numbering, and both reach RUN. The usual split here — a Modbus server simulator in one project and a test client in the other — then talks across the loopback interface with no cable, no switch and no AMS route.
Why both projects land on ADS port 851 #
Every ADS request follows the same path: the XAE on the laptop, the local ADS router, the TwinCAT runtime, and finally a PLC runtime addressed by its AMS Net ID plus its ADS port. On one laptop the local target answers to one AMS Net ID for both projects, so the ADS port is the only thing that tells the two PLC runtimes apart. The first PLC project in a configuration defaults to port 851. Your second XAE project also has a first — and only — PLC project, so it defaults to 851 as well: two runtimes, one address, and only one of them can go to RUN.
Changing the port on one project cures that collision and still fails, because activation is a second, independent limit. The target keeps one active configuration: activating project B restarts the runtime with B and discards A. That is why the port change alone leaves one program stopped or in config mode. Fix both limits at once by putting the two PLC projects into a single configuration.
Compare the three ways to run both #
| Approach | Fixes the 851 collision | Both run at once | Effort |
|---|---|---|---|
| Change ADS Port on one PLC project, keep two XAE projects | Yes | No — each activation replaces the other on the local target | Low |
| Both PLC projects in one XAE configuration | Yes — the XAE assigns the next port, and you can override it | Yes | Low to moderate |
| Second runtime, a VM or a second device, with its own AMS route | Yes — each target has its own AMS Net ID | Yes | Moderate |
Merge the projects unless the two programs must never share a runtime. Merging keeps everything on the laptop, needs no route setup, and uses the port assignment the XAE already performs for multiple PLC projects in one configuration.
Merge both PLC projects into one configuration #
- Open the test client's solution and keep its system configuration as the master. Close the simulator's solution so it cannot be activated by mistake.
- In the Solution Explorer, right-click the PLC node and add the simulator's PLC project as an existing item. This is the same node where Add New Item creates a fresh PLC project inside the TwinCAT project.
- Read the ADS port of each PLC project in its properties: 851 on the first, the next number — 852 by default numbering — on the second. If a port needs setting by hand, right-click the PLC project and choose Change ADS Port.
- Under System > Tasks, link each PLC project to its own task so each program gets its own cycle time and priority. Read the core assignment in the real-time settings before you give both tasks tight cycles.
- Select the local target, choose Activate Configuration, and restart the target in Run mode.
- Archive the old standalone solution and stop activating it: one activation against the local target overwrites this merged configuration.
One safety limit: keep this workflow on the laptop. If the target is ever a machine's controller instead, activating a configuration stops whatever program the machine is running.
Point the Modbus client at the server on the same laptop #
Both endpoints sit on one machine, so the Modbus traffic never leaves the local TCP/IP stack. The client PLC opens a TCP connection to the listening port of the server PLC on the loopback address — the same one-machine pattern as simulating a Modbus TCP SCADA link on one PC.
| Setting | Value | Symptom if wrong |
|---|---|---|
| Client target IP | 127.0.0.1, or the laptop's own address | Connect timeout |
| Modbus TCP port | The port the server PLC listens on; 502 is the Modbus TCP default, so read the actual value from the server configuration | Connection refused when client and server ports differ |
| Start order | Server task in RUN before the client connects | Client faults on its first cycle, then needs a reconnect |
| Local firewall | Allow the listening port | Silent drop that looks like a timeout |
Keep the two port spaces apart. ADS ports 851 and 852 address PLC runtimes inside the TwinCAT router; the Modbus TCP port is an ordinary TCP port on the network stack, and 502 has nothing to do with either ADS number.
Confirm both runtimes are in RUN #
- The XAE status bar shows Run mode for the local target, and both PLC projects list their own ADS port in their properties.
- Log in to each PLC project separately. Each login connects on its own port without a mismatched boot project complaint or a stopped-runtime message.
- Increment a counter once per cycle in each program and watch both numbers move. Example, using a task cycle time of 10 ms read from System > Tasks: one increment per cycle is 1 / 0.010 s = 100 counts per second, so a five-second check shows 5 s × 100 counts/s = 500 counts on each counter. A counter that stands still identifies a dead task or login, not an idle program.
- Confirm the link: the client's connection status reads connected, and a value the client writes shows up in the server's register image.
- Deactivate and reactivate the configuration once. Both projects returning to RUN proves the merged configuration is the one stored on the target.
What breaks a two-PLC local setup #
Activating the wrong solution. Opening the old standalone project and activating it replaces the merged configuration; the archive step exists for this reason.
License state. Each PLC runtime instance needs its runtime license or a valid trial. If one project drops out of RUN after a while, read the license page of the configuration before debugging logic.
Shared task settings. Two PLC tasks on one core with tight cycle times produce cycle-time exceedance messages. Give each program its own priority and cycle time, and check the core assignment.
Stored ports. Any tool or symbol connection that stored 851 for the moved project now addresses the wrong runtime; update the stored ADS port in those tools. And once the client is another controller on the network rather than a local test project, the fault picture changes — that case is covered in fixing a TwinCAT EtherNet/IP slave connection from an Omron PLC.
Questions asked
What happens if I only change the ADS port and keep two separate XAE projects?
The collision goes away, but you still get one program in RUN: a TwinCAT target holds one active configuration, so activating the second XAE project restarts the runtime with that project and drops the first to config mode. The port change fixes addressing only. Merge both PLC projects into one configuration whenever you need them simultaneously.
Does the second PLC project have to use port 852?
No. 852 is simply the next number in the default sequence, so a third PLC project in the same configuration would take 853 (852 plus one). Any unused ADS port works, set by right-clicking the PLC project and choosing Change ADS Port, as long as no other runtime on the target already listens on it. Read the assigned value from the project properties and point your tools at that.
What happens if the Modbus client starts before the server PLC is running?
The TCP connect fails or times out and the client's function block reports an error until the connection is retried. On loopback the failure is usually an immediate refusal; if the local firewall drops the packet instead, it looks like a timeout. Start the server task first or build a reconnect into the client, then check that the connection status turns connected.
Can I keep two XAE projects and switch between them instead of merging?
Yes, but only for sequential work. Each activation replaces the one before it, so the two programs take turns on the local runtime and never run at the same time. That is acceptable while you edit one project with the other out of RUN; as soon as the simulator and the client must exchange data in real time, merge them into one configuration.