views:

154

answers:

5

Is it possible to read from a COM port already in use on Windows XP? I would like to see the communication between some software and a device plugged into a serial device. I wrote a small program using C# to monitor the COM, but once it's in use by the other device it will not let you open it again. How can one monitor a COM port already in use? I'm open to 3rd party software. Thanks

+4  A: 

PortMon is the classic COM port monitor. It has to be running before the program opens the COM port, but the monitoring part can be enabled/disabled.

Stephen Cleary
Good remider to have PortMon running before the other program opens the COM port.
Bratch
+2  A: 

You can use Portmon for Windows to monitor the activity. The other way I do this is with some hardware and a laptop. I'm not sure how you can monitor it yourself with a C# app. Once you are connected to it and attempt to connect again it will already be in use.

Also check this out, it's somewhat related, with a note on how PortMon works:
Serial Port Redirection or Splitting - Stack Overflow

If you have or can get more than one COM port, you could use a splitter and do the monitoring from the other port.

Bratch
A: 

I have some vague recollection of using this COMMSPY article to do something like that many years ago, but I might be mistaken.

http://www.codeguru.com/cpp/i-n/network/article.php/c2461

ho1
+2  A: 

Yes, this is technically possible. You'll need a filter driver, a device driver type of a component that injects itself ahead of the native serial port driver. It gets a crack at the driver IRPs before sending them on to the regular driver.

This is the technique used by SysInternals' PortMon utility. However, you cannot write such a driver in C# code, the CLR cannot be loaded into ring 0. At least not until the super-secret Midori project sees the light of day.

COM filter drivers are pretty common, check out this one for example. You have to do some googling to find one that has a .NET wrapper though.

Hans Passant
+1  A: 

com0com may satisfy your needs. It worked for me.

kenny
I was going to suggest that as well
Tim