Ejemplo n.º 1
0
 void comn_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     if (!start)
     {
         return;
     }
     try
     {
         if (!transmittingYmodem)
         {
             string msg = string.Empty;
             if (transmitState == YmodeSendState.WAIT_START)
             {
                 char c = (char)comn.ReadChar();
                 msg += c;
                 //接收到'C'--CRC16
                 if (c == 'C')
                 {
                     //rMainform.ShowMCUMsg("\n\r Waiting for the file to be sent ...\n\r");
                     transmittingYmodem = true;
                     YmodeStateChanged?.Invoke(12, "进入Ymode模式");
                     recData.Clear();
                 }
                 else
                 {
                     msg += comn.ReadExisting(); //读取串口缓冲区数据
                     comn.Write(new[] { (byte)0x31 }, 0, 1);
                 }
             }
             else  //文件发送完毕后的信息
             {
                 msg += comn.ReadExisting(); //读取串口缓冲区数据
             }
             YmodeResponseGot?.Invoke(msg);
         }
         else
         {
             byte[] temp  = new byte[128];
             int    count = comn.Read(temp, 0, temp.Length);
             if (count > 0)
             {
                 recData.EnqueueRange(temp, 0, count);
             }
         }
     }
     catch (Exception Err)
     {
         YmodeStateChanged?.Invoke(11, "串口通信错误");
     }
 }
Ejemplo n.º 2
0
 protected void OnBytesReceived(byte[] data)
 {
     recQueue.EnqueueRange(data, 0, data.Length);
     BytesReceived?.BeginInvoke(data, null, null);
 }