Example #1
0
        private void GetCommStateNative(ref SerialPortFixer.Dcb lpDcb)
        {
            int num = 0;

            SerialPortFixer.Comstat comstat = new SerialPortFixer.Comstat();
            int num1 = 0;

            while (num1 < 10)
            {
                if (!SerialPortFixer.ClearCommError(this.m_Handle, ref num, ref comstat))
                {
                    SerialPortFixer.WinIoError();
                }
                if (!SerialPortFixer.GetCommState(this.m_Handle, ref lpDcb))
                {
                    if (num1 == 9)
                    {
                        SerialPortFixer.WinIoError();
                    }
                    num1++;
                }
                else
                {
                    return;
                }
            }
        }
Example #2
0
 private SerialPortFixer(string portName)
 {
     if (portName == null || !portName.StartsWith("COM", StringComparison.OrdinalIgnoreCase))
     {
         throw new ArgumentException("Invalid Serial Port", "portName");
     }
     else
     {
         SafeFileHandle safeFileHandle = SerialPortFixer.CreateFile(string.Concat("\\\\.\\", portName), -1073741824, 0, IntPtr.Zero, 3, 1073741824, IntPtr.Zero);
         if (safeFileHandle.IsInvalid)
         {
             SerialPortFixer.WinIoError();
         }
         try
         {
             int fileType = SerialPortFixer.GetFileType(safeFileHandle);
             if (fileType == 2 || fileType == 0)
             {
                 this.m_Handle = safeFileHandle;
                 this.InitializeDcb();
             }
             else
             {
                 throw new ArgumentException("Invalid Serial Port", "portName");
             }
         }
         catch
         {
             safeFileHandle.Close();
             this.m_Handle = null;
             throw;
         }
         return;
     }
 }