EST. 2026 — Notes from real server work SYSADMIN · SECURITY · AI · DIRECTADMIN Issue 01
THE SYSADMIN ALMANAC
Home / Hardware / Taking Over a PLC Program: 12 Checks Before Editing a Line
Hardware

Taking Over a PLC Program: 12 Checks Before Editing a Line

by Ton-Or ·5 Dec 2026·12 min read
Taking Over a PLC Program: 12 Checks Before Editing a Line

A program that compiles and runs the machine can still have outputs written in two places or timers skipped on some scans. These problems can be found in text files before touching a single line of the program.

1-minute summary

Symptom / problem
A PLC program you inherit may compile and run yet write one output in several places or skip timer calls.
Who should read
Anyone taking over someone else's S7-1200/1500 program.
Fix in short
Run the 12-point checklist on the exported files without connecting to the PLC, write the report, and check side effects before changing anything.
Jump to steps

I needed to prepare a way to take over maintenance of PLC programs written by someone else. At first, I had two wrong assumptions. First, I thought a review required going online with the machine and checking the status of each network. Second, I thought a quick read-through would be enough to start making changes. Once I finished building the export tools, I realized that the most dangerous problems could be found in plain text files, and they were things a quick read-through would never catch. So I put together a 12-point checklist to work through before changing anything.

This checklist comes from my own research and tools, drawing on manuals, foundational documentation, and rules I wrote for AI to use when helping review S7-1200/1500 programs. It does not come from any customer project. All tag and block names in this article are generic, and the search scripts included here illustrate an approach. They are not tools that have already been proven on large projects.

This checklist does not certify machine safety

A file review can identify suspicious parts of a program. It cannot establish that a machine is safe. E-Stops, safety doors, and light curtains must use hardwired circuits or an F-CPU, and a qualified engineer must check them on the actual machine. Numbers such as analog raw-value thresholds depend on the module used. Follow the manual for that specific module.

Prepare the data first: work from exported files without going online

In TIA Portal V15.1, SCL code, DBs, and UDTs can be exported directly as text files. LAD must be exported as XML, then converted into text for each network. Tag tables can also be exported as XML. I covered the export mechanism and the pitfalls of importing changes back in the article on editing LAD through XML. Once all the files are ready, the entire review takes place on my own computer without touching the PLC.

Data preparationTIA projectarchive first->exportSCL / DB / UDT->LAD XMLconvert per network->tag tableXML->12 checkswrite report
12 checkscomplete before editing
27648analog full-scale raw value
32511above this is overflow
OB30-38where PID belongs

I organized the 12 checks into five groups and assigned three severity levels. These levels are my own classification, used to prioritize what to inspect first.

12 checks on exported files1 Double coilOutputs2 Gated timerTiming/edges3 absolute addressData/types4 NC/NO polarityOutputs5 No interlockOutputs6 Lossy conversionData/types7 Analog wire breakAnalog/PID8 PID outside OB30Analog/PID9 retainData/types10 Unused tagsData/types11 No step timeoutSequence/HMI12 HMI writes %MSequence/HMIHigh: wrong motionMedium: values/upkeepLow: organization
The 12 checks fall into five groups. Cell colors represent my own severity classification. The 6 red cells cover problems that can cause outputs or sequences to behave incorrectly even when the program compiles. Review this group first.

Outputs: checks 1, 4, and 5

Check 1: The same output or coil is written in more than one place, commonly called a double coil. The value sent to the terminal is the value from the last write in that scan. The others are silently overwritten. This rule is not specific to Siemens. Omron's basic manuals also state that the same output number must not be written more than once. To find this, search for assignments to each tag and count their locations. I wrote a rough search script like this.

import collections, pathlib, re, sys

ASSIGN = re.compile(r'("[^"]+"(?:\.\w+)*)\s*:=')
BLOCK = re.compile(r'^\s*(?:FUNCTION_BLOCK|FUNCTION|ORGANIZATION_BLOCK)\s+"([^"]+)"')

hits = collections.defaultdict(list)
for path in sorted(pathlib.Path(sys.argv[1]).glob("*.scl")):
    block = "?"
    text = path.read_text(encoding="utf-8-sig")
    for no, line in enumerate(text.splitlines(), 1):
        code = line.split("//")[0]
        m = BLOCK.match(code)
        if m:
            block = m.group(1)
        for m in ASSIGN.finditer(code):
            hits[m.group(1)].append((block, path.name, no))

for target, where in sorted(hits.items()):
    if len(where) < 2:
        continue
    blocks = {b for b, _, _ in where}
    level = "HIGH " if len(blocks) > 1 else "CHECK"
    print(level, target)
    for b, name, no in where:
        print("     ", b, name, "line", no)

Results marked HIGH are global tags written from more than one block. CHECK means multiple writes within the same block, which may simply be normal IF and ELSE branches and need manual inspection. This script checks only SCL. For LAD, search for the tag names again in the text converted from XML. It also does not recognize writes through pointers or whole-byte writes that overwrite the bits inside.

Check 4: Stop, Overload, and E-Stop polarity. These devices should be wired NC so that a broken wire stops the machine. This means the signal is 1 under normal conditions. A common mistake is logic that reads the signal as though it were NO, or vice versa. This check cannot be completed from the program alone. Compare the comments in the tag table with the electrical drawings.

NC wiring

1 = normal, 0 = pressed or broken wire

In the logic, the run condition must read the signal directly. For example, DI_M01_StopPB must be TRUE to allow running, and the overload fault is the NOT of the signal. If NOT appears before the Stop button in a run condition, treat it as suspicious.

NO wiring

1 = pressed, 0 = normal or broken wire

This suits a Start button because a broken wire only prevents starting. If a stop button is wired this way, a broken wire makes it unable to stop the machine, with no warning. Record this as high severity in the report even if the logic correctly matches the wiring.

Check 5: Missing interlocks. Look for two patterns: motors that can start without a fault or permit condition, and forward-reverse pairs with nothing preventing both outputs from turning on together. To find these, inspect every line that writes to a DO_ output and check whether its conditions include the fault name and the opposing output's name.

Timing and signal edges: check 2

Check 2: A timer, counter, or R_TRIG instance is called conditionally or shared between two tasks. An IEC timer advances when it is called. If it sits inside an IF that is skipped on some scans, its time or Q will hold its previous value. R_TRIG stores the previous scan's value in its instance. If two tasks share the same instance, one task can consume the other's edge.

// น่าสงสัย: timer ถูกเรียกเฉพาะตอน Auto เป็น TRUE
IF #Auto THEN
   #tDelay(IN := #LevelHigh, PT := T#5S);
END_IF;
#ValveOut := #tDelay.Q;

// ถูก: เรียกทุก scan แล้วเอาเงื่อนไขไปไว้ที่ขา IN
#tDelay(IN := #Auto AND #LevelHigh, PT := T#5S);
#ValveOut := #tDelay.Q;

To find this, locate every line that calls an instance and check whether it is indented inside an IF, CASE, or FOR. Also count how many places call the same instance name. There are two additional checks in this group that I found in the rules I collected. Counting parts using a signal level instead of an edge counts on every scan for as long as the sensor sees the part. A WHILE NOT loop waiting for a signal in SCL stalls the scan and must be written as a state machine using CASE.

Data and types: checks 3, 6, 9, and 10

Check 3: Absolute addresses in logic. This means using %I, %Q, %M, or %DB directly instead of symbolic tags. Readability is not the only problem. If someone moves a wiring connection and updates the tag table, logic that references the address directly will not follow the change. This is the easiest check to search for in the entire set.

# absolute address ที่หลุดเข้ามาใน logic
Select-String -Path .\export\scl\*.scl, .\export\lad\*.txt -Pattern '%(I|Q|M|DB)[BWDX]?\d' |
  Select-Object Filename, LineNumber, Line

# ลูปรอสัญญาณ กับการแปลงชนิดที่ต้องเปิดดูทีละจุด
Select-String -Path .\export\scl\*.scl -Pattern 'WHILE\s+NOT', 'REAL_TO_INT', ' / ' |
  Select-Object Filename, LineNumber, Line

Check 6: Type conversions that lose values. REAL_TO_INT without a range check before conversion, division where the divisor can be zero, and array indexes taken from variables without bounds checking. All three compile successfully. The search commands above only produce a list of locations to inspect. A person must decide whether the incoming values could be out of range.

Check 9: Retain and non-retain. Check counters, operating hours, and recipes to see whether they are intended to survive a power loss. This can go wrong in two directions: values that should be retained disappear, or values that should restart are retained, such as a sequence step that persists across a power loss. Read the attributes in the DB source, then ask the machine owner which behavior is required.

Check 10: Unused tags and blocks, missing comments, and inconsistent naming. This has the lowest severity in the set, but it indicates how difficult the other problems will be to find. I use a readable structure as a reference: OB1 calls only FCs and FBs; IO, Devices, Process, and Comm are grouped separately; devices with state use FBs and instances; settings and HMI data live in global DBs; and repeated structures use UDTs. A program that differs greatly from this structure is not necessarily wrong, but it means I need to allow more time to read it.

Analog and PID: checks 7 and 8

Check 7: Analog inputs without wire-break checks or clamping. Siemens raw values range from 0 to 27648, where 4 mA or 0 V is 0, and 20 mA or 10 V is 27648. If the raw value is far above 27648 or exceeds 32511, it indicates a wire break or overflow. A program that scales the raw value directly produces an engineering value that looks reasonable but is wrong, then passes it to the logic for decisions. The expected pattern is:

