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 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 #3
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;
     }
 }
Example #4
0
        private static string GetMessage(int errorCode)
        {
            StringBuilder stringBuilder = new StringBuilder(512);

            if (SerialPortFixer.FormatMessage(12800, new HandleRef(null, IntPtr.Zero), errorCode, 0, stringBuilder, stringBuilder.Capacity, IntPtr.Zero) == 0)
            {
                return("Unknown Error");
            }
            else
            {
                return(stringBuilder.ToString());
            }
        }
Example #5
0
		private static extern bool GetCommState(SafeFileHandle hFile, ref SerialPortFixer.Dcb lpDcb);
Example #6
0
		public static void Execute(string portName)
		{
			using (SerialPortFixer serialPortFixer = new SerialPortFixer(portName))
			{
			}
		}
Example #7
0
		private static extern bool ClearCommError(SafeFileHandle hFile, ref int lpErrors, ref SerialPortFixer.Comstat lpStat);
Example #8
0
 public static void Execute(string portName)
 {
     using (SerialPortFixer serialPortFixer = new SerialPortFixer(portName))
     {
     }
 }
Example #9
0
        private static void WinIoError()
        {
            int lastWin32Error = Marshal.GetLastWin32Error();

            throw new IOException(SerialPortFixer.GetMessage(lastWin32Error), SerialPortFixer.MakeHrFromErrorCode(lastWin32Error));
        }