Comments and Documentation
Comments are an essential part of writing maintainable, readable, and collaborative PLC programs. While Structured Text is readable compared to graphical languages, clear comments help explain why something is done — not just what is happening.
Comment Syntax
Structured Text supports two styles of comments:
- Single-line comment:
// This is a single-line comment
- Multi-line comment:
/* This is a
multi-line comment */
Use // for quick notes, and /* */ when longer explanations are needed.
Best Practices for Commenting
-
Comment why, not just what: Avoid restating the obvious. Instead, explain the purpose, reasoning, or conditions behind a decision.
-
Be concise and clear: Write comments that add value without clutter.
-
Document assumptions and edge cases: Explain any non-obvious logic, limitations, or dependencies.
-
Use comments for organization: Add section headers or logical breakpoints in large programs.
-
Avoid outdated comments: Make sure comments stay up to date with code change
Examples
// Motor control logic
IF Start_Button THEN
Motor_Start := 1;
END_IF;
// Reset alarm if acknowledged and fault is cleared
IF Ack_Button AND NOT Fault_Active THEN
Alarm := 0;
END_IF;
// Increment count on rising edge
IF Pulse AND NOT Last_Pulse THEN
Counter := Counter + 1;
END_IF;
Last_Pulse := Pulse;
// Safety lockout section
/* Prevents motor restart after emergency stop
until reset is confirmed */
IF E_Stop THEN
Motor_Enabled := 0;
ELSIF Reset_Button THEN
Motor_Enabled := 1;
END_IF;
Final Tip
Use comments for the next person who will read your code — which might be you six months from now.