/// <summary> /// 将回复数据放入队列 /// </summary> /// <param name="CS">COM服务</param> /// <param name="STCD">测站编号</param> /// <param name="bt">数据</param> public static void WriteCsdQ(ComServer CS, string STCD, byte[] bt) { ConcurrentQueue <ComSendData> Qcsd = CS.CQ.Qcsd; ComSendData csd = new ComSendData(); csd.Data = bt; csd.STCD = STCD; lock (Qcsd) { Qcsd.Enqueue(csd); } }
/// <summary> /// 移除召测命令集中的命令 /// </summary> /// <param name="GS">gsm服务</param> /// <param name="STCD">站号</param> /// <param name="CommandCode">命令码</param> public static void RemoveCsdQ(ComServer CS, string STCD, string CommandCode) { ConcurrentQueue <ComSendData> Qcsd = CS.CQ.Qcsd; lock (Qcsd) { for (int i = 0; i < CS.CQ.Qcsd.Count; i++) { ComSendData csd = null; if (Qcsd.TryDequeue(out csd)) { if (csd.STCD != STCD || csd.COMMANDCODE != CommandCode) { Qcsd.Enqueue(csd); } } } } }
/// <summary> /// 将回复数据放入队列 /// </summary> /// <param name="CS">COM服务</param> /// <param name="STCD">测站编号</param> /// <param name="bt">数据</param> public static void WriteCsdQ(ComServer CS, string STCD, byte[] bt, string CommandCode) { ConcurrentQueue <ComSendData> Qcsd = CS.CQ.Qcsd; var qcsd = from c in Qcsd where c.STCD == STCD && c.COMMANDCODE == CommandCode select c; List <ComSendData> QCSD = qcsd.ToList <ComSendData>(); lock (Qcsd) if (QCSD.Count() > 0) { QCSD.First().Data = bt; } else { ComSendData csd = new ComSendData(); csd.Data = bt; csd.STCD = STCD; csd.COMMANDCODE = CommandCode; Qcsd.Enqueue(csd); } }
/// <summary> /// 从回复队列中回复数据 /// </summary> /// <param name="CS">COM服务</param> public static void SendData(ComServer CS) { string ServiceId = CS.ServiceID; ConcurrentQueue <ComSendData> Qcsd = CS.CQ.Qcsd; List <ComSatellite> Cs = CS.Cs; SerialPort sp = CS.sp; lock (Qcsd) { int k = Qcsd.Count; while (Qcsd.Count > 0) { ComSendData cs = null; Qcsd.TryDequeue(out cs); if (cs != null) { lock (Cs) { var temp = from c in Cs where cs.STCD == c.STCD select c; if (temp.Count() > 0) { sp.WriteLine(Encoding.ASCII.GetString(cs.Data)); ServiceBussiness.WriteQUIM("COM", ServiceId, temp.First().STCD, "回复数据", cs.Data, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } else { Qcsd.Enqueue(cs); } } k--; if (k <= 0) { return; } } } } }