Browse Source

设备对PLC指令调整

章政 6 years ago
parent
commit
015b1e1688

+ 5 - 0
UAS-出货标签管理(吉利通)/PublicMethod/LogicHandler.cs

@@ -38,6 +38,11 @@ namespace UAS_LabelMachine.PublicMethod
             adh.UpdateByCondition("prodiobarcode", "pib_ifpick=-1,pib_modify=-1", "pib_id=" + iPibID);
         }
 
+        /// <summary>
+        /// 根据对应的动作查找字段发送指令
+        /// </summary>
+        /// <param name="PLC"></param>
+        /// <param name="Movement"></param>
         public static void SendDataToPLC(SerialPortWithTag PLC, string Movement)
         {
             DataTable dt = (DataTable)adh.ExecuteSql("select * from plcinstruct", "select");

+ 69 - 36
UAS-出货标签管理(吉利通)/UAS_出货标签管理.cs

@@ -229,13 +229,7 @@ namespace UAS_LabelMachine
                             //接收到的数据和指令的对应则
                             if (item.Value == msg)
                             {
-                                switch (item.Key)
-                                {
-                                    case "":
-                                        break;
-                                    default:
-                                        break;
-                                }
+                                Console.WriteLine(item.Key);
                             }
                         }
                         break;
@@ -295,10 +289,10 @@ namespace UAS_LabelMachine
             }
         }
 
-        private bool FrontCheckFunction(string msg, out string ErrorMsg)
+        private bool RegexMatch(string CheckType, string msg, out string ErrorMsg, out int GroupCount)
         {
-            int GroupCount = 0;
             ErrorMsg = "";
+            GroupCount = 0;
             for (int i = 0; i < ScanGroup.Rows.Count; i++)
             {
                 string sg_name = ScanGroup.Rows[i]["sg_name"].ToString();
@@ -356,21 +350,24 @@ namespace UAS_LabelMachine
                                 int rownum = 0;
                                 if (pndt.Rows[0][0].ToString() != "")
                                 {
-                                    rownum = int.Parse(pndt.Rows[0]["rn"].ToString());
-                                    //如果需要翻页的话
-                                    if (!(rownum >= (PageSize * (CurrentPage - 1) + 1) && rownum <= PageSize * CurrentPage))
+                                    if (CheckType == "FrontCheck")
                                     {
-                                        CurrentPage = rownum / PageSize + 1;
-                                        LoadGridData();
-                                        CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
-                                        if (CurrentRowIndex - 10 > 0)
-                                            LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
-                                    }
-                                    else
-                                    {
-                                        CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
-                                        if (CurrentRowIndex - 10 > 0)
-                                            LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
+                                        rownum = int.Parse(pndt.Rows[0]["rn"].ToString());
+                                        //如果需要翻页的话
+                                        if (!(rownum >= (PageSize * (CurrentPage - 1) + 1) && rownum <= PageSize * CurrentPage))
+                                        {
+                                            CurrentPage = rownum / PageSize + 1;
+                                            LoadGridData();
+                                            CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
+                                            if (CurrentRowIndex - 10 > 0)
+                                                LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
+                                        }
+                                        else
+                                        {
+                                            CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
+                                            if (CurrentRowIndex - 10 > 0)
+                                                LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
+                                        }
                                     }
                                 }
                                 else
@@ -427,6 +424,22 @@ namespace UAS_LabelMachine
             {
                 ErrorMsg = "未匹配到合适的采集策略";
             }
+            if (ErrorMsg == "")
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        private bool FrontCheckFunction(string msg, out string ErrorMsg)
+        {
+            int GroupCount = 0;
+            ErrorMsg = "";
+            //调用正则验证
+            RegexMatch("FrontCheck", msg, out ErrorMsg, out GroupCount);
             if (ErrorMsg != "")
             {
                 return false;
@@ -442,11 +455,15 @@ namespace UAS_LabelMachine
                 boxcode = adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode2)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
                 int outboxcode2 = int.Parse(boxcode == "" ? "1" : boxcode);
                 string pd_id = LabelInf.Rows[CurrentRowIndex].Cells["pd_id"].Value.ToString();
+                //如果满容量获取过箱号就不再重复获取了
+                bool GetBarcode = false;
                 //超过中盒容量中盒号+1
                 if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + outboxcode1) >= MidBoxCapacity.Value)
                 {
                     outboxcode1 = outboxcode1 + 1;
+                    GetBarcode = true;
                     LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
+                    LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
                 }
                 //获取当前的行号
                 int CurrentRowNum = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["rownum"].Value.ToString());
