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; }
public PortStatus IsPortAvailable(string s) { IntPtr hObject = Win32Com.CreateFile(s, 0xc0000000, 0, IntPtr.Zero, 3, 0x40000000, IntPtr.Zero); if (hObject == ((IntPtr)(-1))) { if (Marshal.GetLastWin32Error() == 5L) { return(PortStatus.unavailable); } hObject = Win32Com.CreateFile(this.AltName(s), 0xc0000000, 0, IntPtr.Zero, 3, 0x40000000, IntPtr.Zero); if (hObject == ((IntPtr)(-1))) { if (Marshal.GetLastWin32Error() == 5L) { return(PortStatus.unavailable); } return(PortStatus.absent); } } Win32Com.CloseHandle(hObject); return(PortStatus.available); }