views:

145

answers:

2

Hi.

We have several legacy components that interact with COM ports, USB etc.

I would like to create a .NET program that would emulate a COM port and log the traffic, relaying it to a WCF service endpoint somewhere or directly into a database. Maybe also wrapping a real COM port kind of like the decorator pattern.

I have looked around and I have found Sourceforge project Com0Com, but it's pretty old API and in c++.

I realize that I can solve this specific problem by creating a line printer driver and never really interacting with the COM ports registered in the system. Some links to that would also be highly appreciated.

Has anybody done this? How do you create system resources in .NET?

+1  A: 

You would have to write a driver, that's how Com0Com works. If these components run in-process, you could hijack the Windows API functions, Microsoft's Detours for example.

Either solution requires C/C++, you can't write this code in a managed language. Although detouring could be technically possible, just very hard to get right. You can buy a solution though, your requirements are not uncommon, albeit it dated. Dated enough that finding one might be a bit tricky.

Hans Passant
+1  A: 

Has anybody done this?

To add to what nobugz said:

  • When I wrote a COM port emulator, I did it starting from the sample serial port driver in the DDK (serial.sys).

  • When I wrote a COM port wrapper/logger, I did it starting from the sample parallel port filter driver in the DDK (parport.sys).

ChrisW