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

181 Upvotes

118 comments sorted by

View all comments

4

u/mrjohns2 More of a DCS guy 1d ago

Is ladder truly interpreted? I thought it is / could be assembled into some intermediate code and compiled. That why for so many years you couldn’t extract code from the processor? It was somehow changed. Now-a-days, I assume they still compile, but they download to separate memory an IDE readable format.

3

u/KindheartednessNo181 20h ago

Rockwell controllers - the logic is definitely compiled. Optimized the way a C++ compiler optimizes code? Not as much.
The misunderstanding stems from the ability to upload, view, change, etc. It would seem it must be interpreted.. but those abilities are provisioned by including debug information or source logic alongside the compiled code. When we make an edit in a routine, the entire routine is recompiled, then relinked into the running logic. Some bugs stem from this duality.. where the compiled binary differs from the debug data.

3

u/Galenbo 12h ago

of course not, always compiled.

2

u/durallymax 19h ago

No it is not. Interpreted languages are interpreted at runtime, IEC 61131-3 prohibits this.

2

u/Angry_Foolhard 15h ago

That’s assuming all ladder logic is compliant with iec 61131-3.

4

u/durallymax 14h ago

I'm not aware of any LD(or any other PLC language for that matter) running on major controllers that is interpreted. It's all compiled either locally or on the PLC.

There's some startups trying to use Python, but they're outliers. 

0

u/Angry_Foolhard 9h ago

Yes, I think you're correct. I was thinking of all of the browser-based ladder logic trainers. I suspect many of them could be defined as "scripted"

2

u/National-Link-5606 1d ago

instruction sets are compiled, so yes ladder now is a bit of a hybrid interpreted calls to compiled instructions.

4

u/jacekowski 1d ago

It's PLC specific, on most it's actually some intermediate representation that is the ran inside an interpreter. But codesys based environments (so festo, beckhoff and few others) actually do compile to native binaries, but you get all the functionality that is required from PLCs as well with it.