//请求堆垛机状态 private void SendTelegramCRQ(string CraneNo) { THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); tgd.CraneNo = CraneNo; THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string QuenceNo = GetNextSQuenceNo(); string str = tf.DataFraming("1" + QuenceNo, tgd, tf.TelegramCRQ); WriteToService("Crane", "CRQ", str); //记录发送的CRQ报文,预防堆垛机返回错误序列号的NCK。 if (dtSendCRQ == null) { dtSendCRQ = new DataTable(); dtSendCRQ.Columns.Add("CRANE_NO", Type.GetType("System.String")); dtSendCRQ.Columns.Add("SQUENCE_NO", Type.GetType("System.String")); } DataRow dr = dtSendCRQ.NewRow(); dr.BeginEdit(); dr["CRANE_NO"] = CraneNo; dr["SQUENCE_NO"] = QuenceNo; dr.EndEdit(); dtSendCRQ.Rows.Add(dr); dtSendCRQ.AcceptChanges(); }
private void SendDUA() { THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string str = tf.DataFraming("00000", tgd, tf.TelegramDUA); WriteToService("Crane", "DUA", str); }
private void SendDUM() { THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string str = tf.DataFraming("00000", tgd, tf.TelegramDUM); WriteToService("Crane", "DUM", str); //WriteToService("Crane", "DUM", "<00000CRAN30THOK01DUM0000000>"); }
/// <summary> /// 删除指令 /// </summary> /// <param name="dr"></param> private void SendTelegramDER(DataRow dr) { THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); tgd.CraneNo = dr["CRANE_NO"].ToString(); tgd.AssignmenID = dr["ASSIGNMENT_ID"].ToString(); THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string QuenceNo = GetNextSQuenceNo(); string str = tf.DataFraming("1" + QuenceNo, tgd, tf.TelegramDER); WriteToService("Crane", "DER", str); }
private void SendACK(Dictionary <string, string> msg) { if (msg["ConfirmFlag"] == "1") { THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); tgd.SequenceNo = msg["SeqNo"]; THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string str = tf.DataFraming("00000", tgd, tf.TelegramACK); //string str = "<00000CRAN30THOK01ACK0" + msg["SeqNo"] + "00>"; WriteToService("Crane", "ACK", str); } }
/// <summary> /// blnValue=true 正常发送ARQ报文,如果目标地址有货,报警,并要重新指定新货位,blnValue=false /// </summary> /// <param name="dr"></param> /// <param name="blnValue"></param> private void SendTelegramARQ(DataRow dr,bool blnValue) { THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); tgd.CraneNo = dr["CRANE_NO"].ToString(); tgd.AssignmenID = dr["ASSIGNMENT_ID"].ToString(); if (!blnValue) { tgd.AssignmentType = "DE"; } string TaskType = dr["TASK_TYPE"].ToString(); string ItemNo = dr["ITEM_NO"].ToString(); if (TaskType.Substring(1, 1) == "4" && ItemNo == "1" && dr["CRANE_NO"].ToString() == dr["NEW_CRANE_NO"].ToString()) { tgd.StartPosition = dr["CRANESTATION"].ToString(); tgd.DestinationPosition = dr["NEW_TO_STATION"].ToString(); } else { if (TaskType.Substring(1, 1) == "1" || (TaskType.Substring(1, 1) == "4" && ItemNo == "3") || TaskType.Substring(1, 1) == "3" && ItemNo == "4") //入库 { tgd.StartPosition = dr["CRANESTATION"].ToString(); tgd.DestinationPosition = dr["CELLSTATION"].ToString(); } else //出库 { tgd.StartPosition = dr["CELLSTATION"].ToString(); tgd.DestinationPosition = dr["CRANESTATION"].ToString(); } } THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string QuenceNo = GetNextSQuenceNo(); string str = tf.DataFraming("1" + QuenceNo, tgd, tf.TelegramARQ); WriteToService("Crane", "ARQ", str); DataRow[] drs = dtCrane.Select(string.Format("TASK_ID='{0}'", dr["TASK_ID"])); if (drs.Length > 0) { drs[0].BeginEdit(); drs[0]["SQUENCE_NO"] = QuenceNo; drs[0].EndEdit(); dtCrane.AcceptChanges(); dr.BeginEdit(); dr["SQUENCE_NO"] = QuenceNo; dr.EndEdit(); } lock (dCraneState) { dCraneState[dr["CRANE_NO"].ToString()] = "1"; } //更新发送报文。 TaskDal dal = new TaskDal(); dal.UpdateCraneQuenceNo(dr["TASK_ID"].ToString(), dr["SQUENCE_NO"].ToString(), ItemNo); //更新堆垛机序列号。并更新为1 }
private void SendSYN() { THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string str = tf.DataFraming("00000", tgd, tf.TelegramSYN); WriteToService("Crane", "SYN", str); //WriteToService("Crane", "DUM", "<00000CRAN30THOK01SYN0000000>"); }
private void SendACK(Dictionary<string, string> msg) { if (msg["ConfirmFlag"] == "1") { THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); tgd.SequenceNo = msg["SeqNo"]; THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string str = tf.DataFraming("00000", tgd, tf.TelegramACK); //string str = "<00000CRAN30THOK01ACK0" + msg["SeqNo"] + "00>"; WriteToService("Crane", "ACK", str); } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { /* 处理事项: * * 堆垛机任务处理 * 出库任务传入Task 需要产生TaskDetail,并更新起始位置及目的地。 * 入库任务传入TaskDetail * Init - 初始化。 * FirstBatch - 生成第一批入库请求任务。 * StockInRequest - 根据请求,生成入库任务。 * * stateItem.State :参数 - 请求的卷烟编码。 */ try { switch (stateItem.ItemName) { case "StockOutRequest": //开始出库,主动调用。 DataTable[] dtSend = (DataTable[])stateItem.State; if (dtSend[1] != null) { InsertCraneQuene(dtSend[1]); } InsertCraneQuene(dtSend[0]); CraneThreadStart();//线程调度堆垛机 break; case "StockOutToCarStation": //烟包经过扫描,正确烟包更新为3,错误更新为4. string[] strdd = (string[])stateItem.State; if (dtCrane != null) { DataRow[] drs = dtCrane.Select(string.Format("TASK_ID='{0}'", strdd[0])); if (drs.Length > 0) { TaskDal tdal = new TaskDal(); tdal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=1", drs[0]["TASK_ID"].ToString()), "2"); ProductStateDal psdal = new ProductStateDal(); psdal.UpdateOutBillNo(strdd[0]); dtCrane.Rows.Remove(drs[0]); } CraneThreadStart(); //更新完成之后,线程调用堆垛机,避免堆垛机因调度原因而是堆垛机没有任务。 } break; case "CraneInRequest": //货物到达入库站台,调用堆垛机 DataTable dtInCrane = (DataTable)stateItem.State; InsertCraneQuene(dtInCrane); SendTelegram(dtInCrane.Rows[0]["CRANE_NO"].ToString(), dtInCrane.Rows[0]); break; case "ACP": ACP(stateItem.State); break; case "CSR": CSR(stateItem.State); break; case "ACK": ACK(stateItem.State); break; case "DUM": THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string str = tf.DataFraming("00000", tgd, tf.TelegramDUA); WriteToService("Crane", "DUA", str); break; case "DUU": WriteToService("Crane", "DUM", "<00000CRAN30THOK01DUM0000000>"); break; case "NCK": NCK(stateItem.State); break; case "DEC": DEC(stateItem.State); break; default: break; } } catch (Exception e) { Logger.Error("THOK.XC.Process.Process_Crane.CraneProcess,原因:" + e.Message); } }
private void btnOption_Click(object sender, EventArgs e) { if (this.dgvMain.SelectedRows.Count == 0) { MessageBox.Show("请选择要操作的数据行!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } CraneTaskOptionDialog frm = new CraneTaskOptionDialog(); if (frm.ShowDialog() == DialogResult.OK) { DataRow dr = dt.Select(string.Format("TASK_ID='{0}'", this.dgvMain.SelectedRows[0].Cells["colTaskID"].Value.ToString()))[0]; if (frm.OptionCode == "DER") //删除指定 { THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); tgd.CraneNo = dr["CRANE_NO"].ToString(); tgd.AssignmenID = dr["ASSIGNMENT_ID"].ToString(); THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string QuenceNo = GetNextSQuenceNo(); string str = tf.DataFraming("1" + QuenceNo, tgd, tf.TelegramDER); this.mainFrame.Context.ProcessDispatcher.WriteToService("Crane", "DER", str); MessageBox.Show("操作成功", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); tgd.CraneNo = dr["CRANE_NO"].ToString(); tgd.AssignmenID = dr["ASSIGNMENT_ID"].ToString(); string TaskType = dr["TASK_TYPE"].ToString(); string ItemNo = dr["ITEM_NO"].ToString(); if (TaskType.Substring(1, 1) == "4" && ItemNo == "1" && dr["CRANE_NO"].ToString() == dr["NEW_CRANE_NO"].ToString()) { tgd.StartPosition = dr["CRANESTATION"].ToString(); tgd.DestinationPosition = dr["NEW_TO_STATION"].ToString(); } else { if (TaskType.Substring(1, 1) == "1" || (TaskType.Substring(1, 1) == "4" && ItemNo == "3") || TaskType.Substring(1, 1) == "3" && ItemNo == "4") //入库 { tgd.StartPosition = dr["CRANESTATION"].ToString(); tgd.DestinationPosition = dr["CELLSTATION"].ToString(); } else //出库 { tgd.StartPosition = dr["CELLSTATION"].ToString(); tgd.DestinationPosition = dr["CRANESTATION"].ToString(); } } THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string QuenceNo = GetNextSQuenceNo(); string str = tf.DataFraming("1" + QuenceNo, tgd, tf.TelegramARQ); this.mainFrame.Context.ProcessDispatcher.WriteToService("Crane", "ARQ", str); MessageBox.Show("操作成功", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/// <summary> /// blnValue=true 正常发送ARQ报文,如果目标地址有货,报警,并要重新指定新货位,blnValue=false /// </summary> /// <param name="dr"></param> /// <param name="blnValue"></param> private void SendTelegramARQ(DataRow dr, bool blnValue) { THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); tgd.CraneNo = dr["CRANE_NO"].ToString(); tgd.AssignmenID = dr["ASSIGNMENT_ID"].ToString(); if (!blnValue) { tgd.AssignmentType = "DE"; } string TaskType = dr["TASK_TYPE"].ToString(); string ItemNo = dr["ITEM_NO"].ToString(); if (TaskType.Substring(1, 1) == "4" && ItemNo == "1" && dr["CRANE_NO"].ToString() == dr["NEW_CRANE_NO"].ToString()) { tgd.StartPosition = dr["CRANESTATION"].ToString(); tgd.DestinationPosition = dr["NEW_TO_STATION"].ToString(); } else { if (TaskType.Substring(1, 1) == "1" || (TaskType.Substring(1, 1) == "4" && ItemNo == "3") || TaskType.Substring(1, 1) == "3" && ItemNo == "4") //入库 { tgd.StartPosition = dr["CRANESTATION"].ToString(); tgd.DestinationPosition = dr["CELLSTATION"].ToString(); } else //出库 { tgd.StartPosition = dr["CELLSTATION"].ToString(); tgd.DestinationPosition = dr["CRANESTATION"].ToString(); } } THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string QuenceNo = GetNextSQuenceNo(); string str = tf.DataFraming("1" + QuenceNo, tgd, tf.TelegramARQ); WriteToService("Crane", "ARQ", str); DataRow[] drs = dtCrane.Select(string.Format("TASK_ID='{0}'", dr["TASK_ID"])); if (drs.Length > 0) { drs[0].BeginEdit(); drs[0]["SQUENCE_NO"] = QuenceNo; drs[0].EndEdit(); dtCrane.AcceptChanges(); dr.BeginEdit(); dr["SQUENCE_NO"] = QuenceNo; dr.EndEdit(); } lock (dCraneState) { dCraneState[dr["CRANE_NO"].ToString()] = "1"; } //更新发送报文。 TaskDal dal = new TaskDal(); dal.UpdateCraneQuenceNo(dr["TASK_ID"].ToString(), dr["SQUENCE_NO"].ToString(), ItemNo); //更新堆垛机序列号。并更新为1 }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { /* 处理事项: * * 堆垛机任务处理 * 出库任务传入Task 需要产生TaskDetail,并更新起始位置及目的地。 * 入库任务传入TaskDetail * Init - 初始化。 * FirstBatch - 生成第一批入库请求任务。 * StockInRequest - 根据请求,生成入库任务。 * * stateItem.State :参数 - 请求的卷烟编码。 */ try { switch (stateItem.ItemName) { case "StockOutRequest": //开始出库,主动调用。 DataTable[] dtSend = (DataTable[])stateItem.State; if (dtSend[1] != null) { InsertCraneQuene(dtSend[1]); } InsertCraneQuene(dtSend[0]); CraneThreadStart(); //线程调度堆垛机 break; case "StockOutToCarStation": //烟包经过扫描,正确烟包更新为3,错误更新为4. string[] strdd = (string[])stateItem.State; if (dtCrane != null) { DataRow[] drs = dtCrane.Select(string.Format("TASK_ID='{0}'", strdd[0])); if (drs.Length > 0) { TaskDal tdal = new TaskDal(); tdal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=1", drs[0]["TASK_ID"].ToString()), "2"); ProductStateDal psdal = new ProductStateDal(); psdal.UpdateOutBillNo(strdd[0]); dtCrane.Rows.Remove(drs[0]); } CraneThreadStart(); //更新完成之后,线程调用堆垛机,避免堆垛机因调度原因而是堆垛机没有任务。 } break; case "CraneInRequest": //货物到达入库站台,调用堆垛机 DataTable dtInCrane = (DataTable)stateItem.State; InsertCraneQuene(dtInCrane); SendTelegram(dtInCrane.Rows[0]["CRANE_NO"].ToString(), dtInCrane.Rows[0]); break; case "ACP": ACP(stateItem.State); break; case "CSR": CSR(stateItem.State); break; case "ACK": ACK(stateItem.State); break; case "DUM": THOK.CRANE.TelegramData tgd = new CRANE.TelegramData(); THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming(); string str = tf.DataFraming("00000", tgd, tf.TelegramDUA); WriteToService("Crane", "DUA", str); break; case "DUU": WriteToService("Crane", "DUM", "<00000CRAN30THOK01DUM0000000>"); break; case "NCK": NCK(stateItem.State); break; case "DEC": DEC(stateItem.State); break; default: break; } } catch (Exception e) { Logger.Error("THOK.XC.Process.Process_Crane.CraneProcess,原因:" + e.Message); } }