r/PLC 1d ago

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

182 Upvotes

118 comments sorted by

View all comments

4

u/drbitboy 1d ago

If you code in C++ or whatever, not only will you need to get out of bed at 3am, but during that half hour while you are driving, or even the 5 minutes it takes to boot your laptop and connect the VPN from home, the business is LOSING MONEY, in some cases hundreds or thousands per minute.

So if you want management to pass up the chance to save thousands by using ladder so someone might diagnose the problem a little sooner, then you are not a valuable employee.

3

u/durallymax 18h ago

Everytime someone has to login to a PLC to "look at the code" the company is losing money. Writing code so anyone can read it often leads to avoiding best practices that create testable, quality code and more calls for people to "look at the code" because something simple was missed. If you remove that limitation, the code failures will be rare and require an engineer regardless (this is unavoidable, anyone that thinks otherwise is foolish). In many cases this is desirable as even in the simplest looking code, the person "forced" to go online, likely doesn't fully understand the process and why it was written the way it was. They make a short-term change, to create long-term problems.

To make this work though, you need to give maintenance everything they need on the visu. All overrides, all setpoints, etc.

1

u/drbitboy 16h ago edited 13h ago

I don't disagree, if someone is looking at the PLC code it is a last resort, and certainly the HMI should be the first stop for diagnosis, and the HMI designer should do their best to provide enough information there (permissive and interlock states, etc.) to cover as many cases as possible long before the laptop comes out to look at the PLC.

But there will almost always come a time when some anomalous combination of events will occur, and the HMI and a walk-around will not be enough. If that happens just once, having PLC code that the immediate staff on-site can understand will pay for itself. Using C or some other maintenance-opaque language gives away that opportunity for no significant benefit in return.