View Single Post
Old October 11th, 2002, 02:25 PM   #7
Bill Simpson
Lifetime Supporting Member

Bill Simpson is offline
Join Date: Apr 2002
Location: Whitby, Ontario
Posts: 85
Essentially it sounds like you want to emulate the operation of a PLC in code, but you haven't made it clear whether this code will be running on a desktop system or on some form of mpu based I/O board you've developed. In ether case you're faced with writing a ladder logic interpreter, plus an editor that may or may not run on the same computer. Once you have these 2 programs functional, you will still be faced with updating the status of the editor's rungs using info obtained from the running PLC interpreter. The PLC program will of course be scanning the user's program and updating the I/O while in the run mode. If you want online editing, then all the more work. No small task, but it can and has been done.

I've had to do basically the same thing in order to create PLC simulators for training purposes, and I can assure you it's no trivial task. The Ladder logic interpreter is actually the easy part of the equation, while the editor and status updating can be a major challenge, particularly if you get fancy and try to emulate something like the RSLogix editor. Many people believe PLC programs are compiled, which is typically only partly true. Of course your PLC interpreter will be compiled, but if you ever tried to recompile a program while it's executing; then you'd know why the user program is interpreted if you're going to offer on-line editing. The simplest approach is to have the editor send simple ascii representations of each rung to the PLC. (SOR,XIC,I:1/0,OTE,O:2/12,EOR" would get all the required info for a simple rung to the PLC and is fairly easy to decode particularly if you stick to common AB type instructions or similar: Start of Rung, Examine input closed at bit location I:1/0 etc etc.etc. Want a bit more speed; then pre convert the instructions into byte offsets that address indirectly to your code for the appropriate instruction. Lots of fun to be had here, but wait till you tackle the editor!

Once you've gone through this exercise, you'll no doubt have an an appreciation of why AB doesn't want to give their software away.

Best of luck!
  Reply With Quote