فهرست منبع

计数器模式不发送数据

callm 1 ماه پیش
والد
کامیت
74921d0139
2فایلهای تغییر یافته به همراه99 افزوده شده و 52 حذف شده
  1. 9 14
      FileWatcher/AutoSMTRXY.Designer.cs
  2. 90 38
      FileWatcher/AutoSMTRXY.cs

+ 9 - 14
FileWatcher/AutoSMTRXY.Designer.cs

@@ -205,6 +205,7 @@
             this.SN.TabIndex = 37;
             this.SN.Text = "扫描SN";
             this.SN.UseVisualStyleBackColor = true;
+            this.SN.CheckedChanged += new System.EventHandler(this.SN_CheckedChanged);
             // 
             // Counter
             // 
@@ -217,6 +218,7 @@
             this.Counter.TabStop = true;
             this.Counter.Text = "计数器";
             this.Counter.UseVisualStyleBackColor = true;
+            this.Counter.CheckedChanged += new System.EventHandler(this.Counter_CheckedChanged);
             // 
             // StopWatch
             // 
@@ -245,13 +247,13 @@
             // 
             // BaudRate
             // 
+            this.BaudRate.Enabled = false;
             this.BaudRate.Location = new System.Drawing.Point(1020, 229);
             this.BaudRate.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.BaudRate.Name = "BaudRate";
             this.BaudRate.Size = new System.Drawing.Size(146, 35);
             this.BaudRate.TabIndex = 43;
             this.BaudRate.Text = "9600";
-            this.BaudRate.Visible = false;
             // 
             // BaudRate_label
             // 
@@ -263,7 +265,6 @@
             this.BaudRate_label.Size = new System.Drawing.Size(104, 38);
             this.BaudRate_label.TabIndex = 42;
             this.BaudRate_label.Text = "波特率";
-            this.BaudRate_label.Visible = false;
             // 
             // ComPort_label
             // 
@@ -275,7 +276,6 @@
             this.ComPort_label.Size = new System.Drawing.Size(75, 38);
             this.ComPort_label.TabIndex = 41;
             this.ComPort_label.Text = "串口";
-            this.ComPort_label.Visible = false;
             // 
             // Timer
             // 
@@ -307,12 +307,12 @@
             // 
             // Read
             // 
+            this.Read.Enabled = false;
             this.Read.Location = new System.Drawing.Point(1018, 286);
             this.Read.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.Read.Name = "Read";
             this.Read.Size = new System.Drawing.Size(146, 35);
             this.Read.TabIndex = 47;
-            this.Read.Visible = false;
             // 
             // Read_label
             // 
@@ -324,16 +324,15 @@
             this.Read_label.Size = new System.Drawing.Size(75, 38);
             this.Read_label.TabIndex = 46;
             this.Read_label.Text = "读取";
-            this.Read_label.Visible = false;
             // 
             // Write
             // 
+            this.Write.Enabled = false;
             this.Write.Location = new System.Drawing.Point(1018, 338);
             this.Write.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.Write.Name = "Write";
             this.Write.Size = new System.Drawing.Size(146, 35);
             this.Write.TabIndex = 49;
-            this.Write.Visible = false;
             // 
             // Write_label
             // 
@@ -345,16 +344,15 @@
             this.Write_label.Size = new System.Drawing.Size(75, 38);
             this.Write_label.TabIndex = 48;
             this.Write_label.Text = "回写";
-            this.Write_label.Visible = false;
             // 
             // ToZero
             // 
+            this.ToZero.Enabled = false;
             this.ToZero.Location = new System.Drawing.Point(1018, 394);
             this.ToZero.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.ToZero.Name = "ToZero";
             this.ToZero.Size = new System.Drawing.Size(146, 35);
             this.ToZero.TabIndex = 51;
-            this.ToZero.Visible = false;
             // 
             // ToZero_label
             // 
@@ -366,7 +364,6 @@
             this.ToZero_label.Size = new System.Drawing.Size(75, 38);
             this.ToZero_label.TabIndex = 50;
             this.ToZero_label.Text = "清零";
