Donations :

Download sites

My Projects

Design and Code

Source Code Documentation.

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 user contributions. Some open-source code comes from codeguru and codeproject, mainly to provide graphical aspects of the application I would not have written on my own. It has grown organically, and probably due a re-write where it lacks any modularization, and is not very OO at all. Enough groveling, because this simulator works very well, while I get bug reports from time to time I 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, along comes TCP/IP. 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. You get the idea, it's organic.

Compiling it

  1. Either get the source from SVN svn co https://modrssim.svn.sourceforge.net/svnroot/modrssim modrssim 
or
  1. Download the simulator source, and the utility library (separate file called mylib.zip)
  2. Unzip them, drop the mylib source into a folder either under or near the same level as the simulator project.
next:
  1. Build the library, make sure to note where the target library goes, and that the debug and release compile to separate libs, (append a 'D' to the debug library so you can tell it apart latter)
  2. You did build the lib for debug and release? OK now open the main project, add the mylib library as a sub-project in your workspace (basically depending on your IDE, you next want to make mylib a dependency of mod_rssim).
  3. Go to project setting, go to link, and fix the path, so the linker will be  able to find the libraries from step 3, remember the debug library must be in the debug build. If you mix the debug/release up, the app will crash quite early on.
  4. While you in project settings, add the path to the libray header-file mylib.h to the includes path. (I discourage the copying of the h file into the local folder, it may bite you latter)
  5. Compile debug and release. Run them BOTH to verify!

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.

Doxygen UML diagrams.


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.