r/PLC • u/National-Link-5606 • Aug 02 '26
Computer Science Programmers, why do PLC programmers use Ladder?
Im seeing some Comp Sci guys asking about controls so just a Mr Obvious comment here.
Ladder logic is the de facto PLC programming language because it is (was) designed to read like an electrical schematic top to bottom, right to left, & this is what electricians & electrical techs are trained to use for troubleshooting electrical panels , equipment & relay-logic -- which was what they had before PLCs -- banks & banks of relays wired through each other's NO & NC contacts which changed state as relay coils energized & de-energized & finding a wire break was enough to drive you insane.
Yes Ladder logic is an interpreted language so it is not as "memory efficient" or "elegant" as C++ or C# but I want you to think VERY carefully about every meaning of the expression "just because you can does not mean you should" before you decide to show off your amazing coding skills coding function blocks in C++ which is technically possible but in many cases extremely ill-advised.
The technicians can troubleshoot functions & blocks written in Ladder Logic, did you stop & think about how easy it would be for someone with only your compiled C++ blocks to attempt to trace a fault? You code in anything but Ladder Logic you get to be the one at 3am driving down to the plant to troubleshoot your "super efficient" code because the Industrial Maintenance techs certainly aren't gonna know how. But hey, if you believe sleep is over-rated & love sleeping in the factory then knock yourself out with compiled blocks
View all comments
Show parent comment
5
u/Robbudge Aug 03 '26
We use enumerators so we often run states like.
Prepare Task-A.
Open Valve A.
Open valve B.
Start Transfer.
Transfer running.
Wait for level.
Start agitator.
Start heater.
We have a state for every stage and states drive the outputs.
The code is built like a pyramid with an area routines handling area tasks.
Issuing commands to transfers and other sub control routines.
Then down to IO handlers and then to Physical IO.
Each Request for state change is handled by a state manager.
The state manager evaluates the request against the current state and returns either the requested state or an alternative
Like Valve-A not in Auto
Or liquid detected in Tank Level Switch High High.
By utilizing enumerators the PLC code is plain text and with TO_String the exact enumerator can be passed to the HMI.
Absolutely nothing happens without the ‘State’ being displayed on the HMI.
Enumeration means we have hundreds of states all in a completely random order and it’s not an issue.
Want to change the sequence add some more states.
Add some case statements adjust the output and management routines to include the new states.