views:

37

answers:

1

I have a WinForms .Net HMI software which talks to hardware over USB. I check for communication with the hardware at Load time and if communication is active then run it (The hardware manufacturer has provided a communication library to talk over USB).

I want to build an emulator for cases when communication with hardware is not possible (not connected) and want the software to run in simulated mode by providing dummy values for different states of hardware.

Has anyone implemented something similar? Any pointers will be helpful. Are there any design patterns to handle such implementations.

TIA

+1  A: 

Yes, I've done this. Used to write controllers for industrial equipment. Important interfaces were a PLC, a 32 axis motion controller, custom operator stations. I wrote simulators for all of them, making the simulator behave as closely as possible to the hardware I didn't have readily available in my office.

It worked out well, the simulators were done before the custom hardware was anywhere near to being ready to run. Which allowed me to write, debug and finish my code up front. Becoming instrumental in debugging the hardware. The simulators were a joy forever, they were always there when I was in a different (and more preferable) place to work on the next project. Operating a steel mill roll grinder in my bath tub.

Recommended. Nail down the protocol early.

Hans Passant
Thanks for your response. I am looking to do something similar. I have an 8 axis motion controller that I want to build an emulator for. Do you have any examples or resources which give more information about this topic.
Suneet
No such resources exist. Start with the motion controller, it will take commands to query motor status and to make them move. Write your simulator to accept the exact same commands. You'll want to actually simulate motor movement, the position should change and the "in-position" status bit should be false. You don't have to go deeper than this, like simulate acc/dec, unless that is critical in your application. You'll need a config bool that says that motion is simulated, pass the commands to the simulator instead of the controller if it is set.
Hans Passant