Browse Source

电子秤示数读取优化

callm 3 months ago
parent
commit
db3aeed571

+ 9 - 8
UAS_MES_YDCY/FunctionCode/Warehouse/Warehouse_FinishedProductOutSumNEW.cs

@@ -104,14 +104,15 @@ namespace UAS_MES_NEW.Warehouse
                         {
                             try
                             {
-                                int len = serialPort1.BytesToRead;
-                                Byte[] readBuffer = new Byte[len];
-                                serialPort1.Read(readBuffer, 0, len); //将数据读入缓存
-                                string weigh = Encoding.Default.GetString(readBuffer);
-                                if (weigh != "")
-                                {
-                                    weight.Text = re.Match(weigh).Value; ;
-                                }
+                                //int len = serialPort1.BytesToRead;
+                                //Byte[] readBuffer = new Byte[len];
+                                //serialPort1.Read(readBuffer, 0, len); //将数据读入缓存
+                                //string weigh = Encoding.Default.GetString(readBuffer);
+                                //if (weigh != "")
+                                //{
+                                //    weight.Text = re.Match(weigh).Value; ;
+                                //}
+                                weight.Text = re.Match(serialPort1.ReadLine()).Groups[0].Value;
                             }
                             catch (Exception)
                             {