Testing PLC programs with AI in PLCSIM Advanced
Testing PLC programs with AI starts before the machine is finished. With TIA MCP the AI loads the program from the project open in TIA Portal into the S7-PLCSIM Advanced simulator, sets inputs, reads results and writes a report. Unit tests for blocks, scenarios from Excel, a virtual FAT with motor and valve models, and a WinCC Unified HMI test. All on the simulation, not on a real PLC.
What the AI does in PLCSIM Advanced
You give instructions in plain language, the AI calls the TIA MCP tools and shows you the results. In the TIA MCP web interface you can also control the simulator by hand on the Online page and run tests on the Tests page.
The simulator under control
It checks whether PLCSIM Advanced is installed and whether the version matches TIA Portal. It registers an instance, switches RUN and STOP, performs a memory reset or steps cycle by cycle.
Loading to the simulator only
It compiles the PLC and loads the program from the open project via the PLCSIM interface. This tool does not load to a real PLC.
Reading, writing and recording
Values of inputs, outputs, memory bits and DBs in the simulation, writing values and recording trends to CSV. For tuning control loops, ramps and sequences.
Unit tests for FBs and FCs
From cases of inputs and expected outputs it generates a test block, loads it into PLCSIM Advanced, runs it and reads which cases passed.
Scenarios from Excel
A process engineer fills in the scenario template (set, wait, expect, time limit, tolerance) in Excel. The AI runs it on the simulation and saves an XLSX report.
Virtual FAT
From the project's data blocks it recognises motors, valves, analogue measurements and PIDs and proposes test cases. It runs them with process models in a closed loop and creates a report in PDF, XLSX and JSON.
Alarms, I/O list and sequences
More sources of cases for the virtual FAT: triggering alarms, input-to-output links from the I/O list and walking through the transitions of a state machine, including unreachable states.
TIA Test Suite
In TIA Portal V21 with a Test Suite licence it runs the style guide check and test cases on PLCSIM Advanced. It can export and load the sets.
WinCC Unified HMI test
It builds a plan from the project (navigation, buttons, I/O fields, alarms) and verifies it against an HMI simulation connected to PLCSIM Advanced. An HTML report with screenshots of failures.
Example: unit test of an FB in PLCSIM Advanced
An illustrative, shortened example. The fbPump block comes from the example on the SCL generator page.
Request: Write unit tests for fbPump: start switches it on, stop switches it off and stop has priority over start. Run them in PLCSIM.
Test cases the AI prepares (example):
[
{"name": "start", "inputs": {"iStart": true, "iStop": false, "iFeedback": true},
"expect": {"oRun": true, "oFault": false}},
{"name": "stop", "inputs": {"iStart": false, "iStop": true},
"expect": {"oRun": false}},
{"name": "stop priority", "inputs": {"iStart": true, "iStop": true},
"expect": {"oRun": false}}
]
What happens along the way:
- The AI generates a test FB UT_fbPump with an instance DB and optionally a block that runs the tests.
- It compiles the PLC and loads it into the PLCSIM Advanced instance. If needed, it enables simulation support for block compilation in the project.
- It switches the simulation to RUN, waits and reads the number of passed and failed cases and the result of each one.
- If a case fails, the AI goes through the block logic with you. You approve the fix of the block and of the test.
How the AI writes the block is shown on the page AI SCL generator.
The virtual FAT procedure with AI
A virtual FAT tests the program before the process equipment exists. In the TIA MCP web interface a guide leads you through the virtual FAT in PLCSIM and waits for your approval at every writing step. The plan and the run are also on the Tests page.
Simulator
A PLCSIM Advanced instance and loading the program from the open project.
Test plan
The AI proposes cases from the project's DBs, alarms, the I/O list or a state machine. Read-only.
Plan review
You check the tag roles and cases. Whatever the AI cannot assign unambiguously is not run until you complete it.
Test run
Process models respond to the PLC outputs, the cases issue commands and check reactions and times. Runs in the background.
Recording
Optionally the tag trends are written to CSV and the statistics go into the report.
Report
PDF, XLSX and JSON as a basis for the FAT with the customer or for an internal review.
The Tests page in the TIA MCP web interface
Since TIA MCP 2.19 the program tests are together on one page. At the top you choose the PLC and the PLCSIM Advanced instance. The page warns you if the simulator is missing, the version does not match TIA Portal or the CPU is not in RUN, and loads the program into the simulator with one button. You can run tests without a chat with the AI, too.
PLC and simulator
A shared bar: choice of the PLC and the PLCSIM Advanced instance, warnings about missing prerequisites and loading the program into the simulator as a background job.
Block unit tests
Choose an FB or FC, edit cases based on the block interface (inputs, expected outputs, cycles, tolerance), generate the test into the project and run it with a result per case.
Virtual FAT
A plan from the project, choice of objects, a background run with progress and the option to cancel. PDF, XLSX and JSON reports and a CSV recording to download.
PLCSIM scenarios
A scenario template in Excel and running the completed scenario. A table of steps shows what was set, what was expected and what the simulation actually returned.
TIA Test Suite
An overview of rule sets and tests, the style guide check, running tests and loading a set from a file. Results with messages, problems only or all.
HMI test
Reports of the automatic WinCC Unified HMI test for the selected HMI, in one place with the other tests.
Actions that change the project or the simulator (generating a test, loading into PLCSIM, running tests, loading into Test Suite) run only after confirmation. In read-only mode they are disabled. Nothing is loaded to a real PLC from this page.
What you need
Reading and writing tags, scenarios, unit tests and the virtual FAT work with S7-PLCSIM Advanced. You can load the program into the classic S7-PLCSIM, but the AI cannot control it because it has no public interface.
| TIA Portal version | Required PLCSIM Advanced version (minimum) |
|---|---|
| TIA Portal V17 | S7-PLCSIM Advanced V4.0 |
| TIA Portal V18 | S7-PLCSIM Advanced V5.0 |
| TIA Portal V19 | S7-PLCSIM Advanced V6.0 |
| TIA Portal V20 | S7-PLCSIM Advanced V7.0 |
| TIA Portal V21 | S7-PLCSIM Advanced V8.0 |
- Windows and TIA Portal V17 to V21 with Openness, on the same computer as TIA MCP.
- S7-PLCSIM Advanced in the version that matches TIA Portal (table). It is a Siemens product and not part of TIA MCP.
- For the HMI test also the WinCC Unified PC runtime simulation on the same computer.
- For TIA Test Suite, TIA Portal V21 and a Test Suite licence.
Example requests for testing in PLCSIM
The names of blocks, DBs and instances are only examples. The AI works with what is in your project.
Check whether PLCSIM Advanced is installed and whether its version matches TIA Portal.
Load PLC_1 into the instance Sim1, switch it to RUN and read the state of DB_Line.
Write unit tests for FC_Scale including limit values and run them in PLCSIM.
Set Start to TRUE and record speed and current to CSV for 10 seconds.
Prepare a virtual FAT plan for the motors and valves in DB_Station1 and show me what to verify.
Run the HMI test against the simulation and list the cases that failed.
What to watch out for when testing with AI
Simulation only
The PLCSIM tools work with the simulator only and cannot control a real PLC. The HMI test refuses to start if a machine runtime project is running on the computer.
A test checks only what it contains
The process models are simplified and the AI's plan is a proposal. Tests in simulation do not replace testing on the machine or the validation of safety functions.
Project settings
For loading into the simulator, simulation support for block compilation must be enabled in the project. The AI can enable it, and in V21 also virtual PLC support.
Known pitfalls
The AI warns about a version mismatch between PLCSIM Advanced and TIA Portal or about the default IP 192.168.0.1, with which the instance used to shut down when TIA V21 connected.
Values are restored
After each case the HMI test restores the original values in the simulated PLC. Two tests never run on one simulator at the same time.
Confirmation by a person
You confirm before the HMI test that it is a simulation. Verify position-based clicking on fields without text on your own project before you use the report as evidence.
FAQ about testing PLC programs with AI
Do I need S7-PLCSIM Advanced or is S7-PLCSIM enough?
For tests, S7-PLCSIM Advanced. The classic S7-PLCSIM has no public control interface, so you can load the program into it, but reading and writing tags, scenarios, unit tests and the virtual FAT do not work with it.
Which PLCSIM Advanced version do I need?
One that matches the TIA Portal version: at least V4.0 for V17, V5.0 for V18, V6.0 for V19, V7.0 for V20 and V8.0 for V21. TIA MCP compares the versions and warns about a mismatch.
What is the difference between a unit test and a virtual FAT?
A unit test checks one FB or FC: given inputs and expected outputs. A virtual FAT tests the program as a whole with models of motors, valves and measurements that react to the PLC outputs, and also checks reaction times.
Can the AI write to a real PLC during testing?
The PLCSIM and test tools do not: they load and write to the simulator only. Writing values and loading to a real PLC are separate functions, switched off for the AI by default. Only the user can switch them on, and even then they run only after the user confirms a preview and retypes the device name.
Does a process engineer need to program to write a test?
No. They fill in the scenario in an Excel template: what to set, how long to wait and what to expect. When the simulation is running the template also contains a list of tags. The AI runs the scenario and saves the report.
Does the virtual FAT report replace a real FAT?
No. It is a report of a program test on a simulation. It helps find errors earlier and prepare the FAT, but it does not replace the test with the customer on the real equipment.
How much does it cost?
It is part of TIA MCP. A PRO licence costs €295 per year per computer, excluding VAT, and you can try TIA MCP free for the first 7 days. For companies with several computers we offer an Enterprise licence.
Siemens, SIMATIC, TIA Portal, WinCC and S7 are trademarks of Siemens AG. TIA MCP is a standalone product of Benešl Automation, is not a Siemens product and communicates with TIA Portal through the official TIA Portal Openness interface.