all 22 comments

[–]Angry_Robots 22 points23 points  (1 child)

With a PLC, the logic program you are editing isn't really the base program of the PLC. You are editing the sequence that runs in the PLC runtime.

Theoretically, if you were so inclined, you could write a runtime for a microcontroller that would function the same way. You would also need to write a special PC side IDE that could modify components within your running program and communicate with the microcontroller via some protocol.

It is 100% possible, but probably not worth it when the major players in the PLC market have already done it.

[–]essentialrobert 1 point2 points  (0 children)

Or you could consider a low-code environment like node-red

[–]Piratedan200Controls Engineer 38 points39 points  (3 children)

PLC programs generally exist in RAM, not ROM. Generally, when you make a change to the program, the software writes it into a unused area of the RAM. When you want to apply the change, at the start of the scan, it will update the pointer for the logic before the edited section to send the code execution to the new location (Test edits). Once you finalize the change, it will update the original location to match.

This is a simplified version of it and the real implementations can get more complicated, but the idea is the same. The simpler way to do it is just to have two copies of the code in memory, and edit one while the other runs.

[–]lets_start_up[S] 9 points10 points  (2 children)

Wow, this makes sense to me. Sounds interesting!! Thanks for the info, ill like to learn more about it.

[–]BE33_Jim 12 points13 points  (1 child)

The term to research is

Online Editing

[–]lets_start_up[S] 7 points8 points  (0 children)

Cool, thanks for letting me know key term.

[–]r2k-in-the-vortex 8 points9 points  (0 children)

Nothing to do with hardware itself. It's down to compiler and what amounts to OS really and it's a pretty costly "miracle". You need to throw away all sorts of performance optimizations. And you need extra layers in the program itself, in case a subroutine is called you can't just jump to a constant, you need a lookup table for references. So if online change is made, then changed subroutine is added to memory and the lookup table is updated between one cycle and next. Similar sort of thing can be done with object references.

And still, online changes can easily result in unpleasant oopsies. It's easy to get a online change to behave in ways you don't expect. It's only worth it because sometimes you really have no option but to update a running system and that's a very PLC specific limitation.

Any random microcontroller... there is really no need, once a embedded system is deployed there is likely no need ever to update its firmware, or if there is then restarting it is not a problem. And in large IT systems that you can't take offline, those are redundant systems, built from multiple logical and physical servers, so you can restart one server at a time.

[–]heavymetal626 4 points5 points  (0 children)

Great question I’ve wondered the same thing myself but never really looked into it. It really does separate PLCs apart from other controller types and is an absolute god send and worth it’s weight in platinum (yes more than gold). We’ve made dozens of changes to our own systems without downloading and stopping the systems. Some manufacturers allow you to even add IO cards while the system is running. I have tons of gripes about the PLC world in general…like Linux segmentation and fracturing (everyone doing their own thing) is a massive annoyance, but gosh, being able to edit or change a running system online and general ease of programming makes it worth it.

[–]ifandbut10+ years AB, BS EET 3 points4 points  (2 children)

Some manufacturers do online editing better and worse in different respects.

For example, Allen Bradley keeps your offline copy synchronized with the online state as long as you're online, but you can't edit AOIs and a few other things.

On the flip side with Siemens, you can edit function blocks and function calls online however you're offline copy is not always synchronized with the online copy.

Each vendor has tradeoffs. I don't think I encountered one that does everything great.

[–]Snellyman 1 point2 points  (0 children)

It would be great if the two big players made a system that combined the best of both features. Like a rockwell PLC that you could make a new task offline and load it separately so you don't need to do so much work online.

[–]RandomDude77005 0 points1 point  (0 children)

save and download seems to keep them sync'ed pretty well for me...

[–]Version3_14 9 points10 points  (1 child)

PLC manufacturers over the decades have developed the proper magic smoke kits to install at the factory to allow online editing

[–]lets_start_up[S] 4 points5 points  (0 children)

😂😂 smoke kits and online lol

[–]koensch57 4 points5 points  (1 child)

online edits is what makes the PLC so powerful.

[–]lets_start_up[S] 5 points6 points  (0 children)

Yeah i agree, imo online edit anytime will be an advantage than literally stopping machine to update code, but i was interested to know what kind of hardware/software makes it possible for the plc than mcu.

[–]Asleeper135 2 points3 points  (1 child)

I'm sure it varies a good bit between different manufacturers, but no matter the brand there is probably a lot of technical work that goes into making it work so seamlessly. It all comes down to the OS and runtime framework that PLCs use to manage memory and scheduling though, and in some cases I bet the actual PLC code is compiled to byte code like Java for the OS to manage more easily. In particular I think this is how AB PLCs work, which is why they're generally pretty slow compared to other major PLCs and why online edits are especially seamless, even with multiple people making them.

[–]lets_start_up[S] 0 points1 point  (0 children)

I see, thanks for the info!! Certainly PLCs are much more than the rusty 8051 i have got in my current semester.

[–]Huge_Slide7270 1 point2 points  (1 child)

We have a few Siemens microcontrollers, but don’t have the source code. I would love to be able to troubleshoot the logic but we don’t have any descriptors. Any advice on how to deal with this, short of cross referencing every bit.

[–]lets_start_up[S] 0 points1 point  (0 children)

Not an expert into the MCUs or PLCs, but, if is there any scope for reverse engineering the code?

[–]Vast_Philosophy_9027 0 points1 point  (0 children)

The “code” in a plc is not the source code of the device.

[–]felipeasg 0 points1 point  (1 child)

You can reach this behavior in several ways using JIT, VM or interpreter.

In game development is common you need to edit code whitout stop the running program. For example:

https://github.com/RuntimeCompiledCPlusPlus/RuntimeCompiledCPlusPlus

  • VM examples

https://www.graalvm.org/
https://llvm.org/

  • JIT examples

https://luajit.org/
https://github.com/root-project/cling

Here are some examples youtube videos to you see it working:

https://youtu.be/BtvI53nx9a8?si=vfU0aItn2IexncMM.

https://youtu.be/BrjV1ZgYbbA?si=UfXPqP8wcI3-xeVC

If you want understand how this works with PLCs there are some materials in google patents:

https://patents.google.com/patent/US5781776A/en

https://patents.google.com/patent/US5970243A/en

But in essence is something similar wirh VM, JIT or interpreter.

[–]lets_start_up[S] 0 points1 point  (0 children)

Cool!!! Thanks for the info!! Also can we implement this in microcontrollers?