-            this.ToZero_label.Visible = false;
             // 
             // CleanData
             // 
@@ -403,11 +400,11 @@
             this.CountType_label.Size = new System.Drawing.Size(133, 38);
             this.CountType_label.TabIndex = 55;
             this.CountType_label.Text = "计数方式";
-            this.CountType_label.Visible = false;
             // 
             // CountType
             // 
             this.CountType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.CountType.Enabled = false;
             this.CountType.FormattingEnabled = true;
             this.CountType.Items.AddRange(new object[] {
             "PLC",
@@ -416,16 +413,15 @@
             this.CountType.Name = "CountType";
             this.CountType.Size = new System.Drawing.Size(137, 32);
             this.CountType.TabIndex = 54;
-            this.CountType.Visible = false;
             // 
             // UseScan
             // 
+            this.UseScan.Enabled = false;
             this.UseScan.Location = new System.Drawing.Point(1018, 445);
             this.UseScan.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.UseScan.Name = "UseScan";
             this.UseScan.Size = new System.Drawing.Size(146, 35);
             this.UseScan.TabIndex = 57;
-            this.UseScan.Visible = false;
             // 
             // UseScan_label
             // 
@@ -437,7 +433,6 @@
             this.UseScan_label.Size = new System.Drawing.Size(133, 38);
             this.UseScan_label.TabIndex = 56;
             this.UseScan_label.Text = "启用扫描";
-            this.UseScan_label.Visible = false;
             // 
             // Password
             // 
@@ -461,12 +456,12 @@
             // 
             // ComPort
             // 
+            this.ComPort.Enabled = false;
             this.ComPort.Location = new System.Drawing.Point(1018, 181);
             this.ComPort.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
             this.ComPort.Name = "ComPort";
             this.ComPort.Size = new System.Drawing.Size(148, 40);
             this.ComPort.TabIndex = 40;
-            this.ComPort.Visible = false;
             // 
             // ms_sncode
             // 

+ 90 - 38
FileWatcher/AutoSMTRXY.cs

@@ -95,10 +95,6 @@ namespace FileWatcher
             }
             catch (Exception ex) { OperateResult.AppendText(ex.Message); }
 
-            ComPort.Visible = false; Read.Visible = false; Write.Visible = false;
-            BaudRate.Visible = false; ToZero.Visible = false; UseScan.Visible = false;
-            CountType.Visible = false;
-
             RemindTimer.Start();
             this.WindowState = FormWindowState.Normal;
             this.Size = new System.Drawing.Size(900, 400); // 替换为你需要的尺寸
@@ -355,14 +351,29 @@ namespace FileWatcher
                     pipe.SleepTime = 20;
                     pipe.ReceiveTimeOut = 5000;
                     plc.CommunicationPipe = pipe;
-                    OperateResult write = plc.Write(UseScan.Text, 1);
-                    if (write.IsSuccess)
+                    if (Counter.Checked)
                     {
-                        OperateResult.AppendText("通过,发送指令" + UseScan.Text + "写入2\n");
+                        OperateResult write = plc.Write(UseScan.Text, 0);
+                        if (write.IsSuccess)
+                        {
+                            OperateResult.AppendText("通过,发送指令" + UseScan.Text + "写入0\n");
+                        }
+                        else
+                        {
+                            OperateResult.AppendText("写入失败\n");
+                        }
                     }
                     else
                     {
-                        OperateResult.AppendText("写入失败\n");
+                        OperateResult write = plc.Write(UseScan.Text, 2);
+                        if (write.IsSuccess)
+                        {
+                            OperateResult.AppendText("通过,发送指令" + UseScan.Text + "写入2\n");
+                        }
+                        else
+                        {
+                            OperateResult.AppendText("写入失败\n");
+                        }
                     }
                 }
                 else
@@ -409,21 +420,21 @@ namespace FileWatcher
                         {
                             lastqty = 0;
                         }
