Browse Source

修改计数器对接逻辑

callm 5 days ago
parent
commit
896df14174

+ 0 - 9
FileWatcher/AutoMakeQTY.cs

@@ -62,15 +62,6 @@ namespace FileWatcher
             BaseUtil.SetFormValue(this.Controls, Dbfind);
         }
 
-        private int Val(char Expression)
-        {
-            if (Expression >= '1' && Expression <= '9')
-            {
-                return unchecked((int)Expression) - 48;
-            }
-            return 0;
-        }
-
         private void Form1_Load(object sender, EventArgs e)
         {
 

+ 130 - 12
FileWatcher/AutoSMTRXY.Designer.cs

@@ -46,6 +46,16 @@
             this.RemindVoice = new System.Windows.Forms.CheckBox();
             this.SN = new System.Windows.Forms.RadioButton();
             this.Counter = new System.Windows.Forms.RadioButton();
+            this.StopWatch = new System.Windows.Forms.Button();
+            this.StartWatch = new System.Windows.Forms.Button();
+            this.BaudRate = new System.Windows.Forms.TextBox();
+            this.label3 = new System.Windows.Forms.Label();
+            this.label6 = new System.Windows.Forms.Label();
+            this.ComPort = new FileWatcher.SerialPortCombox();
+            this.Timer = new System.Windows.Forms.Timer(this.components);
+            this.pr_pcbacount = new System.Windows.Forms.NumericUpDown();
+            this.label7 = new System.Windows.Forms.Label();
+            ((System.ComponentModel.ISupportInitialize)(this.pr_pcbacount)).BeginInit();
             this.SuspendLayout();
             // 
             // OperateResult
@@ -73,7 +83,7 @@
             // 
             this.MakeCode_lable.AutoSize = true;
             this.MakeCode_lable.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.MakeCode_lable.Location = new System.Drawing.Point(51, 60);
+            this.MakeCode_lable.Location = new System.Drawing.Point(51, 120);
             this.MakeCode_lable.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.MakeCode_lable.Name = "MakeCode_lable";
             this.MakeCode_lable.Size = new System.Drawing.Size(104, 38);
@@ -87,7 +97,7 @@
             this.Type.Items.AddRange(new object[] {
             "投入",
             "产出"});
-            this.Type.Location = new System.Drawing.Point(221, 207);
+            this.Type.Location = new System.Drawing.Point(221, 267);
             this.Type.Name = "Type";
             this.Type.Size = new System.Drawing.Size(436, 32);
             this.Type.TabIndex = 18;
@@ -96,7 +106,7 @@
             // 
             this.label1.AutoSize = true;
             this.label1.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label1.Location = new System.Drawing.Point(51, 201);
+            this.label1.Location = new System.Drawing.Point(51, 261);
             this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label1.Name = "label1";
             this.label1.Size = new System.Drawing.Size(75, 38);
@@ -108,7 +118,7 @@
             this.AutoStart.AutoSize = true;
             this.AutoStart.Checked = true;
             this.AutoStart.CheckState = System.Windows.Forms.CheckState.Checked;
-            this.AutoStart.Location = new System.Drawing.Point(695, 67);
+            this.AutoStart.Location = new System.Drawing.Point(695, 127);
             this.AutoStart.Name = "AutoStart";
             this.AutoStart.Size = new System.Drawing.Size(186, 28);
             this.AutoStart.TabIndex = 20;
@@ -117,7 +127,7 @@
             // 
             // NowQTY
             // 
-            this.NowQTY.Location = new System.Drawing.Point(221, 286);
+            this.NowQTY.Location = new System.Drawing.Point(221, 346);
             this.NowQTY.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.NowQTY.Name = "NowQTY";
             this.NowQTY.Size = new System.Drawing.Size(146, 35);
@@ -127,7 +137,7 @@
             // 
             this.label4.AutoSize = true;
             this.label4.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label4.Location = new System.Drawing.Point(51, 283);
+            this.label4.Location = new System.Drawing.Point(51, 343);
             this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label4.Name = "label4";
             this.label4.Size = new System.Drawing.Size(133, 38);
@@ -138,7 +148,7 @@
             // 
             this.label5.AutoSize = true;
             this.label5.Font = new System.Drawing.Font("微软雅黑", 12F);
-            this.label5.Location = new System.Drawing.Point(51, 131);
+            this.label5.Location = new System.Drawing.Point(51, 191);
             this.label5.Name = "label5";
             this.label5.Size = new System.Drawing.Size(82, 41);
             this.label5.TabIndex = 27;
@@ -148,7 +158,7 @@
             // 
             this.label2.AutoSize = true;
             this.label2.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label2.Location = new System.Drawing.Point(51, 364);
+            this.label2.Location = new System.Drawing.Point(51, 424);
             this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label2.Name = "label2";
             this.label2.Size = new System.Drawing.Size(104, 38);
@@ -165,7 +175,7 @@
             this.ms_sncode.AllPower = null;
             this.ms_sncode.BackColor = System.Drawing.Color.White;
             this.ms_sncode.ID = null;
-            this.ms_sncode.Location = new System.Drawing.Point(221, 370);
+            this.ms_sncode.Location = new System.Drawing.Point(221, 430);
             this.ms_sncode.Name = "ms_sncode";
             this.ms_sncode.Power = null;
             this.ms_sncode.Size = new System.Drawing.Size(333, 35);
@@ -182,7 +192,7 @@
             this.ma_code.Condition = null;
             this.ma_code.DBTitle = null;
             this.ma_code.FormName = null;
-            this.ma_code.Location = new System.Drawing.Point(221, 54);
+            this.ma_code.Location = new System.Drawing.Point(221, 114);
             this.ma_code.Name = "ma_code";
             this.ma_code.Power = null;
             this.ma_code.ReturnData = null;
@@ -200,7 +210,7 @@
             this.li_code.Condition = null;
             this.li_code.DBTitle = null;
             this.li_code.FormName = null;
-            this.li_code.Location = new System.Drawing.Point(221, 131);
+            this.li_code.Location = new System.Drawing.Point(221, 191);
             this.li_code.Name = "li_code";
             this.li_code.Power = null;
             this.li_code.ReturnData = null;
@@ -216,7 +226,7 @@
             this.RemindVoice.AutoSize = true;
             this.RemindVoice.Checked = true;
             this.RemindVoice.CheckState = System.Windows.Forms.CheckState.Checked;
-            this.RemindVoice.Location = new System.Drawing.Point(695, 131);
+            this.RemindVoice.Location = new System.Drawing.Point(695, 191);
             this.RemindVoice.Name = "RemindVoice";
             this.RemindVoice.Size = new System.Drawing.Size(162, 28);
             this.RemindVoice.TabIndex = 35;
@@ -245,11 +255,109 @@
             this.Counter.Text = "计数器";
             this.Counter.UseVisualStyleBackColor = true;
             // 
+            // StopWatch
+            // 
+            this.StopWatch.Enabled = false;
+            this.StopWatch.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.StopWatch.Location = new System.Drawing.Point(402, 552);
+            this.StopWatch.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.StopWatch.Name = "StopWatch";
+            this.StopWatch.Size = new System.Drawing.Size(128, 56);
+            this.StopWatch.TabIndex = 39;
+            this.StopWatch.Text = "停止监控";
+            this.StopWatch.UseVisualStyleBackColor = true;
+            this.StopWatch.Click += new System.EventHandler(this.StopWatch_Click);
+            // 
+            // StartWatch
+            // 
+            this.StartWatch.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.StartWatch.Location = new System.Drawing.Point(206, 552);
+            this.StartWatch.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.StartWatch.Name = "StartWatch";
+            this.StartWatch.Size = new System.Drawing.Size(128, 56);
+            this.StartWatch.TabIndex = 38;
+            this.StartWatch.Text = "开始监控";
+            this.StartWatch.UseVisualStyleBackColor = true;
+            this.StartWatch.Click += new System.EventHandler(this.StartWatch_Click);
+            // 
+            // BaudRate
+            // 
+            this.BaudRate.Location = new System.Drawing.Point(578, 35);
+            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;
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label3.Location = new System.Drawing.Point(440, 35);
+            this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(104, 38);
+            this.label3.TabIndex = 42;
+            this.label3.Text = "波特率";
+            // 
+            // label6
+            // 
+            this.label6.AutoSize = true;
+            this.label6.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label6.Location = new System.Drawing.Point(48, 35);
+            this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(75, 38);
+            this.label6.TabIndex = 41;
+            this.label6.Text = "串口";
+            // 
+            // ComPort
+            // 
+            this.ComPort.Location = new System.Drawing.Point(218, 35);
+            this.ComPort.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+            this.ComPort.Name = "ComPort";
+            this.ComPort.Size = new System.Drawing.Size(176, 40);
+            this.ComPort.TabIndex = 40;
+            // 
+            // Timer
+            // 
+            this.Timer.Interval = 2000;
+            // 
+            // pr_pcbacount
+            // 
+            this.pr_pcbacount.Location = new System.Drawing.Point(596, 349);
+            this.pr_pcbacount.Name = "pr_pcbacount";
+            this.pr_pcbacount.Size = new System.Drawing.Size(120, 35);
+            this.pr_pcbacount.TabIndex = 45;
+            this.pr_pcbacount.Value = new decimal(new int[] {
+            1,
+            0,
+            0,
+            0});
+            // 
+            // label7
+            // 
+            this.label7.AutoSize = true;
+            this.label7.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label7.Location = new System.Drawing.Point(426, 346);
+            this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label7.Name = "label7";
+            this.label7.Size = new System.Drawing.Size(104, 38);
+            this.label7.TabIndex = 44;
+            this.label7.Text = "拼版数";
+            // 
             // AutoSMTRXY
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1443, 640);
+            this.Controls.Add(this.pr_pcbacount);
+            this.Controls.Add(this.label7);
+            this.Controls.Add(this.BaudRate);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.label6);
+            this.Controls.Add(this.ComPort);
+            this.Controls.Add(this.StopWatch);
+            this.Controls.Add(this.StartWatch);
             this.Controls.Add(this.SN);
             this.Controls.Add(this.Counter);
             this.Controls.Add(this.RemindVoice);
