AI review of a PLC program before FAT: code review in TIA Portal
Before the FAT (factory acceptance test) a programmer wants to be sure that nothing is left in the program that could pop up during the test: an output written twice, an instruction error that is never evaluated, a forgotten test block. Going through hundreds of networks by hand is slow and tiring, though. We describe how to split a PLC program review between automated checks, AI and a human.
Why do a code review of a PLC program
Errors found at the desk are the cheapest. At the FAT they cost the customer's time, during commissioning the whole team's time and in operation production. Yet many typical errors follow a clear pattern and can therefore be found automatically.
What the automated block review checks
TIA MCP contains deterministic checks, i.e. rules that give the same result every time. The AI runs them on the project, sorts the results and explains them. For a single block it checks:
- multiple coils and writes to the same variable,
- unused variables and outputs that are never written,
- temporary variables read before they are written,
- CASE without an ELSE branch and division by a variable,
- conditionally called timers and edge detection,
- instructions whose STATUS or ERROR is not evaluated,
- WHILE and REPEAT loops, deep nesting and magic numbers,
- absolute addresses instead of symbols, missing documentation and compliance with naming conventions.
Each finding has a severity, a rule, a network or line number and a recommendation. The check changes nothing in the project.
Checking the whole PLC and project
- The program review goes through all FBs, FCs and OBs in the PLC or in a selected folder, sorts findings by severity and shows the worst blocks and global operands written from several blocks.
- Unused objects: blocks, data blocks, UDTs and PLC tags that nothing refers to, and dead code called only from unreachable blocks. This is a heuristic that does not cover HMI, OPC UA or absolute addressing, so everything is verified in the cross-references before deletion.
- Naming conventions: variable and tag names against your rules, prefixes per interface section, missing parameter comments and unused Static and Temp variables, with suggested fixes.
- Cross-PLC check: duplicate IP addresses and PROFINET names, communication blocks, and DBs and UDTs with the same name whose structure has drifted apart between PLCs.
- Alarms: priority distribution, missing and duplicate texts and alarms without operator guidance, following ISA-18.2 recommendations.
For a quick check of a single block, just right-click the block in TIA Portal: the Copilot add-in in TIA Portal offers an explanation or a code review of the selected block.
The safety program
For F-CPUs (S7-1500F) TIA MCP checks the safety program separately: F-I/O reintegration and acknowledgement, F-parameters and discrepancy times, F-cycle and watchdog, F-blocks that are not called or not compiled, and a comparison of signatures with the state saved after the last validation. A changed signature means a new validation is needed.
It is an aid for the programmer, not a replacement for certified validation according to IEC 61508 or ISO 13849. A qualified person is responsible for the safety program.
Output to Excel and PDF
The overall project audit combines the review of all PLCs, the cross-PLC check and unused objects into one verdict and saves the report to Excel or Markdown. The list of unused objects and the safety review result can also be saved to Excel. The code review result is also part of the software handover documentation in PDF. For the FAT itself, TIA MCP generates an I/O checklist in Excel with OK and NOK columns.
What the AI does and what the human does
Rules find patterns. The AI sorts the results, tells real errors apart from intent, for example a bit deliberately written in different steps of a sequence, explains them clearly and suggests a fix. After your approval it writes the fixes with a backup.
Automated checks cannot tell whether the program does what the machine is supposed to do. Only a functional test verifies that, first in simulation and then at the FAT.
Checklist before FAT
- The whole project compiles without errors and the warnings have been reviewed.
- The program review has no error-level findings; warnings are fixed or justified.
- No output or global operand is written from several places without a reason.
- Instructions with a STATUS or ERROR output are evaluated.
- Unused blocks and test code have been removed.
- Names and comments follow the conventions, networks have titles.
- The safety program has a current signature that matches the last validation.
- IP addresses and PROFINET names are unique, communication DBs match between PLCs.
- Alarms have texts and operator guidance.
- The I/O checklist is ready and functional tests have been run in simulation.
- A backup of the project version going to the FAT is stored.
Frequently asked questions
Can AI review a PLC program?
Yes, if it has access to the program. Through TIA MCP the AI runs deterministic checks on blocks and the whole PLC, explains the results and suggests fixes. It does not replace a functional test on the machine, though.
What does a PLC code review check?
Typically multiple writes, unevaluated instruction errors, conditionally called timers, unused variables and blocks, absolute addresses, naming conventions, documentation and, for F-CPUs, the safety program.
Does an AI review replace validation of the safety program?
No. The safety review is an aid that points out typical shortcomings and signature changes. Validation according to IEC 61508 or ISO 13849 remains the job of a qualified person.
Can the review result be saved to Excel?
Yes. The project audit is saved to Excel or Markdown, the list of unused objects and the safety review to Excel as well, and the code review result is part of the handover documentation in PDF.
Related articles
- ChatGPT and Siemens PLCs: what AI can and cannot do in TIA Portal
- Converting STL (AWL) to SCL with AI: procedure and pitfalls
Preparing for a FAT?
Try the program review on your own project. TIA MCP works with TIA Portal V17–V21, and the first 7 days are free.