Hydroautomatyka

Engineer Zone

ST code refactoring

Practical demo showing how we transform hard-to-maintain Structured Text into cleaner and service-friendly PLC logic.

Technical demo

ST spaghetti -> refactor

This interactive demo presents our approach to improving Structured Text readability and long-term PLC maintainability.

1. ST logic refactoring example

Choose scenario

Each scenario has its own code sample, quality metrics and change list.

Available examples: 2

START/STOP + indicator lamp + TON

Typical motor run logic with timer confirmation and lamp signaling, cleaned up for diagnostics and maintenance.

Available examples: 2

start-stopindicatortonreadabilitydiagnostics

Before

(* START / STOP + lampka + TON - wersja przed refaktorem *)IF StartPB THEN    MotorRun := TRUE;END_IF; IF StopPB THEN    MotorRun := FALSE;END_IF; IF MotorRun THEN    LampCmd := TRUE;    DelayTON(IN := TRUE, PT := T#5s);    IF DelayTON.Q THEN        RunConfirmed := TRUE;    END_IF;ELSE    LampCmd := FALSE;    DelayTON(IN := FALSE, PT := T#5s);    RunConfirmed := FALSE;END_IF; IF FaultActive THEN    MotorRun := FALSE;    LampCmd := FALSE;END_IF;

Before

We will show how we structure PLC logic

After a quick code review, we identify technical risk points and define a safe refactoring plan for maintainability.

2. What we improved

The list of improvements appears after the refactoring step is completed.

3. Quality metrics

Before/after metrics are shown after the cleaned-up variant is generated.

4. Need a similar cleanup on your PLC codebase?

We can audit existing logic and deliver a safe, phased PLC refactoring plan.

Contact us

Disclaimer: Educational demo. The snippet is vendor-neutral and demonstrates refactoring approach only.