|
|
@@ -190,6 +190,7 @@ namespace UAS_LabelMachine
|
|
|
BackendCheck.DataReceived += Serial_DataReceived;
|
|
|
BackendCheck.Open();
|
|
|
}
|
|
|
+ RefreshPLCInstruct();
|
|
|
}
|
|
|
|
|
|
string LotNo = "";
|
|
|
@@ -203,6 +204,7 @@ namespace UAS_LabelMachine
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ string ErrorMsg = "";
|
|
|
SerialPortWithTag port = sender as SerialPortWithTag;
|
|
|
int len = port.BytesToRead;
|
|
|
byte[] readBuffer = new byte[len];
|
|
|
@@ -221,15 +223,30 @@ namespace UAS_LabelMachine
|
|
|
switch (port.Tag)
|
|
|
{
|
|
|
case "PLC1":
|
|
|
+ //返回的指令和设备执行的动作对应
|
|
|
+ foreach (var item in instruct)
|
|
|
+ {
|
|
|
+ //接收到的数据和指令的对应则
|
|
|
+ if (item.Value == msg)
|
|
|
+ {
|
|
|
+ switch (item.Key)
|
|
|
+ {
|
|
|
+ case "":
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
break;
|
|
|
case "PLC2":
|
|
|
break;
|
|
|
case "FrontendCheck":
|
|
|
//比对当前箱数量和容量
|
|
|
FrontCollect.Text = msg;
|
|
|
- string ErrorMsg = "";
|
|
|
if (!FrontCheckFunction(msg, out ErrorMsg))
|
|
|
{
|
|
|
+ LogicHandler.SendDataToPLC(PLC1, PLCInstruct.FrontDataDelete);
|
|
|
MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
|
|
|
}
|
|
|
else
|
|
|
@@ -251,12 +268,21 @@ namespace UAS_LabelMachine
|
|
|
if (MidLabelAutoPrint.Checked)
|
|
|
AutoPrintMidLabel();
|
|
|
LabelInfDataTable.Rows[CurrentRowIndex]["pib_ifpick"] = true;
|
|
|
+ LogicHandler.SendDataToPLC(PLC1, PLCInstruct.FrontDataPass);
|
|
|
LabelInf.Refresh();
|
|
|
}
|
|
|
break;
|
|
|
case "BackendCheck":
|
|
|
BackCheck.Text = msg;
|
|
|
- BackendCheckFunction(msg, pib_id);
|
|
|
+ if (BackendCheckFunction(msg, pib_id, out ErrorMsg))
|
|
|
+ {
|
|
|
+ LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataPass);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataDelete);
|
|
|
+ MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
|
|
|
+ }
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
@@ -411,8 +437,9 @@ namespace UAS_LabelMachine
|
|
|
//中盒条码号
|
|
|
string MidBoxBarCode = "";
|
|
|
|
|
|
- private void BackendCheckFunction(string msg, string pib_id)
|
|
|
+ private bool BackendCheckFunction(string msg, string pib_id, out string ErrorMsg)
|
|
|
{
|
|
|
+ ErrorMsg = "";
|
|
|
DataTable dtt = LabelInf.DataSource as DataTable;
|
|
|
string[] msgArr = msg.Split(back_sg_separator.Text.ToCharArray());
|
|
|
//需要校验2项数据,完成校验后此项的值需要为2则表示校验成功
|
|
|
@@ -458,7 +485,7 @@ namespace UAS_LabelMachine
|
|
|
if (checkItemCount != 2)
|
|
|
{
|
|
|
MessageBox.Show("复核不通过");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
LabelInfDataTable.Rows[CurrentRowIndex]["pib_ifrecheck"] = true;
|
|
|
adh.ExecuteSql("update prodiobarcode set pib_ifrecheck=-1 where pib_id=" + pib_id, "update");
|
|
|
@@ -603,6 +630,7 @@ namespace UAS_LabelMachine
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
//只执行一次窗体自适应
|
|
|
@@ -1787,7 +1815,7 @@ namespace UAS_LabelMachine
|
|
|
if (!PLC1.IsOpen)
|
|
|
{
|
|
|
PLC1.PortName = dr[0]["COM"].ToString();
|
|
|
- PLC1.Tag = "FrontendCheck";
|
|
|
+ PLC1.Tag = "PLC1";
|
|
|
PLC1.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
|
|
|
PLC1.DataReceived += Serial_DataReceived;
|
|
|
PLC1.Open();
|
|
|
@@ -1813,9 +1841,10 @@ namespace UAS_LabelMachine
|
|
|
|
|
|
private void ButtonRecheckPass_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
+ string ErrorMsg = "";
|
|
|
string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
|
|
|
int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
|
|
|
- BackendCheckFunction("", pib_id);
|
|
|
+ BackendCheckFunction("", pib_id, out ErrorMsg);
|
|
|
}
|
|
|
|
|
|
private void ButtonSetMidBox_Click(object sender, EventArgs e)
|
|
|
@@ -1892,5 +1921,20 @@ namespace UAS_LabelMachine
|
|
|
PageInf.Text = CurrentPage + "/" + MaxPageSize;
|
|
|
LoadGridData();
|
|
|
}
|
|
|
+
|
|
|
+ Dictionary<string, string> instruct = new Dictionary<string, string>();
|
|
|
+ private void RefreshPLCInstruct()
|
|
|
+ {
|
|
|
+ //查询所有的PLC指令
|
|
|
+ DataTable dtPLCInstruct = (DataTable)adh.ExecuteSql("select * from PLCInstruct", "select");
|
|
|
+ //如果存在指令参数的话则全部添加到键值对当中
|
|
|
+ if (dtPLCInstruct.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < dtPLCInstruct.Columns.Count; i++)
|
|
|
+ {
|
|
|
+ instruct.Add(dtPLCInstruct.Columns[i].ColumnName, dtPLCInstruct.Rows[0][dtPLCInstruct.Columns[i].ColumnName].ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|