Source Code Documentation.All of this page will move to the SF Wiki, since wiki is just tider and collaborative. (If you have not realized by now, I'm not in this for myself, so all this is just me trying to help.) What? OK,
so this program was never designed for re-use of any kind, so cutting
any of this source and re-using it is going to be difficult. Why? Well
50% of this code was crafted by my own hand, the other half is code I
have picked up from contributions, and sites like codeguru and
codeproject, mainly to provide graphical aspects of the application I
would not have written on my own. It has grown organically, is probably
due a re-write and lacks any modularization, and is not very OO at all.
Enough groveling, because this simulator works very well, and I get bug
reports from time to time and normally fix them in around a fortnight
as time allows. It's always easier to just call a bit of code, than to wrap it in an interface first; which is how I started out, since this was just going to be a very tiny simulator, with only modbus support, on TCP/IP only... I then added serial/RTU, then added Allen-Bradley, added a comms debugger screen, added Allen-Bradley Joy simulation, added some graphical effects to make the UI more intuitive, and well I run out of breath there. Compiling it
Good, now you are done, you might want to first hack the key-check code, and fiddle about in the easter-egg. Breakdown (detail) The goal was to create a modbus simulator, so the core logic revolves around spawning a comms thread (since the GUI thread needs to still respond to the user), which interfaces to the comms APIs and updates a block of RAM which acts like PLC memory. Serial protocols get 1 worker thread, the TCP/IP sockets are managed on 1 thread round-robin style. When the worker has to tell the GUI that a register has changed, the GUI receives a paint message with the register if it is currently visible. Simple, the normal Windows controls work as-is, and the worker thread posts messages to it. Below are links to the classes.
Credit Most
of the imported code that is used as a module will have some link or
name of author. Primarily the necessity came in the workplace, I was
facing a few bugs, and reproducing them with only one or 2 controllers
was difficult. Sometimes my real controller was too well behaved, and
would not create the problem situations I was getting from customers.
So I can simulate comms glitches, as well as specific 'bad' behavior
which you can get from some cloned modbus implementations. |