#WireBreak := (#Raw > 27648 + 1000) OR (#Raw < -1000);
#norm := NORM_X(MIN := 0, VALUE := #Raw, MAX := 27648);
#Value := LIMIT(MN := #LoEng,
                IN := SCALE_X(MIN := #LoEng, VALUE := #norm, MAX := #HiEng),
                MX := #HiEng);

To find this, locate every call to NORM_X or SCALE_X and check for raw-value range checks and LIMIT nearby. Also check whether the resulting WireBreak is used elsewhere or merely calculated and left unused.

Check 8: PID_Compact outside a cyclic interrupt OB, meaning OB30 through OB38. If called from OB1, its period varies with the scan time, while PID calculations assume a constant period. Find which block calls PID_Compact, then trace upward to identify the originating OB.

Sequence and HMI: checks 11 and 12

Check 11: A sequence with no abort or reset path and no alarm when a step exceeds its time limit. A single failed sensor can leave a step waiting forever, with the machine sitting idle and no indication of what it is waiting for. In the CASE, check whether each step has an exit other than its normal condition, and whether a timer tracks the time spent in that step.

Check 12: The HMI writes directly to %M bits scattered throughout the program instead of going through a central HMI DB. As a result, the PLC program alone does not reveal which bits have external writers, and this can lead back to check 1. Compare against the tag list in the HMI project. An additional note for Basic panels: discrete alarms number the bits in a Word with the bytes swapped. Bit 0 of the Word is bit 8 on the HMI. If the project has no table mapping bits to alarm messages, create one before changing anything.

If the program receives data from another PLC

These 12 checks cover the program within a single PLC. If data arrives from another PLC, also check whether that data has a freshness indicator and what happens to the outputs when the link is lost. I covered this separately in the PLC-to-PLC link review checklist.

Report the findings and check side effects before submitting changes

A useful report must identify locations that someone else can navigate to. Every finding needs a block name, a network number for LAD or a line number for SCL, a severity level, and a proposed fix. I use this format. The contents illustrate the format and are not findings from a real project.

[
  {
    "rule": 1,
    "severity": "high",
    "block": "FB_Motor",
    "where": "SCL line 42 และ FC_WriteOutputs network 7",
    "finding": "DO_M01_Run ถูกเขียนสองที่",
    "fix": "ให้ FB_Motor เป็นที่เดียวที่เขียน แล้วให้อีกจุดส่งคำสั่งผ่านขา StartCmd"
  },
  {
    "rule": 7,
    "severity": "high",
    "block": "FC_AnalogScale",
    "where": "SCL line 15",
    "finding": "scale ค่า raw โดยไม่ตรวจช่วงและไม่ LIMIT",
    "fix": "เพิ่ม WireBreak กับ LIMIT ตามรูปแบบมาตรฐาน"
  }
]

Once I reach the editing stage, I have four more side-effect checks to complete before submitting any changes.

  1. The modified UDT or DB is used only where intended, and no other blocks depend on its old structure.
  2. Any spare tag being put into use really had zero references before it was selected.
  3. Wider tags such as byte or word do not overlap bits already in use.
  4. No new absolute addresses have slipped in with the changes.
What exported files do not tell me

Forces still active in the machine are not included in the project files. They must be checked on the machine. An illuminated MAINT light means a force is active, and it must always be removed before leaving the site. Another issue is that the program in the machine may differ from the files received. Before trusting the review results, have the person responsible for the machine compare the online and offline versions.

Rules when using AI to help review

I also wrote this checklist for AI to use, because finding duplicate assignments and conditionally called instances is work that AI can do faster than a person when reading text files. But there are four rules I do not allow it to skip.

  1. Code from AI must compile, pass simulation, and pass human review before being loaded onto the machine.
  2. E-Stops, safety doors, and light curtains use hardwired circuits or an F-CPU. They are not ordinary logic for AI to edit.
  3. Archive the project before every automated import.
  4. Do not send projects covered by confidentiality agreements to cloud AI.

Before editing someone else's program, I export everything and work through the six red cells first: checks 1, 2, 4, 5, 7, and 11. Then I cover the rest, write a report with traceable locations, and discuss what to change with the machine owner. Whether I go through all 12 checks every time or select only the groups relevant to the planned changes depends on the size of the job and the time available.

What I have not done yet is apply this checklist and these search scripts to an entire large program and count how many actual findings each check produces. The double-coil search also does not yet cover LAD. Once I have done that, I will come back and update the checklist if any items need adding or removing.

Hit something like this? Stuck somewhere?

Come trade notes on the LinuxThai board

→ Continue on the board

Comments 0

No comments yet — be the first