Пример #1
0
        /// <summary>
        /// Performs actions after polling the specified device.
        /// </summary>
        public override void AfterSession(DeviceLogic deviceLogic)
        {
            if (currentConn != null)
            {
                // disconnect according to the options, or in case of error
                if ((!options.StayConnected || deviceLogic.DeviceStatus == DeviceStatus.Error) &&
                    currentConn.Connected)
                {
                    Log.WriteLine();
                    Log.WriteAction(Locale.IsRussian ?
                                    "Отключение от {0}" :
                                    "Disconnect from {0}", currentConn.RemoteAddress);
                    currentConn.Disconnect();
                }

                if (Behavior == ChannelBehavior.Slave)
                {
                    Monitor.Exit(currentConn.SyncRoot);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Stops the communication channel.
        /// </summary>
        public override void Stop()
        {
            if (thread != null)
            {
                terminated = true;
                thread.Join();
                thread = null;
            }

            if (options.ConnectionMode == ConnectionMode.Individual)
            {
                if (indivConnList != null)
                {
                    indivConnList.ForEach(conn => conn.Close());
                    indivConnList.Clear();
                }
            }
            else
            {
                SetDeviceConnection(null);
                sharedConn?.Disconnect();
            }
        }