@@ -272,6 +380,7 @@
             this.Text = "UAS设备数据解析 2023-06-29  10:05";
             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
             this.Load += new System.EventHandler(this.Form1_Load);
+            ((System.ComponentModel.ISupportInitialize)(this.pr_pcbacount)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 
@@ -295,6 +404,15 @@
         private System.Windows.Forms.CheckBox RemindVoice;
         private System.Windows.Forms.RadioButton SN;
         private System.Windows.Forms.RadioButton Counter;
+        private System.Windows.Forms.Button StopWatch;
+        private System.Windows.Forms.Button StartWatch;
+        private System.Windows.Forms.TextBox BaudRate;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.Label label6;
+        private SerialPortCombox ComPort;
+        private System.Windows.Forms.Timer Timer;
+        private System.Windows.Forms.NumericUpDown pr_pcbacount;
+        private System.Windows.Forms.Label label7;
     }
 }
 

+ 91 - 2
FileWatcher/AutoSMTRXY.cs

@@ -75,6 +75,7 @@ namespace FileWatcher
                 if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
                     IPAddress = IpEntry.AddressList[i].ToString();
             }
+            serialPort1.DataReceived += SerialPort1_DataReceived;
             //获取缓存信息
             try
             {
@@ -84,6 +85,41 @@ namespace FileWatcher
             catch (Exception ex) { MessageBox.Show(ex.Message); }
             RemindTimer.Start();
         }
