DanoMagnum.com

>Pyladderlogic 

Last Edit: Jan. 10, 2012, 7:55 p.m.

Ladder Logic in Python: PyLadderLogic

I've always thought it would be pretty handy to have a ladder logic simulator that you could run on your computer, particularly for people trying to learn how it works. I started this project a while back and dropped it, but decided to finish it this weekend. It's a little sloppy, but I'm fairly pleased with the results. As a bonus, this was my first real in-depth use of tkinter.

Now on to the neat stuff.

Here is a screenshot of the interface. There are add rung, save, and load buttons at the top. Below that is the display of all the "IO". You can right click on just about anything in the window to add in the logic, set values, or add descriptions to the bits/words/etc. New in version 2 is the ability to increase the IO on the fly.

The neatest thing about it is that it would be easy to add output blocks which could do all sorts of interesting things: save files, open webpages, whatever!

What use is it? Well, I figure the biggest use would be as a teaching tool for people wanting to learn to program PLCs but don't have access to one.

It's kind of messy and a little buggy, but the proof of concept is there, and all in all it's fairly straightforward once you know how tkinter works. I have been tweaking it, adding features, and debugging and it's getting better and better.

Save files are XML with the following format:


	
		
			I0:1
			bool
			
			0
		
		
			I0:2
			bool
			
			0
		
		
			O0:0
			bool
			
			0
		
		
			B0:0
			bool
			
			0
		
	
	

		
			
				And
				
					I0:1
					I0:2
					
						Not
						
							B0:0
						
					
				
			
		
		
			
				Close
				
					O0:0
				
			
		
	

In the live version the display code and underlying code are now separate. Also, you can add IO on the fly now and I've added a few new functions.

New: The "live" version now has faults.

"Live" Version:

Version 2:

Version 1: