1

Closed

Serial Bug in .net framework

description

since the .net framework have a bug make appear a messagebox with error when something happen to the comport, I sugest to use that little class
 
in serialDevice.cs
old:
    private SerialPort _Port;
new:
    private clsSerialPort _Port;
 
 
old:
SerialPort clone = new SerialPort(_Port.PortName, _Port.BaudRate, _Port.Parity, _Port.DataBits, _Port.StopBits);
 
new:
        clsSerialPort clone = new clsSerialPort();
 
        clone.PortName = _Port.PortName;
        clone.BaudRate = _Port.BaudRate;
        clone.Parity = _Port.Parity;
        clone.DataBits = _Port.DataBits;
        clone.StopBits = _Port.StopBits;
 
and the little class:
public partial class clsSerialPort : SerialPort
{
public new void Open()
{
    try
    {
        base.Open();
 
        /*
        ** because of the issue with the FTDI USB serial device,
        ** the call to the stream's finalize is suppressed
        **
        ** it will be un-suppressed in Dispose if the stream
        ** is still good
        */
        GC.SuppressFinalize(BaseStream);
    }
    catch
    {
    }
}
 
public new void Dispose()
{
    Dispose(true);
}
 
protected override void Dispose(bool disposing)
{
    if (disposing && (base.Container != null))
    {
        base.Container.Dispose();
    }
 
    try
    {
        /*
        ** because of the issue with the FTDI USB serial device,
        ** the call to the stream's finalize is suppressed
        **
        ** an attempt to un-suppress the stream's finalize is made
        ** here, but if it fails, the exception is caught and
        ** ignored
        */
        //GC.ReRegisterForFinalize(BaseStream);
    }
    catch
    {
    }
 
    base.Dispose(disposing);
}
}
Closed Dec 16, 2009 at 5:47 PM by BigstickCarpet

comments

BigstickCarpet wrote Dec 7, 2009 at 4:28 PM

Is there an MSDN article or some other link you can provide that discusses this problem with the .Net SerialPort class? I would like to know the full details of the problem before trying to implement a workaround.

JFDionne wrote Dec 7, 2009 at 8:20 PM

wrote Dec 16, 2009 at 5:47 PM

Resolved with changeset 52292.

wrote Feb 21, 2013 at 10:51 PM

wrote May 16, 2013 at 10:37 AM