+
+        double lastqty = 0;
+        private void SerialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
+        {
+            int len = serialPort1.BytesToRead;
+            Byte[] readBuffer = new Byte[len];
+            serialPort1.Read(readBuffer, 0, len); //将数据读入缓存
+            string data = BitConverter.ToString(readBuffer, 0, readBuffer.Length).Replace("-", "");
+            string error = "";
+            if (data != "")
+            {
+                double qty = Convert.ToInt32(data.Substring(6, 8), 16);
+                if (lastqty > qty)
+                {
+                    lastqty = 0;
+                }
+                NowQTY.Text = qty.ToString();
+                if (Type.Text == "投入")
+                {
+                    string ma_inqty = dh.getFieldDataByCondition("make", "nvl(ma_inqty,0)", "ma_code='" + ma_code.Text + "'").ToString();
+                    dh.ExecuteSql("update make set ma_inqty=nvl(ma_inqty,0)+'" + (qty - lastqty) + "' where ma_code='" + ma_code.Text + "' ", "update");
+                    dh.ExecuteSql("insert into makehourcount(mhc_id,mhc_macode,mhc_indate,mhc_type,mhc_qty,mhc_linecode,mhc_pcbcount)" +
+                        "values(makehourcount_seq.nextval,'" + ma_code.Text + "',sysdate,'" + Type.Text + "','" + (qty - lastqty) + "','" + li_code.Text + "','" + pr_pcbacount.Value + "')", "insert");
+                }
+                else
+                {
+                    string ma_endqty = dh.getFieldDataByCondition("make", "nvl(ma_endqty,0)", "ma_code='" + ma_code.Text + "'").ToString();
+                    dh.ExecuteSql("update make set ma_endqty=nvl(ma_endqty,0)+'" + (qty - lastqty) + "' where ma_code='" + ma_code.Text + "' ", "update");
+                    dh.ExecuteSql("insert into makehourcount(mhc_id,mhc_macode,mhc_indate,mhc_type,mhc_qty,mhc_linecode,mhc_pcbcount)" +
+                             "values(makehourcount_seq.nextval,'" + ma_code.Text + "',sysdate,'" + Type.Text + "','" + (qty - lastqty) + "','" + li_code.Text + "','" + pr_pcbacount.Value + "')", "insert");
+                }
+                LogicHandler.CS_SetResult(ma_code.Text, li_code.Text, "", qty.ToString(), li_code.Text, "OK", out error);
+                lastqty = qty;
+            }
+        }
         private void ConnectDB()
         {
             dh = new DataHelper();
@@ -201,12 +237,12 @@ namespace FileWatcher
                 if (dt.Rows.Count > 0)
                 {
                     string MainSN = dt.Rows[0]["MSL_MAINS"].ToString();
-                    LogicHandler.CS_SetResult(ma_code.Text, li_code.Text, MainSN, li_code.Text, "OK", out error);
+                    LogicHandler.CS_SetResult(ma_code.Text, li_code.Text, MainSN, "0", li_code.Text, "OK", out error);
                 }
             }
             else
             {
-                LogicHandler.CS_SetResult(ma_code.Text, li_code.Text, "", li_code.Text, "OK", out error);
+
             }
         }
 