@@ -458,45 +475,50 @@ namespace UAS_LabelMachine
                     //或者不符合合并条件中盒号+1
                     if (cu_print_midlotno.Checked)
                     {
-                        if (LastRowData.Rows[0]["pib_lotno"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString())
+                        if (LastRowData.Rows[0]["pib_lotno"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString() && !GetBarcode)
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
+                            LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
                             outboxcode1 = outboxcode1 + 1;
                         }
                     }
                     else if (cu_print_midpo.Checked)
                     {
-                        if (LastRowData.Rows[0]["pd_pocode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_pocode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() && !GetBarcode)
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
+                            LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
                             outboxcode1 = outboxcode1 + 1;
                         }
                     }
                     else if (cu_print_midprod.Checked)
                     {
-                        if (LastRowData.Rows[0]["pd_custprodcode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_custprodcode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString() && !GetBarcode)
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
+                            LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
                             outboxcode1 = outboxcode1 + 1;
                         }
                     }
                     else if (cu_print_midspec.Checked)
                     {
-                        if (LastRowData.Rows[0]["pd_custprodspec"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_custprodspec"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString() && !GetBarcode)
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
+                            LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
                             outboxcode1 = outboxcode1 + 1;
                         }
                     }
                     else if (cu_print_middc.Checked)
                     {
-                        if (LastRowData.Rows[0]["pib_datecode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pib_datecode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString() && !GetBarcode)
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
+                            LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
                             outboxcode1 = outboxcode1 + 1;
                         }
@@ -511,8 +533,10 @@ namespace UAS_LabelMachine
                     LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
                     LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
                 }
+                GetBarcode = false;
                 if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + outboxcode2) >= OutBoxCapacity.Value)
                 {
+                    GetBarcode = true;
                     outboxcode2 = outboxcode2 + 1;
                     LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
                     LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
@@ -522,7 +546,7 @@ namespace UAS_LabelMachine
                     //或者不符合合并条件中盒号+1
                     if (cu_print_outlotno.Checked)
                     {
-                        if (LastRowData.Rows[0]["pib_lotno"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString())
+                        if (LastRowData.Rows[0]["pib_lotno"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString() && !GetBarcode)
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
@@ -530,7 +554,7 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_outpo.Checked)
                     {
-                        if (LastRowData.Rows[0]["pd_pocode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_pocode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() && !GetBarcode)
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
@@ -538,7 +562,7 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_outprod.Checked)
                     {
-                        if (LastRowData.Rows[0]["pd_custprodcode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_custprodcode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString() && !GetBarcode)
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
@@ -546,7 +570,7 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_outspec.Checked)
                     {
-                        if (LastRowData.Rows[0]["pd_custprodspec"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString())
+                        if (LastRowData.Rows[0]["pd_custprodspec"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString() && !GetBarcode)
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
@@ -554,7 +578,7 @@ namespace UAS_LabelMachine
                     }
                     else if (cu_print_outdc.Checked)
                     {
-                        if (LastRowData.Rows[0]["pib_datecode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString())
+                        if (LastRowData.Rows[0]["pib_datecode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString() && !GetBarcode)
                         {
                             LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
                             LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
@@ -570,6 +594,7 @@ namespace UAS_LabelMachine
                     LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
                     LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
                 }
+
                 LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value = outboxcode1;
                 LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = outboxcode2;
                 string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
@@ -592,6 +617,7 @@ namespace UAS_LabelMachine
             //需要校验2项数据,完成校验后此项的值需要为2则表示校验成功
             int checkItemCount = 0;
             List<string> CheckItem = new List<string>();
+            int GroupCount = 0;
             for (int i = 0; i < msgArr.Length; i++)
             {
                 if (RecheckCuprodcode.Checked)
@@ -620,7 +646,7 @@ namespace UAS_LabelMachine
                             checkItemCount = checkItemCount + 1;
                         }
                     }
-                    if (msgArr[i] == LabelInf.Rows[CurrentRowIndex].Cells["pr_orispeccode"].Value.ToString())
+                    if (RegexMatch("BackCheck", msgArr[i], out ErrorMsg, out GroupCount))
                     {
                         CheckItem.Remove("原厂型号");
                         checkItemCount = checkItemCount + 1;
@@ -638,7 +664,7 @@ namespace UAS_LabelMachine
                         CheckItem.Remove("唯一条码");
                         checkItemCount = checkItemCount + 1;
                     }
-                    if (msgArr[i] == LabelInf.Rows[CurrentRowIndex].Cells["pr_orispeccode"].Value.ToString())
+                    if (RegexMatch("BackCheck", msgArr[i], out ErrorMsg, out GroupCount))
                     {
                         CheckItem.Remove("原厂型号");
                         checkItemCount = checkItemCount + 1;
@@ -1336,6 +1362,7 @@ namespace UAS_LabelMachine
         /// </summary>
         private void OutBoxCodePrint(int rowindex)
         {
+            LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
             //获取对应行的pib_id
             string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
             string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
@@ -1490,7 +1517,7 @@ namespace UAS_LabelMachine
             //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
             for (int i = 0; i < LabelInf.RowCount; i++)
             {
-                if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
+                if (LabelInf.Rows[i].Cells["pib_ifrecheck"].FormattedValue.ToString() != "True")
                 {
                     CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
                     break;
@@ -1812,6 +1839,7 @@ namespace UAS_LabelMachine
                     break;
                 case "参数配置":
                     ParamSetting form2 = new ParamSetting();
+                    form2.FormClosed += Form2_FormClosed;
                     BaseUtil.SetFormCenter(form2);
                     form2.ShowDialog();
                     break;
@@ -1825,6 +1853,11 @@ namespace UAS_LabelMachine
             }
         }
 
+        private void Form2_FormClosed(object sender, FormClosedEventArgs e)
+        {
+            RefreshPLCInstruct();
+        }
+
         private void DetailRange_CheckedChanged(object sender, EventArgs e)
         {
             if (DetailRange.Checked)