9

I have a device which sends data by com port on my computer.

I know how to simulate it, but the controller must be plugged in to simulate sending data (using Proteus)

Is it possible to simulate the com port sending data without having any external device plugged in?

For example: I want to write a C# program which opens the com port and waits for data, and another c# program which writes data on the same port.

Can
  • 8,502
  • 48
  • 57
abdolah
  • 546
  • 1
  • 4
  • 13
  • Why don't you just logically simulate the device itself in your code? You just need a SimRead and SimWrite method. – Hans Passant Jan 07 '14 at 19:32
  • 1
    @HansPassant Usually working with hardware devices you are writing event-driven code - SimWrite would work fine but usually you would be reacting to a `DataReceived` event rather than reading actively. That's not to say that you couldn't implement something logically equivalent, but null-modem emulation provides the cleanest solution, I find. This way you can write a completely separate test application that emulates the connected device behaviour and the control application does not need to be modifed whatsoever for testing. – J... Jan 07 '14 at 20:18
  • Does this answer your question? [Faking an RS232 Serial Port](https://stackoverflow.com/questions/1605721/faking-an-rs232-serial-port) – Xavier J Aug 24 '22 at 17:08

2 Answers2

14

The best way to do this is to use a software COM port emulator. I use com0com :

Null-modem emulator

This provides virtual NM COM port pairs on the system (ie: what is output to one is input to the other and vice-versa). The devices show up in Device Manager just like a real COM port so you interact with them in C# as though they were real hardware devices.

J...
  • 30,968
  • 6
  • 66
  • 143
5

For simplicity's sake, get yourself a com port or null modem emulator. You'll get very far off track, and maybe waste a lot of time, trying to do this yourself.

See this post, too: Faking an RS232 Serial Port

Community
  • 1
  • 1
Xavier J
  • 4,326
  • 1
  • 14
  • 25