views:

55

answers:

2

I am looking for a serial port component for .NET that overcomes the issues with the built-in Serial Port component related to sudden unplugging of USB-to-RS232 adapters, and suspension of the computer while the port is open. (Untrappable errors occurring after the the device is unplugged or the computer comes back after being suspended.)

I have been using Richard Grier's solution, but I still have problems when resuming from suspend.

Is there a 3rd party component that you would recommend? I have tried several, and each have their shortcomings. Ideally I'd like a drop-in replacement for the standard serial port, but I'll take whatever I can get.

(Note: I apologize if you find this post a bit vague. This question is targeted to those familiar with my problem... it is a very common issue.)

Thank you for your time.

Edit: It turns out that upgrading to .NET 4 and using the serial class works fine on XP, but does not work on Windows 7.

+1  A: 

While it would be helpful to post which solutions you've tried (no sense in someone recommending something that you've already ruled out), I can recommend the CommStudio component.

While it's a bit pricey, it's a great component and has done well with a few high-throughput (relatively speaking, of course), highly-bidirectional applications that I've worked on, and it's never had an issue with unexpected device removal.

Adam Robinson
I didn't post which solutions I've tried because I didn't want to lead anyone. Perhaps if several people had the same suggestion of something I've already tried, I'd go back and give it another shot. Thank you for your suggestion, I'm checking it out now!
Brad
+2  A: 

By popular demand, this was addressed in .NET 4.0. There are two critical changes in the internal SerialStream and EventRunner classes. The SerialStream.Dispose(bool) method avoids touching the serial port when the Windows API returns an access denied error, indicating that the port disappeared. This will prevent the Dispose() method and the finalizer from crashing.

The EventRunner.CallEvents() method avoids throwing an uncatchable exception if an attempt to clear a serial port error fails. Which would happen when the emulator is yanked out of the slot while it is in use.

Hans Passant
Cool! Looks like I will need to upgrade, but I think this will be the most straightforward solution. Thanks.
Brad
It turns out that everything works great in .NET 4 for XP, but I still get the exact same issues in Windows 7! Any thoughts?
Brad