-                        else
-                        {
-                            if (qty - lastqty > 0)
-                            {
-                                OperateResult write = plc.Write(Write.Text, 1);
-                                if (write.IsSuccess)
-                                {
-                                    OperateResult.AppendText("通过,发送指令" + Write.Text + "写入1\n");
-                                }
-                                else
-                                {
-                                    OperateResult.AppendText("写入失败\n");
-                                }
-                            }
-                        }
+                        //else
+                        //{
+                        //    if (qty - lastqty > 0)
+                        //    {
+                        //        OperateResult write = plc.Write(Write.Text, 1);
+                        //        if (write.IsSuccess)
+                        //        {
+                        //            OperateResult.AppendText("通过,发送指令" + Write.Text + "写入1\n");
+                        //        }
+                        //        else
+                        //        {
+                        //            OperateResult.AppendText("写入失败\n");
+                        //        }
+                        //    }
+                        //}
                         NowQTY.Text = qty.ToString();
                         if (Type.Text == "投入")
                         {
@@ -497,27 +508,20 @@ namespace FileWatcher
 
         private void Setting_Click(object sender, EventArgs e)
         {
-            if (ComPort.Visible == true)
+            if (Read.Enabled == true)
             {
-                ComPort.Visible = false; Read.Visible = false; Write.Visible = false;
-                BaudRate.Visible = false; ToZero.Visible = false; UseScan.Visible = false;
-                CountType.Visible = false;
-
-                ComPort_label.Visible = false; Read_label.Visible = false; Write_label.Visible = false;
-                BaudRate_label.Visible = false; ToZero_label.Visible = false; UseScan_label.Visible = false;
-                CountType_label.Visible = false;
+                ComPort.Enabled = false; Read.Enabled = false; Write.Enabled = false;
+                BaudRate.Enabled = false; ToZero.Enabled = false; UseScan.Enabled = false;
+                CountType.Enabled = false;
             }
             else
             {
                 if (Password.Text == "1234")
                 {
-                    ComPort.Visible = true; Read.Visible = true; Write.Visible = true;
-                    BaudRate.Visible = true; ToZero.Visible = true; UseScan.Visible = true;
-                    CountType.Visible = true;
-
-                    ComPort_label.Visible = true; Read_label.Visible = true; Write_label.Visible = true;
-                    BaudRate_label.Visible = true; ToZero_label.Visible = true; UseScan_label.Visible = true;
-                    CountType_label.Visible = true;
+                    ComPort.Enabled = true; Read.Enabled = true; Write.Enabled = true;
+                    BaudRate.Visible = true; ToZero.Enabled = true; UseScan.Enabled = true;
+                    CountType.Enabled = true;
+                    Password.Text = "";
                 }
                 else
                 {
@@ -525,5 +529,53 @@ namespace FileWatcher
                 }
             }
         }
+
+        private void Counter_CheckedChanged(object sender, EventArgs e)
+        {
+            if (Counter.Checked) {
+                string ExitConfirm = MessageBox.Show(this, "确认切换为计数器?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+                if (ExitConfirm == "Yes")
+                {
+                    OperateResult write = plc.Write(UseScan.Text, 0);
+                    if (write.IsSuccess)
+                    {
+                        OperateResult.AppendText("通过,发送指令" + UseScan.Text + "写入0\n");
+                    }
+                    else
+                    {
+                        OperateResult.AppendText("写入失败\n");
+                    }
+                }
+                else
+                {
+                    SN.Checked = false;
+                }
+            }
+         
+        }
+
+        private void SN_CheckedChanged(object sender, EventArgs e)
+        {
+            if (SN.Checked) {
+                string ExitConfirm = MessageBox.Show(this, "确认切换为扫码?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+                if (ExitConfirm == "Yes")
+                {
+                    OperateResult write = plc.Write(UseScan.Text, 2);
+                    if (write.IsSuccess)
+                    {
+                        OperateResult.AppendText("通过,发送指令" + UseScan.Text + "写入2\n");
+                    }
+                    else
+                    {
+                        OperateResult.AppendText("写入失败\n");
+                    }
+                }
+                else
+                {
+                    Counter.Checked = true;
+                }
+            }
+       
+        }
     }
 }