浏览代码

添加红外计数接口

callm 1 周之前
父节点
当前提交
da6ba7b9d1

+ 281 - 5
UAS_MES_YTDZ/FunctionCode/Make/Make_SplitBoard.Designer.cs

@@ -28,23 +28,299 @@
         /// </summary>
         private void InitializeComponent()
         {
+            this.components = new System.ComponentModel.Container();
+            this.pr_pcbacount = new System.Windows.Forms.NumericUpDown();
+            this.label6 = new System.Windows.Forms.Label();
+            this.NowQTY = new System.Windows.Forms.TextBox();
+            this.label4 = new System.Windows.Forms.Label();
+            this.BaudRate = new System.Windows.Forms.TextBox();
+            this.label3 = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.AutoStart = new System.Windows.Forms.CheckBox();
+            this.Type = new System.Windows.Forms.ComboBox();
+            this.ATEFile = new System.IO.FileSystemWatcher();
+            this.Timer = new System.Windows.Forms.Timer(this.components);
+            this.MakeCode_lable = new System.Windows.Forms.Label();
+            this.Clean = new System.Windows.Forms.Button();
+            this.OperateResult = new System.Windows.Forms.RichTextBox();
+            this.StopWatch = new System.Windows.Forms.Button();
+            this.StartWatch = new System.Windows.Forms.Button();
+            this.XmlFolder = new System.Windows.Forms.FolderBrowserDialog();
+            this.label1 = new System.Windows.Forms.Label();
+            this.XmlWatcher = new System.IO.FileSystemWatcher();
+            this.ma_code = new UAS_MES_NEW.CustomControl.TextBoxWithIcon.MaCodeSearchTextBox();
+            this.ComPort = new UAS_MES_NEW.CustomControl.ComBoxWithFocus.SerialPortCombox();
+            ((System.ComponentModel.ISupportInitialize)(this.pr_pcbacount)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.ATEFile)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).BeginInit();
             this.SuspendLayout();
             // 
