Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you simulate a serial device?

I am working on driver that talks to a device via a serial port in C#. I do not always have the device available to do physical testing with. Is there a way I can simulate a device on a serial port so that it responds in an ideal manner?

like image 876
PICyourBrain Avatar asked Jan 19 '10 17:01

PICyourBrain


3 Answers

Get a second COM port and use a Null-modem cable to connect the COM ports to allow two C# programs to talk to each other.

like image 121
martinr Avatar answered Oct 13 '22 13:10

martinr


I used Com0Com for a while and wrote some simulator/emulator code.

like image 30
Tim Avatar answered Oct 13 '22 13:10

Tim


What kind of driver? If it is the serial interface driver, then that gets quite tricky.

However, if your driver is an application level above the Windows device driver, then it's fairly easy to replace the i/o behavior by altering the string passed to CreateFile, or whatever layer on top of that C# uses.

== More ==

Since you use the .net library tools, this technique may be too yucky to bother. However the idea is to replace where, at some point, your code says open COM1: or whatever. Change that to be a file which has the simulated data, say `c:/com1testdata.txt'. Additional emulation code which recognizes the contents of the file for pauses and/or responses might be useful for some protocols. Data which is written to the port can be logged or ignored, depending on your requirements.

like image 1
wallyk Avatar answered Oct 13 '22 13:10

wallyk