Pārlūkot izejas kodu

添加串口关闭功能

章政 5 gadi atpakaļ
vecāks
revīzija
81a2b7b474

+ 29 - 14
UAS-出货标签管理(泽天)/UAS_出货标签管理.Designer.cs

@@ -167,6 +167,7 @@
             this.MidLabelAutoPrint = new System.Windows.Forms.CheckBox();
             this.MidLabelCombox = new System.Windows.Forms.ComboBox();
             this.OutBoxLabel = new UAS_LabelMachine.CustomControl.GroupBoxWithBorder.GroupBoxWithBorder();
+            this.BoxCount = new System.Windows.Forms.Label();
             this.DiffLotNo = new System.Windows.Forms.CheckBox();
             this.DiffDC = new System.Windows.Forms.CheckBox();
             this.OnlyOneRow = new System.Windows.Forms.CheckBox();
@@ -180,7 +181,7 @@
             this.OutboxCapacity = new System.Windows.Forms.NumericUpDown();
             this.OutBoxLabelPrint = new System.Windows.Forms.Button();
             this.OutBoxCombox = new System.Windows.Forms.ComboBox();
-            this.BoxCount = new System.Windows.Forms.Label();
+            this.CloseSerialPort = new System.Windows.Forms.Button();
             ((System.ComponentModel.ISupportInitialize)(this.MidSource)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
             this.groupBoxWithBorder2.SuspendLayout();
@@ -758,14 +759,15 @@
             // 
             // groupBoxWithBorder2
             // 
+            this.groupBoxWithBorder2.Controls.Add(this.CloseSerialPort);
             this.groupBoxWithBorder2.Controls.Add(this.ConnectCom);
             this.groupBoxWithBorder2.Controls.Add(this.ButtonWeigh);
             this.groupBoxWithBorder2.Controls.Add(this.Weight);
-            this.groupBoxWithBorder2.Location = new System.Drawing.Point(1135, 222);
+            this.groupBoxWithBorder2.Location = new System.Drawing.Point(1124, 222);
             this.groupBoxWithBorder2.Margin = new System.Windows.Forms.Padding(2);
             this.groupBoxWithBorder2.Name = "groupBoxWithBorder2";
             this.groupBoxWithBorder2.Padding = new System.Windows.Forms.Padding(2);
-            this.groupBoxWithBorder2.Size = new System.Drawing.Size(123, 155);
+            this.groupBoxWithBorder2.Size = new System.Drawing.Size(134, 155);
             this.groupBoxWithBorder2.TabIndex = 113;
             this.groupBoxWithBorder2.TabStop = false;
             this.groupBoxWithBorder2.Text = "称重";
@@ -773,7 +775,7 @@
             // ConnectCom
             // 
             this.ConnectCom.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.ConnectCom.Location = new System.Drawing.Point(27, 93);
+            this.ConnectCom.Location = new System.Drawing.Point(7, 93);
             this.ConnectCom.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.ConnectCom.Name = "ConnectCom";
             this.ConnectCom.Size = new System.Drawing.Size(80, 26);
@@ -785,10 +787,10 @@
             // ButtonWeigh
             // 
             this.ButtonWeigh.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.ButtonWeigh.Location = new System.Drawing.Point(27, 123);
+            this.ButtonWeigh.Location = new System.Drawing.Point(7, 123);
             this.ButtonWeigh.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.ButtonWeigh.Name = "ButtonWeigh";
-            this.ButtonWeigh.Size = new System.Drawing.Size(81, 26);
+            this.ButtonWeigh.Size = new System.Drawing.Size(66, 26);
             this.ButtonWeigh.TabIndex = 97;
             this.ButtonWeigh.Text = "称量箱重";
             this.ButtonWeigh.UseVisualStyleBackColor = true;
@@ -852,7 +854,7 @@
             this.GridPrcode.MultiSelect = false;
             this.GridPrcode.Name = "GridPrcode";
             this.GridPrcode.RowTemplate.Height = 23;
-            this.GridPrcode.Size = new System.Drawing.Size(1134, 158);
+            this.GridPrcode.Size = new System.Drawing.Size(1119, 158);
             this.GridPrcode.TabIndex = 88;
             this.GridPrcode.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.GridPrcode_CellClick);
             this.GridPrcode.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.GridPrcode_CellEndEdit);
@@ -1609,6 +1611,15 @@
             this.OutBoxLabel.TabStop = false;
             this.OutBoxLabel.Text = "外箱标签";
             // 
+            // BoxCount
+            // 
+            this.BoxCount.AutoSize = true;
+            this.BoxCount.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.BoxCount.Location = new System.Drawing.Point(8, 183);
+            this.BoxCount.Name = "BoxCount";
+            this.BoxCount.Size = new System.Drawing.Size(0, 17);
+            this.BoxCount.TabIndex = 97;
+            // 
             // DiffLotNo
             // 
             this.DiffLotNo.AutoSize = true;
@@ -1763,14 +1774,17 @@
             this.OutBoxCombox.TabIndex = 78;
             this.OutBoxCombox.SelectedIndexChanged += new System.EventHandler(this.OutBoxCombox_SelectedIndexChanged);
             // 
-            // BoxCount
+            // CloseSerialPort
             // 
-            this.BoxCount.AutoSize = true;
-            this.BoxCount.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.BoxCount.Location = new System.Drawing.Point(8, 183);
-            this.BoxCount.Name = "BoxCount";
-            this.BoxCount.Size = new System.Drawing.Size(0, 17);
-            this.BoxCount.TabIndex = 97;
+            this.CloseSerialPort.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.CloseSerialPort.Location = new System.Drawing.Point(74, 123);
+            this.CloseSerialPort.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.CloseSerialPort.Name = "CloseSerialPort";
+            this.CloseSerialPort.Size = new System.Drawing.Size(55, 26);
+            this.CloseSerialPort.TabIndex = 115;
+            this.CloseSerialPort.Text = "关闭";
+            this.CloseSerialPort.UseVisualStyleBackColor = true;
+            this.CloseSerialPort.Click += new System.EventHandler(this.CloseSerialPort_Click);
             // 
             // UAS_出货标签打印
             // 
@@ -2001,5 +2015,6 @@
         private System.Windows.Forms.DataGridViewTextBoxColumn pjd_zxbzs_user;
         private System.Windows.Forms.DataGridViewTextBoxColumn pr_spec1;
         private System.Windows.Forms.Label BoxCount;
+        private System.Windows.Forms.Button CloseSerialPort;
     }
 }

+ 13 - 5
UAS-出货标签管理(泽天)/UAS_出货标签管理.cs

@@ -2206,18 +2206,26 @@ namespace UAS_LabelMachine
                 int len = Com.BytesToRead;
                 byte[] readBuffer = new byte[len];
                 Com.Read(readBuffer, 0, len); //将数据读入缓存
-                Weight.Text = reg.Match(Encoding.ASCII.GetString(readBuffer, 0, len)).Value;
-                //读不到数据的时间删掉
-                if (Weight.Text == "")
+                string value = reg.Match(Encoding.ASCII.GetString(readBuffer, 0, len)).Value;
+                if (value != "")
                 {
-                    Com.DataReceived -= Com_DataReceived;
-                    return;
+                    Weight.Text = value;
                 }
+                //读不到数据的时间删掉
             }
             catch (Exception)
             {
                 return;
             }
         }
+
+        private void CloseSerialPort_Click(object sender, EventArgs e)
+        {
+            if (Com.IsOpen)
+            {
+                Com.Close();
+                Com.DataReceived -= Com_DataReceived;
+            }
+        }
     }
 }