Click here to Skip to main content
Click here to Skip to main content

A PLC simulator for WINDOWS

By , 28 Sep 2008
 

Download IO_SIMULATOR.zip - 46.06 KB

Download PLC.zip - 70.53 KB

Download resource.zip - 423 B

Introduction

Here is my first version of PC PLC simulator program. I dreamed about it for almost 15 years and now my dream come true. 


I’ll keep it as real as possible, if I have plenty of time. Any contribute is thankful.
Programmable Logic Controller was designed for most industrial application.
In order to control peripheral electronic devices such as Relay、Magnetic-contactors、solenoid valve…etc. It is intended to be an Interpreter.


The PLC programming language is knowen like ladder diagram symbol, Person who is familiar with electronic automatic control, should be familiar with it. PLC was controlled by input and ladder program after program computation PLC will control output, after all you can control electronic devices as you want.

Overview

PLC.exe is a Programmable Logic Controller simulator program. It is parsing ladder program, reading input and doing computation then doing output.


In the simulator environment, we don’t need I/O control card. I have wroten a program IO_SIMULATOR.exe to simulator input and output via file input.txt and output.txt the example ladder program also included in files for downloading
running screen snapshot


1. the PLC program running, click Sel Ladder file to load ladder program

pic1.jpg

2.Select ladder file

pic2.jpg

3.Click Run to start PLC

pic3.jpg

4.You can stop at any time as you want by click Stop

pic4.jpg

pic5.jpg

5.After PLC is running, you can use IO_SIMULATOR.exe to simulate input and watching output.

pic6.jpg

6.click X000 and X001 to switch on input X000,X001 then ouput Y000 will switch on by PLC.

pic7.jpg

7.click X006 to switch on input X006 after 5 sec output Y002 will switch on by PLC.

pic8.jpg

pic9.jpg

8.click X002 to switch on input X002 in order to switch off output Y000(in our ladder program Y000 with Counter were mutually exclusive) then click X005 on/off for 5 times then output Y002 will be switch on by PLC

pic9.jpg

You can enjoy editing ladder program to test PLC program in ordering to check whether it is enough or any suggest.

Improvements

I know it’s just simulator, but after improvI/O control module it can be real PLC for daily life. 

Technical details

I hope I can provide all of design document including Flow diagram,status diagram but it will take many time.


PLC program just implement a multimedia timer to computation timer object and parsing,computation working thread to computation ladder program to control output to proper status.


IO_SIMULATOR is just only an interface for control input and see output status via file,name input.txt and output.txt each byte indicate X000 to X007 and Y000 to Y007.

pic10.jpg

pic11.jpg
Ladder program was like the following,I don’t spend more time to do more desicriptions

pic12.jpg

Conclusion

Before complaining about that it was so ugly, I need to talk about my dream.
I want it to be a kind of application, and I planed to develop an Editor that it can edit ladder program and also can monitor computation status as soon as possible (I know in computer world what real time is , so I use the word as soon as possible),I also want to develop an GUI editor as for an Interface to control PLC, after all ,it can be applyed in many other environments as your application as possible.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jaker.Chen
Software Developer (Senior) MDS
Taiwan Taiwan
Member
8 years experience of automatic control with micro computer.
8 years experience of IT,SI,Software development(including 3 years of Project management).
I'm familiar with VB,C,C++,JAVA.
Operating System design and development is my little hobby.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generali need help with plc project i'm trying to domemberמתן פיכמן5 Jan '13 - 6:57 
Hello everyone !
i'm in my 4 year studying 1st degree of electrical Eng . i have to do a project(sort of big one) of a PLC with GUI based on c++ and an embedded c programming for the plc it self
until now evey thing is O.K
the problem is that my programming experience is very limited and i have a hard time to start
i wonder if you can help with finding a basic code for 8in 8out plc with gui   programming windows based program .
once i finish it i would gladly publish it for the sake of those who will need it as well ;
my device is going to be USB connected (not a problem my chip is designed for that purpose ) it going to be programmed by the user on a WIN XP station (old but what can i do ).
i have to create a GUI for it as well --> i am probably going to use QT creator
the GUI is going to be very simple with some simple commands (nothing fancy :while\ delay\ IfElse \for each \ OnOff ETC...)
it has to 8input and 8uotput all analogical (not digital...)
and need to store the commands and work while not connected to the computer .
I need your help please i must finish it with in 6 month and i just can get it going as well as i should an want
 
Matan
EWB(Engineer Without Borders ) Israel Branch TAU collage     
The Tanazania Project
Question|Do you have the source code for change plc ladder grahp to plc instruction text?memberjoshua013727 Mar '12 - 15:00 
If you have, can you send me one copy?
thanks very much.
GeneralMy vote of 5 [modified]memberGustavo Sanchez28 Oct '11 - 6:55 
Excellent Job, I have translated your code to Delphi 7.0, it runs in its own thread (TThread Class), if anybody want it just ask. It has more than two years running with a PCI-6515 (32 DI/DO) from National Instrument, so far so good.
 
All you need is load a text file (xxx.LAD) where the Logic is, override two procedures, ReadInputs (the X's) & UpdateOutputs (the Y's) to communicate with your DI/DO Card.
Gustavo Sanchez
Electronic & Computer Systems Engineer
Nuevo Laredo, Mexico.


modified 25 Jul '12 - 11:20.

GeneralMy vote of 5memberKOZAK26 Apr '11 - 7:59 
Good job!
GeneralMy vote of 5memberadmin84200121 Nov '10 - 5:05 
so good test proj~~
GeneralMy vote of 5memberitechnology5 Oct '10 - 17:44 
Thanks for you excellent job.
GeneralErrors in the destructor of the object cPLCCorememberRodrigueRoland15 Feb '10 - 23:54 
Hello Big Grin | :-D ,
 
I'm currently writing a PLC Simulator (in c# but I'm a C+ Guru Laugh | :laugh: ). I found your code and I detected some errors in it.
By example, in the destructor of the object cPLCCore, you must release the memory with delete[] and not delete (because you instaciate it with new[]):
cPLCCore::~cPLCCore(){
	thePLCCore->fnRESETAll();
	thePLCCore->fnWriteOutput();
	delete pInPut;
	delete pOutPut;
	delete pAUX;
	delete pSTATUS;
	delete pTimer;
	delete pCounter;
	delete pMEMBUF;
...
 
Thanks a lot to share your code and have a good day!
GeneralRe: Errors in the destructor of the object cPLCCorememberJaker.Chen26 Feb '10 - 4:37 
Many thanks Big Grin | :-D
GeneralHI, Jakermemberzhan82619 Nov '09 - 18:13 
Hi, Jaker.
I come from China.I am a Hakkanese.
I modified your codes and make your IO_SIMULATOR and PLC to become one. How do I contact you with MSN or mail?
I have developed some communication programs with PLCs and Servos etc. in Shanghai. Glad to meet you.
My E-Mail: zhan826@hotmail.com.
 
Best wish!
 
James.zhan
GeneralRe: HI, JakermemberJaker.Chen21 Nov '09 - 3:44 
Hi,James,
I'm so glag to see you doing that,any problem or suggest feel free contact me.
 
My MSN :jaker@mdsserv.mds.com.tw
E-mail : jaker.chen@gmail.com
Jaker.Chen

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 29 Sep 2008
Article Copyright 2008 by Jaker.Chen
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid