Bläddra i källkod

修改串口读取方式

callm 6 månader sedan
förälder
incheckning
0528a1fd5c
1 ändrade filer med 17 tillägg och 9 borttagningar
  1. 17 9
      UAS_MES_HGS/FunctionCode/Make/Make_ColorBoxWeigh_ReadLine.cs

+ 17 - 9
UAS_MES_HGS/FunctionCode/Make/Make_ColorBoxWeigh_ReadLine.cs

@@ -105,7 +105,7 @@ namespace UAS_MES_NEW.Make
         {
             try
             {
-                engine = new Engine(true);
+                //engine = new Engine(true);
                 BaseUtil.WriteLbl();
             }
             catch (Exception)
@@ -259,16 +259,24 @@ namespace UAS_MES_NEW.Make
                         {
                             try
                             {
-                                int len = serialPort1.BytesToRead;
-                                Byte[] readBuffer = new Byte[len];
-                                serialPort1.Read(readBuffer, 0, len); //将数据读入缓存
-                                string weigh = Encoding.Default.GetString(readBuffer);
-                                Remark.AppendText(weigh.Trim() + "\n");
-                                if (weigh != "")
+                                //int len = serialPort1.BytesToRead;
+                                //Byte[] readBuffer = new Byte[len];
+                                //serialPort1.Read(readBuffer, 0, len); //将数据读入缓存
+                                //string weigh = Encoding.Default.GetString(readBuffer);
+                                //Remark.AppendText(weigh.Trim() + "\n");
+                                //if (weigh != "")
+                                //{
+                                //    weight.Text = re.Match(weigh).Groups[0].Value;
+                                //}
+                                try
                                 {
-                                    weight.Text = re.Match(weigh).Groups[0].Value;
+                                    weight.Text = re.Match(serialPort1.ReadLine().Trim()).Groups[0].Value;
+                                    Remark.AppendText(weight.Text + "\n");
+                                }
+                                catch (Exception)
+                                {
+                                    GetData = false;
                                 }
-                                Remark.Clear();
                             }
                             catch (Exception)
                             {