-            // 分板作业
+            // pr_pcbacount
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
+            this.pr_pcbacount.Location = new System.Drawing.Point(480, 601);
+            this.pr_pcbacount.Name = "pr_pcbacount";
+            this.pr_pcbacount.Size = new System.Drawing.Size(120, 35);
+            this.pr_pcbacount.TabIndex = 48;
+            this.pr_pcbacount.Value = new decimal(new int[] {
+            1,
+            0,
+            0,
+            0});
+            // 
+            // 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(310, 598);
+            this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(104, 38);
+            this.label6.TabIndex = 47;
+            this.label6.Text = "拼版数";
+            // 
+            // NowQTY
+            // 
+            this.NowQTY.Location = new System.Drawing.Point(480, 681);
+            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);
+            this.NowQTY.TabIndex = 45;
+            // 
+            // label4
+            // 
+            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(310, 678);
+            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);
+            this.label4.TabIndex = 44;
+            this.label4.Text = "当前计数";
+            // 
+            // BaudRate
+            // 
+            this.BaudRate.Location = new System.Drawing.Point(840, 376);
+            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(702, 376);
+            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 = "波特率";
+            // 
+            // label2
+            // 
+            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(310, 376);
+            this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(75, 38);
+            this.label2.TabIndex = 41;
+            this.label2.Text = "串口";
+            // 
+            // AutoStart
+            // 
+            this.AutoStart.AutoSize = true;
+            this.AutoStart.Checked = true;
+            this.AutoStart.CheckState = System.Windows.Forms.CheckState.Checked;
+            this.AutoStart.Location = new System.Drawing.Point(954, 460);
+            this.AutoStart.Name = "AutoStart";
+            this.AutoStart.Size = new System.Drawing.Size(186, 28);
+            this.AutoStart.TabIndex = 40;
+            this.AutoStart.Text = "开机自动启动";
+            this.AutoStart.UseVisualStyleBackColor = true;
+            // 
+            // Type
+            // 
+            this.Type.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.Type.FormattingEnabled = true;
+            this.Type.Items.AddRange(new object[] {
+            "投入",
+            "产出"});
+            this.Type.Location = new System.Drawing.Point(480, 528);
+            this.Type.Name = "Type";
+            this.Type.Size = new System.Drawing.Size(436, 32);
+            this.Type.TabIndex = 38;
+            // 
+            // ATEFile
+            // 
+            this.ATEFile.EnableRaisingEvents = true;
+            this.ATEFile.Filter = "*.txt";
+            this.ATEFile.SynchronizingObject = this;
+            // 
+            // Timer
+            // 
+            this.Timer.Interval = 2000;
+            this.Timer.Tick += new System.EventHandler(this.Timer_Tick);
+            // 
+            // MakeCode_lable
+            // 
+            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(310, 453);
+            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);
+            this.MakeCode_lable.TabIndex = 37;
+            this.MakeCode_lable.Text = "工单号";
+            // 
+            // Clean
+            // 
+            this.Clean.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Clean.Location = new System.Drawing.Point(1372, 836);
+            this.Clean.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.Clean.Name = "Clean";
+            this.Clean.Size = new System.Drawing.Size(112, 48);
+            this.Clean.TabIndex = 36;
+            this.Clean.Text = "清除";
+            this.Clean.UseVisualStyleBackColor = true;
+            // 
+            // OperateResult
+            // 
+            this.OperateResult.Location = new System.Drawing.Point(1168, 278);
+            this.OperateResult.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.OperateResult.Name = "OperateResult";
+            this.OperateResult.Size = new System.Drawing.Size(517, 535);
+            this.OperateResult.TabIndex = 35;
+            this.OperateResult.Text = "";
+            // 
+            // 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(774, 813);
+            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 = 34;
+            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(566, 813);
+            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 = 33;
+            this.StartWatch.Text = "开始监控";
+            this.StartWatch.UseVisualStyleBackColor = true;
+            this.StartWatch.Click += new System.EventHandler(this.StartWatch_Click);
+            // 
+            // label1
+            // 
+            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(310, 522);
+            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);
+            this.label1.TabIndex = 39;
+            this.label1.Text = "类型";
+            // 
+            // XmlWatcher
+            // 
+            this.XmlWatcher.EnableRaisingEvents = true;
+            this.XmlWatcher.Filter = "*.log";
+            this.XmlWatcher.SynchronizingObject = this;
+            // 
+            // ma_code
+            // 
+            this.ma_code.AllPower = null;
+            this.ma_code.Caller = null;
+            this.ma_code.Condition = null;
+            this.ma_code.DBTitle = null;
+            this.ma_code.FormName = null;
+            this.ma_code.Location = new System.Drawing.Point(480, 453);
+            this.ma_code.Margin = new System.Windows.Forms.Padding(5);
+            this.ma_code.Name = "ma_code";
+            this.ma_code.Power = null;
+            this.ma_code.ReturnData = null;
+            this.ma_code.SelectField = null;
+            this.ma_code.SetValueField = null;
+            this.ma_code.Size = new System.Drawing.Size(436, 43);
+            this.ma_code.TabIndex = 68;
+            this.ma_code.TableName = null;
+            this.ma_code.Tag = "ma_code";
+            this.ma_code.TextBoxEnable = true;
+            // 
+            // ComPort
+            // 
+            this.ComPort.Location = new System.Drawing.Point(480, 376);
+            this.ComPort.Margin = new System.Windows.Forms.Padding(4);
+            this.ComPort.Name = "ComPort";
+            this.ComPort.Size = new System.Drawing.Size(192, 40);
+            this.ComPort.TabIndex = 69;
+            // 
+            // Make_SplitBoard
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(1329, 727);
+            this.ClientSize = new System.Drawing.Size(1994, 1163);
+            this.Controls.Add(this.ComPort);
+            this.Controls.Add(this.ma_code);
+            this.Controls.Add(this.pr_pcbacount);
+            this.Controls.Add(this.label6);
+            this.Controls.Add(this.NowQTY);
+            this.Controls.Add(this.label4);
+            this.Controls.Add(this.BaudRate);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.AutoStart);
+            this.Controls.Add(this.Type);
+            this.Controls.Add(this.MakeCode_lable);
+            this.Controls.Add(this.Clean);
+            this.Controls.Add(this.OperateResult);
+            this.Controls.Add(this.StopWatch);
+            this.Controls.Add(this.StartWatch);
+            this.Controls.Add(this.label1);
             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
-            this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
-            this.Name = "分板作业";
+            this.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.Name = "Make_SplitBoard";
             this.Tag = "Make!SplitBoard";
             this.Text = "分板作业";
             this.Load += new System.EventHandler(this.分板作业_Load);
+            ((System.ComponentModel.ISupportInitialize)(this.pr_pcbacount)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.ATEFile)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).EndInit();
             this.ResumeLayout(false);
+            this.PerformLayout();
 
         }
 
         #endregion
+
+        private System.Windows.Forms.NumericUpDown pr_pcbacount;
+        private System.Windows.Forms.Label label6;
+        private System.Windows.Forms.TextBox NowQTY;
+        private System.Windows.Forms.Label label4;
+        private System.Windows.Forms.TextBox BaudRate;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.CheckBox AutoStart;
+        private System.Windows.Forms.ComboBox Type;
+        private System.IO.FileSystemWatcher ATEFile;
+        private System.Windows.Forms.Label MakeCode_lable;
+        private System.Windows.Forms.Button Clean;
+        private System.Windows.Forms.RichTextBox OperateResult;
+        private System.Windows.Forms.Button StopWatch;
+        private System.Windows.Forms.Button StartWatch;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Timer Timer;
+        private System.Windows.Forms.FolderBrowserDialog XmlFolder;
+        private System.IO.FileSystemWatcher XmlWatcher;
+        private CustomControl.TextBoxWithIcon.MaCodeSearchTextBox ma_code;
+        private CustomControl.ComBoxWithFocus.SerialPortCombox ComPort;
     }
 }

