Пример #1
0
        public bool Close()
        {
            if (blnClose == false)
            {
                blnClose = true;
                Globals.queChannelDisplay.Enqueue("G*** Closing " + stcChannel.ChannelName + " at " + Globals.TimestampEx());
                if (objTCPPort != null)
                {
                    try
                    {
                        objTCPPort.LingerState = new LingerOption(false, 0);
                        cancelTokenSource.Cancel(); // cancels any pending reads
                        objTCPPort.Close();
                        OnDisconnected(objTCPPort);
                    }
                    catch
                    {
                    }

                    objTCPPort.Dispose();
                    objTCPPort = null;
                }

                if (objProtocol is object)
                {
                    objProtocol.CloseProtocol();
                }
                Globals.queStateDisplay.Enqueue("");
                Globals.blnChannelActive = false;
                Globals.ObjSelectedModem = null;
                return(true);
            }

            return(default);
Пример #2
0
        public bool Close()
        {
            // Subroutine to close the channel and put TNC into known state...
            // Always call this method before the instance goes out of scope
            if (blnClosed)
            {
                return(true);
            }
            try
            {
                if (Globals.blnManualAbort == true)
                {
                    enmState = LinkStates.Disconnected;
                }

                blnClosed = true;
                Globals.queChannelDisplay.Enqueue("G*** Closing Packet Channel " + Globals.stcSelectedChannel.ChannelName + " at " + Globals.TimestampEx());
                if (Globals.objRadioControl != null) // Shut down the radio control and free the serial port
                {
                    Globals.objRadioControl.Close();
                    Thread.Sleep(Globals.intComCloseTime);
                    Globals.objRadioControl = null;
                }

                if (objProtocol is object)
                {
                    objProtocol.CloseProtocol();
                }
                var dttTimeout = DateTime.Now;
                dttTimeout = DateTime.Now;
                while (!(enmState == LinkStates.Disconnected | enmState == LinkStates.LinkFailed))
                {
                    if (dttTimeout.AddSeconds(10) < DateTime.Now)
                    {
                        break;
                    }
                }

                if (objCon != null)
                {
                    objCon.Close();
                }

                if (objKissDLProvider != null)
                {
                    objKissDLProvider.RemoveConnection(objCon);
                    objKissDLProvider.Close();
                }

                if (blnExitKiss & objKissChannel != null)
                {
                    objKissChannel.SetKissModeOff();
                    Thread.Sleep(200);
                }

                if (objKissChannel != null)
                {
                    objKissChannel.Close();
                }
                if (objKissComPort != null)
                {
                    objKissComPort.Close();
                }
                Globals.queStatusDisplay.Enqueue("Idle");
                Globals.queRateDisplay.Enqueue("------");
                Globals.blnChannelActive = false;
                Globals.ObjSelectedModem = null;
                return(true);
            }
            catch (Exception ex)
            {
                Log.Error("[ModemNativeKiss.Close]: " + ex.ToString());
            }

            return(default);