Пример #1
0
        /// <summary>
        /// 从回复队列中回复数据(未使用)
        /// </summary>
        /// <param name="TS">tcp服务</param>
        public static void SendData(TcpServer TS)
        {
            string ServiceId = TS.ServiceID;
            ConcurrentQueue <TcpSendData> Qtsd = TS.TQ.Qtsd;
            List <TcpSocket> Ts = TS.Ts;

            int k = Qtsd.Count;

            lock (Qtsd)
                while (Qtsd.Count > 0)
                {
                    TcpSendData ts = null;
                    Qtsd.TryDequeue(out ts);
                    if (ts != null)
                    {
                        var temp = from t in Ts where ts.STCD == t.STCD select t;
                        if (temp.Count() > 0)
                        {
                            temp.First().TCPSOCKET.Send(ts.Data);
                        }
                        else
                        {
                            Qtsd.Enqueue(ts);
                        }

                        k--;
                        if (k <= 0)
                        {
                            return;
                        }
                    }
                }
        }
Пример #2
0
        /// <summary>
        /// 将回复数据放入队列
        /// </summary>
        /// <param name="TS">tcp服务</param>
        /// <param name="STCD">测站编号</param>
        /// <param name="bt">数据</param>
        /// <param name="CommandcCode">命令码</param>
        public static void WriteTsdQ(TcpServer TS, string STCD, byte[] bt, string CommandCode)
        {
            ConcurrentQueue <TcpSendData> Qtsd = TS.TQ.Qtsd;

            TcpSendData tsd = new TcpSendData();

            tsd.Data        = bt;
            tsd.STCD        = STCD;
            tsd.COMMANDCODE = CommandCode;
            tsd.STATE       = 0;
            lock (Qtsd)
            {
                Qtsd.Enqueue(tsd);
            }
        }
Пример #3
0
        /// <summary>
        /// 移除召测命令集中的命令
        /// </summary>
        /// <param name="TS">tcp服务</param>
        /// <param name="STCD">站号</param>
        /// <param name="CommandCode">命令号</param>
        public static void RemoveTsdQ(TcpServer TS, string STCD, string CommandCode)
        {
            ConcurrentQueue <TcpSendData> Qtsd = TS.TQ.Qtsd;

            lock (Qtsd)
            {
                TcpSendData tsd = null;
                if (Qtsd.TryDequeue(out tsd))
                {
                    if (tsd.STCD != STCD || tsd.COMMANDCODE != CommandCode)
                    {
                        Qtsd.Enqueue(tsd);
                    }
                }
            }
        }
Пример #4
0
 /// <summary>
 /// 移除召测命令集中的命令
 /// </summary>
 /// <param name="TS">tcp服务</param>
 /// <param name="STCD">站号</param>
 /// <param name="CommandCode">命令号</param>
 public static void RemoveTsdQ(TcpServer TS, string STCD, string CommandCode)
 {
     lock (TS.TQ.Qtsd)
     {
         for (int i = 0; i < TS.TQ.Qtsd.Count; i++)
         {
             TcpSendData tsd = null;
             if (TS.TQ.Qtsd.TryDequeue(out tsd))
             {
                 if (tsd.STCD != STCD || tsd.COMMANDCODE != CommandCode)
                 {
                     TS.TQ.Qtsd.Enqueue(tsd);
                 }
             }
         }
     }
 }
Пример #5
0
        /// <summary>
        /// 将回复数据放入队列(每个测站同一命令只允许有1条,默认为最后1条)
        /// </summary>
        /// <param name="TS">tcp服务</param>
        /// <param name="STCD">测站编号</param>
        /// <param name="bt">数据</param>
        /// <param name="CommandcCode">命令码</param>
        public static void WriteTsdQ(TcpServer TS, string STCD, byte[] bt, string CommandCode)
        {
            ConcurrentQueue <TcpSendData> Qtsd = TS.TQ.Qtsd;
            var qtsd = from t in Qtsd where t.STCD == STCD && t.COMMANDCODE == CommandCode select t;

            lock (Qtsd)
                if (qtsd.Count() > 0)
                {
                    qtsd.First().Data  = bt;
                    qtsd.First().STATE = 0;
                }
                else
                {
                    TcpSendData tsd = new TcpSendData();
                    tsd.Data        = bt;
                    tsd.STCD        = STCD;
                    tsd.COMMANDCODE = CommandCode;
                    tsd.STATE       = 0;
                    Qtsd.Enqueue(tsd);
                }
        }