Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to simulate com port sending and receiving data using only C# programming?

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.

like image 512
abdolah Avatar asked Jan 07 '14 19:01

abdolah


People also ask

How do you emulate a serial port?

Download Virtual Serial Port Driver on your Windows machine. Install the application on your system and launch it. Choose “Pair” in the application's main window. Click the “Add a new pair” button to create a pair of virtual serial ports.

How do virtual serial ports work?

A software-based virtual serial port presents one or more virtual serial port identifiers on a PC which other applications can see and interact with as if they were real hardware ports, but the data sent and received to these virtual devices is handled by software that manipulates the transmitted and received data to ...

What is virtual serial port?

The simulation of a serial port in software in order to allow USB, Ethernet or some other input/output port to take its place. Virtual serial ports are necessary to enable an application that was written for the serial port to run on a computer that does not have that interface. See serial port.


2 Answers

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.

like image 162
J... Avatar answered Oct 14 '22 22:10

J...


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

like image 32
Xavier J Avatar answered Oct 14 '22 22:10

Xavier J