@@ -214,5 +250,58 @@ namespace FileWatcher
         {
             Remind();
         }
+
+        private void StartWatch_Click(object sender, EventArgs e)
+        {
+            BaseUtil.SetCacheData("ComPort", ComPort.Text);
+            BaseUtil.SetCacheData("BaudRate", BaudRate.Text);
+            BaseUtil.SetCacheData("Line", li_code.Text);
+            if (!dh.CheckExist("Make", "ma_code='" + ma_code.Text + "'"))
+            {
+                OperateResult.AppendText("工单号不能为空\n");
+                return;
+            }
+            if (!dh.CheckExist("line", "li_code='" + li_code.Text + "'"))
+            {
+                OperateResult.AppendText("线别不能为空\n");
+                return;
+            }
+
+
+            string ExitConfirm = MessageBox.Show(this, "确认计数器是否置为0?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+            if (ExitConfirm != "Yes")
+            {
+                return;
+            }
+            //设置按钮不可点击
+            StartWatch.Enabled = false;
+            ma_code.Enabled = false;
+            StopWatch.Enabled = true;
+            try
+            {
+                serialPort1.PortName = ComPort.Text;
+                serialPort1.BaudRate = int.Parse(BaudRate.Text);
+                serialPort1.Open();
+                Timer.Start();
+            }
+            catch (Exception mes)
+            {
+                if (BaudRate.Text == "" || BaudRate.Text == "")
+                    OperateResult.AppendText(">>请先维护波特率和串口\n");
+                else
+                    OperateResult.AppendText(">>" + mes.Message + "\n");
+            }
+            OperateResult.AppendText("开始执行监控\n");
+        }
+
+        private void StopWatch_Click(object sender, EventArgs e)
+        {
+            StartWatch.Enabled = true;
+            ma_code.Enabled = true;
+
+            StopWatch.Enabled = false;
+            OperateResult.AppendText("停止执行监控\n");
+        }
+
     }
 }

+ 3 - 0
FileWatcher/AutoSMTRXY.resx

@@ -120,4 +120,7 @@
   <metadata name="RemindTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>17, 17</value>
   </metadata>
+  <metadata name="Timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>435, 17</value>
+  </metadata>
 </root>

+ 5 - 5
FileWatcher/LogicHandler.cs

@@ -222,16 +222,16 @@ namespace FileWatcher
             return false;
         }
 
-        public static bool SetStepResult(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, out string oErrorMessage)
+        public static bool SetStepResult(string iMakeCode, string iSourceCode, string iSN, string passqty, string iResult, string iUserCode, out string oErrorMessage)
         {
-            return CS_SetResult(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrorMessage);
+            return CS_SetResult(iMakeCode, iSourceCode, iSN, passqty, iUserCode, iResult, out oErrorMessage);
         }
 
-        public static bool CS_SetResult(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrorMessage)
+        public static bool CS_SetResult(string iMakeCode, string iSourceCode, string iSN,string passqty, string iUserCode, string iResult, out string oErrorMessage)
         {
             oErrorMessage = "";
-            string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrorMessage };
-            dh.CallProcedure("CS_SETSTEPRESULT", ref param);
+            string[] param = new string[] { iMakeCode, iSourceCode, iSN, passqty, iUserCode, iResult, oErrorMessage };
+            dh.CallProcedure("CS_SETSTEPRESULT_SMT", ref param);
             oErrorMessage = param[5];
             if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
                 return true;