Ejemplo n.º 1
0
 internal void process()
 {
     while (isConnected)
     {
         List <byte[]> msgs        = null;
         byte[]        bufferQueue = BufferQueue;
         iProcess.Parse(bufferQueue, out msgs);
         if (msgs != null && msgs.Count > 0)
         {
             foreach (byte[] item in msgs)
             {
                 try
                 {
                     Console.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "]接收数据:" + Util.ConvertbyteArrayToHexWordstring(item));
                     Console.WriteLine("");
                 }
                 catch (Exception ex)
                 {
                     Log.Error(ex.Message);
                 }
                 lock (lockinfo)
                 {
                     if (info != null && !info.isDone && iProcess.GetMessageID(item) == info.msg.MessageID)
                     {
                         info.msg.ReceivedData = item;
                         info.isDone           = true;
                         info.ev.Set();
                         continue;
                     }
                 }
                 IReaderMessage readerMessage = null;
                 try
                 {
                     readerMessage = iProcess.ParseMessageNotification(item);
                     if (this.OnMsgReceived != null && readerMessage != null)
                     {
                         this.OnMsgReceived.BeginInvoke(readerMessage, null, null);
                     }
                 }
                 catch (Exception ex2)
                 {
                     string text = "";
                     if (readerMessage != null)
                     {
                         text = readerMessage.MessageID.ToString("X4");
                     }
                     if (text.Length % 2 == 1)
                     {
                         text = "0" + text;
                     }
                     Log.Error("ICommunication:" + ex2.Message + "|MsgID:" + text);
                 }
             }
         }
         if (this.OnBuffReceived != null)
         {
             this.OnBuffReceived(bufferQueue);
         }
     }
     Log.Info("ICommunication:线程退出");
 }