Esempio n. 1
0
 //接收数据
 private void Com_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     if (PortConfig.serialPort1.IsOpen)
     {
         string backStr = PortConfig.serialPort1.ReadExisting();
         if (backStr.Length < 30)
         {
             if (backStr.Trim() == "@")
             {
                 Dispatcher.Invoke(new Action(() =>
                 {
                     CheckBtn.Background = System.Windows.Media.Brushes.Orange;
                     CheckBtn.Content    = "正在设置数据";
                 }));
             }
             else if (backStr.Trim() == "S6")
             {
                 Dispatcher.Invoke(new Action(() =>
                 {
                     CheckBtn.Content = "检测中......";
                 }));
             }
         }
         if (backStr.Length > 30)
         {
             if (backStr.Substring(0, 1) == "{")
             {
                 StudentCheckData data = new StudentCheckData
                 {
                     activityId  = activityId,
                     studentId   = stnId,
                     checkDate   = DateTime.Now.ToString(),
                     jsonContent = backStr
                 };
                 bool isSave = dbUtill.SavaStudentCheckData(data);
                 if (isSave)
                 {
                     MessageBox.Show("检测完毕,请离开体测仪", "提示");
                 }
                 else
                 {
                     MessageBox.Show("保存失败,请离开体测仪", "提示");
                 }
                 Dispatcher.Invoke(new Action(() =>
                 {
                     CheckBtn.Content = "开始检测";
                 }));
             }
         }
     }
     else
     {
         MessageBox.Show("串口未打开", "提示");
     }
 }