This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this questionIs it possible to read from a C开发者_运维问答OM 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 third-party software.
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.
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.
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.
com0com may satisfy your needs. It worked for me.
精彩评论