Rules / output-stuck-outside-modes
An output freezes when no mode branch applies
A discrete output is switched on and off inside the AUTO and MANUAL branches, but there is no fallback branch and nothing outside the chain touches it. In any state not covered by a branch it keeps last scan's value.
Severity: Warning
Rule id: output-stuck-outside-modes
Output freezes when no mode branch applies
What the rule checks
Unit control is often written as a chain of modes: IF sensor_ok AND AUTO THEN … ELSIF MANUAL THEN … END_IF. A discrete output (open/close, start) is switched on and off inside every branch. If there is no fallback branch and nothing outside the chain touches the output, then in any state not covered by a branch (sensor fault, selector at OFF, lost link) the output keeps last scan's value. If an open command was active at that moment, the relay stays energised until the limit switch, and the software position estimate stops updating. The rule leaves set/reset latches alone (a branch that only sets or only clears the output is meant to hold state) as well as chains whose conditions cover every combination.
What it does to the plant
On a sensor fault or with the selector at OFF, the "open" relay stays energised until the limit switch.
Example
VAR_GLOBAL xSensorFault, xAuto, xManual, xBtnOpen : BOOL; rPidOut : REAL; xOpen : BOOL;END_VARPROGRAM ValveCtrlIF NOT gvl.xSensorFault AND gvl.xAuto THEN IF gvl.rPidOut > 1.0 THEN gvl.xOpen := TRUE; ELSE gvl.xOpen := FALSE; END_IFELSIF gvl.xManual THEN gvl.xOpen := gvl.xBtnOpen;END_IF
VAR_GLOBAL xSensorFault, xAuto, xManual, xBtnOpen : BOOL; rPidOut : REAL; xOpen : BOOL;END_VARPROGRAM ValveCtrlIF NOT gvl.xSensorFault AND gvl.xAuto THEN IF gvl.rPidOut > 1.0 THEN gvl.xOpen := TRUE; ELSE gvl.xOpen := FALSE; END_IFELSIF gvl.xManual THEN gvl.xOpen := gvl.xBtnOpen;ELSE gvl.xOpen := FALSE;END_IF
Both listings are run through the linter by an automated test: the rule fires on the first and stays silent on the second.
How to fix
- Add an ELSE branch that puts the output into a safe state (usually both relays off), or reset the output before the chain.
- Agree with the process engineer what is safe for this unit: for some it is stop, for others fully open; either way the decision belongs in the code, not in the previous scan.
Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.
The same linter without uploading a file: command line and GitHub Action.
Related rules
2026-11-26