+ 136 - 7
UAS_MES_YTDZ/FunctionCode/Make/Make_SplitBoard.cs

@@ -1,16 +1,19 @@
 using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
+using System.IO.Ports;
 using System.Windows.Forms;
+using UAS_MES_NEW.DataOperate;
+using UAS_MES_NEW.Entity;
+using UAS_MES_NEW.PublicMethod;
 
 namespace UAS_MES_NEW.Make
 {
     public partial class Make_SplitBoard : Form
     {
+
+        DataHelper dh = null;
+
+        SerialPort serialPort1 = new SerialPort();
+
         public Make_SplitBoard()
         {
             InitializeComponent();
@@ -18,7 +21,133 @@ namespace UAS_MES_NEW.Make
 
         private void 分板作业_Load(object sender, EventArgs e)
         {
+            dh = SystemInf.dh;
+            serialPort1.DataReceived += SerialPort1_DataReceived;
+        }
+
+        private void StartWatch_Click(object sender, EventArgs e)
+        {
+            BaseUtil.SetCacheData("Type", Type.Text);
+            BaseUtil.SetCacheData("ComPort", ComPort.Text);
+            BaseUtil.SetCacheData("BaudRate", BaudRate.Text);
+            if (!dh.CheckExist("Make", "ma_code='" + ma_code.Text + "'"))
+            {
+                OperateResult.AppendText("工单号不能为空\n");
+                return;
+            }
+            if (Type.Text == "印刷机")
+            {
+                Timer.Start();
+            }
+            else
+            {
+                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");
+        }
 
+        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("-", "");
+
+            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_sourcecode,mhc_stepcode,mhc_pcbcount)" +
+                        "values(makehourcount_seq.nextval,'" + ma_code.Text + "',sysdate,'" + Type.Text + "','" + (qty - lastqty) + "','" + User.UserSourceCode + "','" + User.CurrentStepCode + "','" + 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_sourcecode,mhc_stepcode,mhc_pcbcount)" +
+                             "values(makehourcount_seq.nextval,'" + ma_code.Text + "',sysdate,'" + Type.Text + "','" + (qty - lastqty) + "','" + User.UserSourceCode + "','" + User.CurrentStepCode + "','" + pr_pcbacount.Value + "')", "insert");
+                }
+                lastqty = qty;
+            }
+        }
+
+        private void StopWatch_Click(object sender, EventArgs e)
+        {
+            XmlWatcher.EnableRaisingEvents = false;
+            StartWatch.Enabled = true;
+            ma_code.Enabled = true;
+
+            StopWatch.Enabled = false;
+            OperateResult.AppendText("停止执行监控\n");
+        }
+
+        private void Timer_Tick(object sender, EventArgs e)
+        {
+            if (serialPort1.IsOpen)
+            {
+                byte[] data = HexStringToBytes("01 03 00 01 00 06 94 08");
+                serialPort1.Write(data, 0, data.Length);
+            }
+        }
+
+        private byte[] HexStringToBytes(string hs)//十六进制字符串转byte
+        {
+            string a = hs.Replace(" ", "");
+            int bytelength = 0;
+            if (a.Length % 2 == 0)
+            {
+                bytelength = a.Length / 2;
+            }
+            else
+            {
+                bytelength = a.Length / 2 + 1;
+            }
+            byte[] b = new byte[bytelength];
+            //逐个字符变为16进制字节数据
+            for (int i = 0; i < bytelength; i++)
+            {
+                if (i == bytelength - 1)
+                {
+                    b[i] = Convert.ToByte(a.Substring(i * 2), 16);
+                }
+                else
+                {
+                    b[i] = Convert.ToByte(a.Substring(i * 2, 2), 16);
+                }
+            }
+            //按照指定编码将字节数组变为字符串
+            return b;
         }
     }
-}
+}

+ 12 - 0
UAS_MES_YTDZ/FunctionCode/Make/Make_SplitBoard.resx

@@ -117,4 +117,16 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
+  <metadata name="ATEFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>592, 17</value>
+  </metadata>
+  <metadata name="Timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>749, 17</value>
+  </metadata>
+  <metadata name="XmlFolder.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>888, 17</value>
+  </metadata>
+  <metadata name="XmlWatcher.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>1080, 17</value>
+  </metadata>
 </root>