Пример #1
0
        public CommBase.PortStatus IsPortAvailable(string s)
        {
            IntPtr intPtr = Win32Com.CreateFile(s, 0xc0000000, 0, IntPtr.Zero, 3, 0x40000000, IntPtr.Zero);

            if (intPtr == (IntPtr)(-1))
            {
                if ((long)Marshal.GetLastWin32Error() != (long)5)
                {
                    intPtr = Win32Com.CreateFile(this.AltName(s), 0xc0000000, 0, IntPtr.Zero, 3, 0x40000000, IntPtr.Zero);
                    if (intPtr == (IntPtr)(-1))
                    {
                        if ((long)Marshal.GetLastWin32Error() != (long)5)
                        {
                            return(CommBase.PortStatus.absent);
                        }
                        else
                        {
                            return(CommBase.PortStatus.unavailable);
                        }
                    }
                }
                else
                {
                    return(CommBase.PortStatus.unavailable);
                }
            }
            Win32Com.CloseHandle(intPtr);
            return(CommBase.PortStatus.available);
        }
Пример #2
0
 private void InternalClose()
 {
     Win32Com.CancelIo(this.hPort);
     if (this.rxThread != null)
     {
         this.rxThread.Abort();
         this.rxThread.Join(100);
         this.rxThread = null;
     }
     Win32Com.CloseHandle(this.hPort);
     if (this.ptrUWO != IntPtr.Zero)
     {
         Marshal.FreeHGlobal(this.ptrUWO);
     }
     this.stateRTS = 2;
     this.stateDTR = 2;
     this.stateBRK = 2;
     this.online   = false;
 }