private bool WriteTaskParam(ControlTaskModel ctlTask) { if (taskParamModel == null) { return(false); } //1 任务类型码 this.db1ValsToSnd[2] = (short)this.currentTask.TaskType; this.db1ValsToSnd[3] = (short)taskParamModel.InputPort; this.db1ValsToSnd[4] = (short)taskParamModel.OutputPort; this.db1ValsToSnd[5] = (short)taskParamModel.CellPos1.Row; this.db1ValsToSnd[6] = (short)taskParamModel.CellPos1.Col; this.db1ValsToSnd[7] = (short)taskParamModel.CellPos1.Layer; if (this.CurrentTask.TaskType == 5) { this.db1ValsToSnd[8] = (short)taskParamModel.CellPos2.Row; this.db1ValsToSnd[9] = (short)taskParamModel.CellPos2.Col; this.db1ValsToSnd[10] = (short)taskParamModel.CellPos2.Layer; } return(true); }
public virtual bool DevReset(ref string reStr) { this.currentTask = null; this.currentTaskPhase = 0; Array.Clear(this.db1ValsToSnd, 0, this.db1ValsToSnd.Length); return(NodeCmdCommit(false, ref reStr)); }
/// <summary> /// 系统启动后,先回复设备运行状态 /// </summary> /// <param name="errStr"></param> /// <returns></returns> public virtual bool DevStatusRestore() { bool readDB1OK = false; //for (int i = 0; i < 5; i++) { if (!ReadDB1()) { Console.WriteLine(string.Format("恢复设备状态失败,读DB1区数据失败,{0}", this.nodeName)); logRecorder.AddDebugLog(nodeName, string.Format("恢复设备状态失败,读DB1区数据失败,{0}", this.nodeName)); //return false; } else { readDB1OK = true; // break; } } if (!readDB1OK) { devStatusRestore = false; this.currentTaskDescribe = "恢复下电前状态失败,该设备将禁用,请尝试重启软件!"; return(false); } devStatusRestore = true; string strWhere = string.Format("(TaskStatus='执行中' or TaskStatus='超时') and DeviceID='{0}' order by CreateTime ", this.nodeID); this.currentTask = ctlTaskBll.GetFirstRequiredTask(strWhere); if (this.currentTask != null) { if (this.nodeID == "6001" || this.nodeID == "6002" || this.nodeID == "6003") { if (this.currentTask.TaskPhase != 3) { this.currentTaskPhase = 0; if (this.currentTask.TaskPhase == 4) { this.currentTaskPhase = this.currentTask.TaskPhase; } } else { this.currentTaskPhase = this.currentTask.TaskPhase; } } else if (this.nodeID == "6004" || this.nodeID == "6005" || this.nodeID == "6006" || this.nodeID == "6007") { this.currentTaskPhase = 0; } else { this.currentTaskPhase = this.currentTask.TaskPhase; } this.rfidUID = this.currentTask.TaskParam; } return(true); }
/// <summary> /// 给安排任务 /// </summary> /// <param name="task"></param> /// <param name="reStr"></param> /// <returns></returns> public bool FillTask(ControlTaskModel task, ref string reStr) { if (this.currentTask != null) { reStr = "当前任务未执行完,不能接受新的任务"; return(false); } this.currentTask = task; return(true); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ControlTaskModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ControlTask("); strSql.Append("TaskID,TaskType,TaskParam,TaskStatus,TaskPhase,CreateTime,FinishTime,CreateMode,Remark,DeviceID,tag1,tag2,tag3,tag4,tag5)"); strSql.Append(" values ("); strSql.Append("@TaskID,@TaskType,@TaskParam,@TaskStatus,@TaskPhase,@CreateTime,@FinishTime,@CreateMode,@Remark,@DeviceID,@tag1,@tag2,@tag3,@tag4,@tag5)"); SqlParameter[] parameters = { new SqlParameter("@TaskID", SqlDbType.NVarChar, 255), new SqlParameter("@TaskType", SqlDbType.Int, 4), new SqlParameter("@TaskParam", SqlDbType.NVarChar, 255), new SqlParameter("@TaskStatus", SqlDbType.NVarChar, 50), new SqlParameter("@TaskPhase", SqlDbType.Int, 4), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@FinishTime", SqlDbType.DateTime), new SqlParameter("@CreateMode", SqlDbType.NVarChar, 50), new SqlParameter("@Remark", SqlDbType.NVarChar, 50), new SqlParameter("@DeviceID", SqlDbType.NVarChar, 50), new SqlParameter("@tag1", SqlDbType.NVarChar, 255), new SqlParameter("@tag2", SqlDbType.NVarChar, 255), new SqlParameter("@tag3", SqlDbType.NVarChar, 255), new SqlParameter("@tag4", SqlDbType.NVarChar, 255), new SqlParameter("@tag5", SqlDbType.NVarChar, 255) }; parameters[0].Value = model.TaskID; parameters[1].Value = model.TaskType; parameters[2].Value = model.TaskParam; parameters[3].Value = model.TaskStatus; parameters[4].Value = model.TaskPhase; parameters[5].Value = model.CreateTime; parameters[6].Value = model.FinishTime; parameters[7].Value = model.CreateMode; parameters[8].Value = model.Remark; parameters[9].Value = model.DeviceID; parameters[10].Value = model.tag1; parameters[11].Value = model.tag2; parameters[12].Value = model.tag3; parameters[13].Value = model.tag4; parameters[14].Value = model.tag5; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 更新产品工艺状态信息,出库时更新 /// </summary> /// <param name="containerID"></param> /// <summary> /// 系统启动后,先回复设备运行状态 /// </summary> /// <param name="errStr"></param> /// <returns></returns> public virtual bool DevStatusRestore() { if (!this.nodeEnabled) { return(false); } bool readDB1OK = false; //for (int i = 0; i < 5; i++) { if (!ReadDB1()) { Console.WriteLine(string.Format("恢复设备状态失败,读DB1区数据失败,{0}", this.nodeName)); if (logRecorder != null) { logRecorder.AddDebugLog(nodeName, string.Format("恢复设备状态失败,读DB1区数据失败,{0}", this.nodeName)); } //return false; } else { readDB1OK = true; // break; } } if (!readDB1OK) { devStatusRestore = false; this.currentTaskDescribe = "恢复下电前状态失败,该设备将禁用,请尝试重启软件!"; return(false); } string reStr = ""; if (!ReadDB2(ref reStr)) { devStatusRestore = false; this.currentTaskDescribe = "恢复下电前状态失败,该设备将禁用,请尝试重启软件!"; return(false); } Array.Copy(db2Vals, db2ValsLast, db2Vals.Count()); devStatusRestore = true; string strWhere = string.Format("(TaskStatus='执行中' or TaskStatus='超时') and DeviceID='{0}' order by CreateTime ", this.nodeID); this.currentTask = ctlTaskBll.GetFirstRequiredTask(strWhere); if (this.currentTask != null) { this.currentTaskPhase = this.currentTask.TaskPhase; this.rfidUID = this.currentTask.TaskParam; } return(true); }
public bool ModifyTaskPri(string taskID, int pri, ref string reStr) { ControlTaskModel taskM = taskBll.GetModel(taskID); if (taskM == null) { reStr = "不存在的任务ID:" + taskID; return(false); } taskM.tag4 = pri.ToString(); return(taskBll.Update(taskM)); }
protected override bool NodeStatParse(ref string reStr) { if (db2Vals[1] == 0) //对于审核工位,判断有板信号是否复位,决定流程是否复位 { if (currentTaskPhase != 0) { if (!ctlTaskBll.ClearTask(string.Format("DeviceID='{0}'", this.nodeID))) { logRecorder.AddDebugLog(nodeName, "清理任务失败"); return(false); } this.currentTask = null; DevCmdReset(); this.currentStat.Status = EnumNodeStatus.设备空闲; this.currentStat.ProductBarcode = ""; this.currentStat.StatDescribe = "设备空闲"; checkFinished = false; currentTaskDescribe = "等待有板信号"; } currentTaskPhase = 0; //复位 rfidUID = string.Empty; checkEnable = true; } else if (db2Vals[1] == 1) //有板信号 { if (currentTaskPhase == 0) { ControlTaskModel task = new ControlTaskModel(); task.TaskID = System.Guid.NewGuid().ToString("N"); task.TaskParam = string.Empty; task.TaskPhase = 1; task.CreateTime = System.DateTime.Now; task.DeviceID = this.nodeID; task.CreateMode = "自动"; task.TaskStatus = EnumTaskStatus.执行中.ToString(); ctlTaskBll.Add(task); this.currentTask = task; currentTaskPhase = 1; //开始流程 checkEnable = true; } } else { ThrowErrorStat("PLC错误的状态数据", EnumNodeStatus.设备故障); return(true); } return(true); }
private void AutoCreateControlTask(ManageTaskModel manaTaskModel, long taskID, TaskTypeModel taskType) { ControlTaskModel controlTaskModel = new ControlTaskModel();//生成控制任务 controlTaskModel.ControlCode = manaTaskModel.TaskCode; controlTaskModel.TaskTypeName = taskType.TaskTypeName; controlTaskModel.StartArea = manaTaskModel.TaskStartArea; controlTaskModel.StartDevice = manaTaskModel.TaskStartPostion; controlTaskModel.TargetArea = manaTaskModel.TaskEndArea; controlTaskModel.TargetDevice = manaTaskModel.TaskEndPostion; controlTaskModel.TaskID = taskID; controlTaskModel.CreateMode = EnumCreateMode.手动生成.ToString(); controlTaskModel.TaskStatus = EnumTaskStatus.待执行.ToString(); controlTaskModel.TaskType = manaTaskModel.TaskType; controlTaskModel.TaskTypeCode = taskType.TaskTypeCode; controlTaskModel.CreateTime = DateTime.Now; bllControlTask.Add(controlTaskModel); }
//A1库出库任务委托 public CtlDBAccess.Model.ControlTaskModel GetCheckoutOfA1(AsrsControl.AsrsCtlModel asrsCtl, IAsrsManageToCtl asrsResManage, IList <CtlDBAccess.Model.ControlTaskModel> taskList, SysCfg.EnumAsrsTaskType taskType) { if (asrsCtl.HouseName != AsrsModel.EnumStoreHouse.A1库房.ToString()) { return(null); } if (taskList == null) { return(null); } NodeVirStation nodeStation = GetNodeByID("4001") as NodeVirStation; //AsrsModel.EnumLogicArea requireCheckoutArea = AsrsModel.EnumLogicArea.一次高温A区; List <AsrsModel.EnumLogicArea> areaList = new List <AsrsModel.EnumLogicArea>(); if (nodeStation.Db2Vals[2] == 1) { //requireCheckoutArea = AsrsModel.EnumLogicArea.一次高温A区; areaList.Add(AsrsModel.EnumLogicArea.一次高温A区); areaList.Add(AsrsModel.EnumLogicArea.一次高温B区); } else if (nodeStation.Db2Vals[2] == 2) { areaList.Add(AsrsModel.EnumLogicArea.一次高温B区); areaList.Add(AsrsModel.EnumLogicArea.一次高温A区); } else { return(null); } string houseName = asrsCtl.HouseName; ControlTaskModel task = null; foreach (AsrsModel.EnumLogicArea requireCheckoutArea in areaList) { task = GetCheckoutOfArea(asrsCtl, asrsResManage, taskType, taskList, requireCheckoutArea); if (task != null) { break; } } return(task); }
private bool WriteTaskParam(ControlTaskModel ctlTask) { if (taskParamModel == null) { return(false); } //1 任务类型码 this.db1ValsToSnd[2] = (short)this.currentTask.TaskType; this.db1ValsToSnd[3] = (short)taskParamModel.InputPort; this.db1ValsToSnd[4] = (short)taskParamModel.OutputPort; this.db1ValsToSnd[5] = (short)taskParamModel.CellPos1.Row; this.db1ValsToSnd[6] = (short)taskParamModel.CellPos1.Col; this.db1ValsToSnd[7] = (short)taskParamModel.CellPos1.Layer; if (ctlTask.TaskType == (int)SysCfg.EnumAsrsTaskType.移库) { this.db1ValsToSnd[8] = (short)taskParamModel.CellPos2.Row; this.db1ValsToSnd[9] = (short)taskParamModel.CellPos2.Col; this.db1ValsToSnd[10] = (short)taskParamModel.CellPos2.Layer; } for (int i = 0; i < Math.Min(7, taskParamModel.ReserveParams.Count); i++) { this.db1ValsToSnd[12 + i] = taskParamModel.ReserveParams[i]; } if (ctlTask.tag5 == "1") { this.db1ValsToSnd[12] = 1; //紧急出库 } //if (ctlTask.TaskType == (int)SysCfg.EnumAsrsTaskType.产品出库) //{ // for(int i=0;i<Math.Min(7,taskParamModel.ReserveParams.Count);i++) // { // this.db1ValsToSnd[12 + i] = taskParamModel.ReserveParams[i]; // } //} return(true); }
private CtlDBAccess.Model.ControlTaskModel GetCheckoutOfArea(AsrsControl.AsrsCtlModel asrsCtl, IAsrsManageToCtl asrsResManage, SysCfg.EnumAsrsTaskType taskType, IList <CtlDBAccess.Model.ControlTaskModel> taskList, AsrsModel.EnumLogicArea checkOutArea) { string houseName = asrsCtl.HouseName; ControlTaskModel task = null; if (taskList == null) { return(null); } foreach (ControlTaskModel t in taskList) { string reStr = ""; AsrsTaskParamModel paramModel = new AsrsTaskParamModel(); if (!paramModel.ParseParam(taskType, t.TaskParam, ref reStr)) { continue; } AsrsModel.EnumGSEnabledStatus cellEnabledStatus = AsrsModel.EnumGSEnabledStatus.启用; if (!asrsResManage.GetCellEnabledStatus(houseName, paramModel.CellPos1, ref cellEnabledStatus)) { // reStr = "获取货位启用状态失败"; continue; } if (cellEnabledStatus == AsrsModel.EnumGSEnabledStatus.禁用) { continue; } AsrsModel.EnumLogicArea curLogicArea = AsrsModel.EnumLogicArea.一次高温A区; if (!asrsResManage.GetLogicAreaName(houseName, paramModel.CellPos1, ref curLogicArea)) { continue; } if (curLogicArea == checkOutArea) { task = t; break; } } return(task); }
/// <summary> /// 清理当前正在运行的任务 /// </summary> /// <returns></returns> public bool ClearRunningTask() { //if (devModel.DeviceType == EnumDevType.机械手.ToString()) //{ // if (this.currentTask != null) // { // if (this.ctlTaskBll.Exists(this.currentTask.ControlTaskID)) // { // this.currentTask.TaskStatus = EnumTaskStatus.已完成.ToString(); // if (!ctlTaskBll.Update(this.currentTask)) // { // AddLog(devName + "更新任务状态失败,TaskID:" + this.currentTask.TaskID, EnumLogType.错误); // return false; // } // } // } //} this.currentTask = null; this.currentTaskPhase = 0; return(true); }
/// <summary> /// 得到一个对象实体 /// </summary> public ControlTaskModel GetModel(string TaskID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 TaskID,TaskType,TaskParam,TaskStatus,TaskPhase,CreateTime,FinishTime,CreateMode,Remark,DeviceID,tag1,tag2,tag3,tag4,tag5 from ControlTask "); strSql.Append(" where TaskID=@TaskID "); SqlParameter[] parameters = { new SqlParameter("@TaskID", SqlDbType.NVarChar, 255) }; parameters[0].Value = TaskID; ControlTaskModel model = new ControlTaskModel(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void ModifyRow() { if (comboBoxDtName.Text == "控制任务表") { DataGridViewSelectedRowCollection rws = this.dataGridViewDt.SelectedRows; if (rws != null && rws.Count > 0) { foreach (DataGridViewRow rw in rws) { if (rw != null) { int id = int.Parse(rw.Cells["ControlID"].Value.ToString()); ControlTaskModel taskModel = ctlTaskBll.GetModel(id); if (taskModel == null) { continue; } taskModel.TaskPhase = rw.Cells["TaskPhase"].Value.ToString(); taskModel.TaskStatus = rw.Cells["TaskStatus"].Value.ToString(); } } } } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ControlTaskModel model) { return(dal.Add(model)); }
/// <summary> /// 分析工位状态 /// </summary> /// <param name="reStr"></param> /// <returns></returns> protected override bool NodeStatParse(ref string reStr) { if (db2Vals[0] == 0) { if (productChecked) { logRecorder.AddDebugLog(nodeName, "产品离开工位"); } productChecked = false; //查询未执行完任务,清掉 if (!ctlTaskBll.ClearTask(string.Format("DeviceID='{0}'", this.nodeID))) { logRecorder.AddDebugLog(nodeName, "清理任务失败"); return(false); } this.currentTask = null; //if (currentTaskPhase != 0) //{ // //查询未执行完任务,清掉 // if (!ctlTaskBll.ClearTask(string.Format("DeviceID='{0}'", this.nodeID))) // { // logRecorder.AddDebugLog(nodeName, "清理任务失败"); // return false; // } // this.currentTask = null; //} //if(this.currentTask == null) // { DevCmdReset(); this.currentStat.Status = EnumNodeStatus.设备空闲; this.currentStat.ProductBarcode = ""; this.currentStat.StatDescribe = "设备空闲"; checkFinished = false; currentTaskDescribe = "等待有板信号"; currentTaskPhase = 0; //复位 checkEnable = true; //} } else if (db2Vals[0] == 1) { if (!productChecked) { logRecorder.AddDebugLog(nodeName, "检测到有产品"); } productChecked = true; if (currentTaskPhase == 0) { //生成新任务 ControlTaskModel task = new ControlTaskModel(); task.TaskID = System.Guid.NewGuid().ToString("N"); task.TaskParam = string.Empty; task.TaskPhase = 1; task.CreateTime = System.DateTime.Now; task.DeviceID = this.nodeID; task.CreateMode = "自动"; task.TaskStatus = EnumTaskStatus.执行中.ToString(); ctlTaskBll.Add(task); this.currentTask = task; currentTaskPhase = 1; //开始流程 checkEnable = true; } } else { ThrowErrorStat("PLC错误的状态数据", EnumNodeStatus.设备故障); return(true); } return(true); }
/// <summary> /// 分拣任务申请 /// </summary> private bool GraspTaskRequire(ref string reStr) { //if (db2Vals[0] == 1) //{ // currentTaskPhase = 0; // db1ValsToSnd[0] = 1; // rfidUID = string.Empty; // currentTaskDescribe = "等待新的任务"; // return; //} if (db2Vals[0] == 2 && db1ValsToSnd[1] != 2) { if (this.currentTask != null) { return(true); } //if (ExistUnCompletedTask((int)SysCfg.EnumAsrsTaskType.OCV测试分拣)) //{ // return true; //} //先读RFID卡 currentTaskDescribe = "开始读RFID"; this.rfidUID = ""; if (SysCfg.SysCfgModel.SimMode || SysCfg.SysCfgModel.RfidSimMode) { this.rfidUID = this.SimRfidUID; } else { if (this.barcodeRW != null) { this.rfidUID = this.barcodeRW.ReadBarcode(); } else { this.rfidUID = rfidRW.ReadStrData();// rfidRW.ReadUID(); } } if (string.IsNullOrWhiteSpace(this.rfidUID)) { if (this.db1ValsToSnd[0] != 3) { logRecorder.AddDebugLog(nodeName, "读RFID失败"); this.currentTaskDescribe = "读RFID失败"; } this.db1ValsToSnd[0] = 3; return(true); } this.rfidUID = this.rfidUID.Trim(new char[] { '\0', '\r', '\n', '\t', ' ' }); string palletPatten = @"^[a-z|A-Z|0-9]{4}TP[0-9]{4,}"; if (!System.Text.RegularExpressions.Regex.IsMatch(this.rfidUID, palletPatten)) { if (this.db1ValsToSnd[1] != 3) { logRecorder.AddDebugLog(nodeName, "读料框ID错误,含有非法字符 !" + this.rfidUID); } this.db1ValsToSnd[1] = 3; return(true); } //if (this.rfidUID.Length < 9) //{ // if (this.db1ValsToSnd[0] != 3) // { // logRecorder.AddDebugLog(nodeName, "读料框RFID错误,长度不足9字符!"); // } // this.db1ValsToSnd[0] = 3; // return true; //} //if (this.rfidUID.Length > 9) //{ // this.rfidUID = this.rfidUID.Substring(0, 9); //} if (db1ValsToSnd[0] == 1 || db1ValsToSnd[0] == 3) { logRecorder.AddDebugLog(this.nodeName, "读到托盘号:" + this.rfidUID); this.currentTaskDescribe = "读到托盘号:" + this.rfidUID; } if (this.nodeID == "6002") //ocv1分拣处判断步号,如果大于10,报错 { int step = 0; if (!MesAcc.GetStep(this.rfidUID, out step, ref reStr)) { currentTaskDescribe = "查询MES工步失败:" + reStr; return(false); } if (step > 10) { if (db1ValsToSnd[0] != 5) { logRecorder.AddDebugLog(nodeName, string.Format("{0}步号错误,当前步号:{1},当前工位不能超过10,请检查是否使用了OCV2测试后的料筐", rfidUID, step)); } this.currentTaskDescribe = string.Format("{0}步号错误,当前步号:{1},当前工位不能超过10,请检查是否使用了OCV2测试后的料筐", rfidUID, step); db1ValsToSnd[0] = 5; reStr = this.currentTaskDescribe; return(false); } } /* * List<MesDBAccess.Model.ProductOnlineModel> bindedProducts = productOnlineBll.GetProductsInPallet(this.rfidUID); * if(bindedProducts == null || bindedProducts.Count()<1) * { * this.db1ValsToSnd[0] = 4; * this.currentTaskDescribe = string.Format("{0}无绑定数据",this.rfidUID); * return true; * }*/ //生成新任务 this.currentTaskPhase = 1; ControlTaskModel task = new ControlTaskModel(); task.DeviceID = this.nodeID; task.CreateMode = "自动"; task.CreateTime = System.DateTime.Now; task.TaskID = System.Guid.NewGuid().ToString("N"); task.TaskStatus = SysCfg.EnumTaskStatus.待执行.ToString(); task.TaskType = (int)SysCfg.EnumAsrsTaskType.分拣; task.TaskParam = this.rfidUID; task.TaskPhase = this.currentTaskPhase; task.TaskStatus = SysCfg.EnumTaskStatus.执行中.ToString(); this.ctlTaskBll.Add(task); this.currentTask = task; currentTaskDescribe = "分拣任务生成"; return(true); } if (db2Vals[0] == 1 && this.currentTask == null) { this.db1ValsToSnd[0] = 1; } return(true); }
private bool ExeBind(ref string reStr) { if (!devStatusRestore) { devStatusRestore = DevStatusRestore(); } if (!devStatusRestore) { return(false); } if (this.rfidRWList != null && this.rfidRWList.Count() > 0) { this.rfidRW = this.rfidRWList[0]; //临时 } if (db2Vals[1] == 1) { if (this.currentTask != null) { //查询未执行完任务,清掉 if (!ctlTaskBll.ClearTask(string.Format("DeviceID='{0}'", this.nodeID))) { logRecorder.AddDebugLog(nodeName, "清理任务失败"); return(false); } this.currentTask = null; this.currentStat.Status = EnumNodeStatus.设备空闲; this.currentStat.ProductBarcode = ""; this.currentStat.StatDescribe = "设备空闲"; checkFinished = false; currentTaskDescribe = "等待有板信号"; } currentTaskPhase = 0; db1ValsToSnd[3] = 1; db1ValsToSnd[4] = 1; this.rfidUID = string.Empty; //if (!SysCfgModel.SimMode) //{ // (this.rfidRW as DevAccess.RfidCF).ClearBufUID(); //} this.currentStat.Status = EnumNodeStatus.设备空闲; this.currentStat.StatDescribe = "工位空闲"; currentTaskDescribe = ""; return(true); } if (db2Vals[1] == 2) { if (currentTaskPhase == 0) { db1ValsToSnd[3] = 1; db1ValsToSnd[4] = 1; currentTaskPhase = 1; this.currentStat.Status = EnumNodeStatus.设备使用中; this.currentStat.StatDescribe = "工作中"; ControlTaskModel task = new ControlTaskModel(); task.TaskID = System.Guid.NewGuid().ToString("N"); task.TaskParam = string.Empty; task.TaskPhase = 1; task.CreateTime = System.DateTime.Now; task.DeviceID = this.nodeID; task.CreateMode = "自动"; task.TaskStatus = EnumTaskStatus.执行中.ToString(); ctlTaskBll.Add(task); this.currentTask = task; } } //int bindCount = modPalletMax; //this.db1ValsToSnd[2] = (short)modPalletMax; //this.db1ValsToSnd[2] = (short)bindCount; switch (currentTaskPhase) { case 1: { currentTaskDescribe = "开始读RFID"; if (!RfidReadC()) { break; } if (SysCfgModel.SimMode == false) { if (ModuleCodeRequire(ref this.mesReqGroupCode, ref reStr) == false) { Console.WriteLine(this.nodeName + "请求模组二维码失败!" + reStr); break; } else { this.logRecorder.AddDebugLog(this.nodeName, "请求模组二维码成功!" + this.mesReqGroupCode); this.TxtLogRecorder.WriteLog("请求模组二维码成功!" + this.mesReqGroupCode); } //bindCount = 2;//现场条码不正确 //mesReqGroupCode = "123456789202345678988043"; } else { //bindCountGlobal = 4; mesReqGroupCode = "04GPE3VB150E118530000002"; } currentTaskPhase++; this.currentTask.TaskPhase = this.currentTaskPhase; this.ctlTaskBll.Update(this.currentTask); break; } case 2: { //int bindCount = 0; if (this.swithBarcode == "") { currentTaskDescribe = "模块二位码没有扫码!"; break; } currentTaskDescribe = "计算工装板绑定模块数量!"; if (SysCfgModel.SimMode == false) { if (CalcuBindCount(mesReqGroupCode, this.swithBarcode, ref this.bindCountGlobal, ref reStr) == false) { currentTaskDescribe = "带绑定模块数量计算错误!" + reStr; return(false); } } else { bindCountGlobal = 2; } this.swithBarcode = ""; this.db1ValsToSnd[2] = (short)bindCountGlobal; //this.db1ValsToSnd[2] = (short)modPalletMax;//测试版本 this.plcRW2.WriteDB("D8500", (short)bindCountGlobal); currentTaskPhase++; this.currentTask.TaskParam = rfidUID; this.currentTask.TaskPhase = this.currentTaskPhase; this.ctlTaskBll.Update(this.currentTask); logRecorder.AddDebugLog(nodeName, string.Format("读到RFID:{0},开始绑定", this.rfidUID)); this.TxtLogRecorder.WriteLog(string.Format("读到RFID:{0},开始绑定", this.rfidUID)); break; } case 3: { #region 原来绑定流程 //short groupSeq = this.db2Vals[3]; //plNodeModel = plNodeBll.GetModel(nodeID); //List<string> mods = new List<string>(); //switch (groupSeq) //{ // case 1: // { // string[] strArray = plNodeModel.tag1.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); // if (strArray != null && strArray.Count() > 0) // { // mods.AddRange(strArray); // } // break; // } // case 2: // { // string[] strArray = plNodeModel.tag2.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); // if (strArray != null && strArray.Count() > 0) // { // mods.AddRange(strArray); // } // break; // } // case 3: // { // string[] strArray = plNodeModel.tag3.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); // if (strArray != null && strArray.Count() > 0) // { // mods.AddRange(strArray); // } // break; // } // case 4: // { // string[] strArray = plNodeModel.tag4.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); // if (strArray != null && strArray.Count() > 0) // { // mods.AddRange(strArray); // } // break; // } // default: // break; //} #endregion currentTaskDescribe = "扫码中,计划扫码个数:" + bindCountGlobal + ",当前扫码计数:第" + this.qrList.Count() + "个!"; int rqRequire = 0; if (this.plcRW2.ReadDB("D3004", ref rqRequire) == false) //有第二个扫码请求 { break; } NodeDB2Commit(4, (short)rqRequire, ref reStr); if (rqRequire != 1) //有第二个扫码请求 { break; } //扫码请求 string barcode = ""; if (SysCfgModel.SimMode) { barcode = this.SimBarcode; } else { barcode = barcodeRW2.ReadBarcode(); } if (string.IsNullOrWhiteSpace(barcode) == true) { this.readCodeTimes++; if (this.readCodeTimes > 4) { if (this.plcRW2.WriteDB("D3004", 3) == false) { break; } NodeDB2Commit(4, 3, ref reStr); this.readCodeTimes = 0; } break; } if (this.plcRW2.WriteDB("D3004", 2) == false) { break; } NodeDB2Commit(4, 2, ref reStr); this.qrList.Add(barcode); if (this.qrList.Count != bindCountGlobal) { break; } if (this.qrList.Count() < 1) { this.db1ValsToSnd[4] = 3; //this.currentTaskDescribe = string.Format("分档位:{0} 可供绑定的模块为空,", groupSeq); break; } this.currentTaskPhase++; this.currentTask.TaskPhase = this.currentTaskPhase; this.ctlTaskBll.Update(this.currentTask); break; } case 4: { currentTaskDescribe = "绑定中!"; //绑定 //TryUnbind(this.rfidUID, ref reStr); AddPack(this.mesReqGroupCode, ref reStr); for (int i = 0; i < Math.Min(this.qrList.Count(), modPalletMax); i++) { string modID = this.qrList[i]; DBAccess.Model.BatteryModuleModel mod = modBll.GetModel(modID); if (mod == null) { mod = new DBAccess.Model.BatteryModuleModel(); mod.batModuleID = modID; mod.palletID = this.rfidUID; mod.palletBinded = true; mod.checkResult = 1; mod.batPackID = this.mesReqGroupCode; mod.curProcessStage = nodeName; mod.asmTime = System.DateTime.Now; mod.tag1 = this.db2Vals[3].ToString(); modBll.Add(mod); } else { mod.checkResult = 1; mod.palletBinded = true; mod.palletID = this.rfidUID; mod.curProcessStage = nodeName; mod.batPackID = this.mesReqGroupCode; modBll.Update(mod); } this.currentTaskDescribe = string.Format("绑定,RFID:{0},模块条码:{1}", rfidUID, modID); logRecorder.AddDebugLog(nodeName, string.Format("绑定,RFID:{0},模块条码:{1}", rfidUID, modID)); AddProcessRecord(mod.batModuleID, "模块", "追溯记录", string.Format("绑定,RFID:{0},模块条码:{1}", rfidUID, modID), ""); //AddProcessRecord(mod.batModuleID, this.nodeName, ""); } int removeSum = Math.Min(this.qrList.Count(), modPalletMax); this.qrList.RemoveRange(0, removeSum); //string strMods = ""; //for (int i = 0; i < this.qrList.Count(); i++) //{ // strMods += (this.qrList[i] + ","); //} //switch (groupSeq) //{ // case 1: // { // plNodeModel.tag1 = strMods; // break; // } // case 2: // { // plNodeModel.tag2 = strMods; // break; // } // case 3: // { // plNodeModel.tag3 = strMods; // break; // } // case 4: // { // plNodeModel.tag4 = strMods; // break; // } // default: // break; //} //plNodeBll.Update(plNodeModel); if (this.db2Vals[2] != 2) { break; } if (this.db2Vals[3] < 1 || this.db2Vals[3] > 4) { break; } currentTaskPhase++; this.currentTask.TaskPhase = this.currentTaskPhase; this.ctlTaskBll.Update(this.currentTask); this.TxtLogRecorder.WriteLog("工装板数据绑定完成!"); currentTaskDescribe = "绑定完成!"; break; } case 5: { #region MES绑定数据 currentTaskDescribe = "开始上传MES绑定数据!"; string restr = ""; int uploadStatus = UploadDataToMes(2, "M00100101", this.rfidUID, ref restr); if (uploadStatus == 0) //OK { this.logRecorder.AddDebugLog(this.nodeName, "上传MES数据成功:" + restr); } else if (uploadStatus == 1) //NG { this.logRecorder.AddDebugLog(this.nodeName, "上传MES数据成功,返回NG:" + restr); } else { this.logRecorder.AddDebugLog(this.nodeName, "上传MES数据失败:" + restr); //需要重复上传 break; } this.TxtLogRecorder.WriteLog("上传MES数据:工装板号" + this.rfidUID); #endregion currentTaskPhase++; this.db1ValsToSnd[4] = 2; this.currentTask.TaskPhase = this.currentTaskPhase; this.ctlTaskBll.Update(this.currentTask); this.plNodeModel.tag1 = ""; this.plNodeModel.tag2 = ""; this.plNodeModel.tag3 = ""; this.plNodeModel.tag4 = ""; this.plNodeBll.Update(this.plNodeModel); break; } case 6: { currentTaskDescribe = "流程完成"; this.db1ValsToSnd[2] = 0; this.mesReqGroupCode = ""; this.currentTask.TaskPhase = this.currentTaskPhase; this.currentTask.TaskStatus = EnumTaskStatus.已完成.ToString(); this.ctlTaskBll.Update(this.currentTask); this.TxtLogRecorder.WriteLog("工位流程处理完成!"); break; } default: break; } return(true); }
/// <summary> /// 装载任务申请 /// </summary> private bool FillTaskRequire(ref string reStr) { //if (db2Vals[0] == 1) //{ // currentTaskPhase = 0; // db1ValsToSnd[0] = 1; // rfidUID = string.Empty; // currentTaskDescribe = "等待新的任务"; // return; //} if (db2Vals[0] == 2 && db1ValsToSnd[0] != 2) { if (ExistUnCompletedTask((int)SysCfg.EnumAsrsTaskType.托盘装载)) { return(true); } //先读RFID卡 currentTaskDescribe = "开始读RFID"; this.rfidUID = ""; if (SysCfg.SysCfgModel.SimMode || SysCfg.SysCfgModel.RfidSimMode) { this.rfidUID = this.SimRfidUID; } else { if (this.barcodeRW != null) { this.rfidUID = this.barcodeRW.ReadBarcode(); } else { this.rfidUID = rfidRW.ReadStrData();// rfidRW.ReadUID(); } } if (string.IsNullOrWhiteSpace(this.rfidUID)) { if (this.db1ValsToSnd[1] != 3) { logRecorder.AddDebugLog(nodeName, "读RFID失败"); } this.db1ValsToSnd[1] = 3; return(true); } this.rfidUID = this.rfidUID.Trim(new char[] { '\0', '\r', '\n', '\t', ' ' }); string pattern = @"^[a-zA-Z0-9]*$"; //匹配所有字符都在字母和数字之间 if (!System.Text.RegularExpressions.Regex.IsMatch(this.rfidUID, pattern)) { if (this.db1ValsToSnd[1] != 3) { logRecorder.AddDebugLog(nodeName, "读料框RFID错误,含有非法字符 !" + this.rfidUID); } this.db1ValsToSnd[1] = 3; return(true); } if (this.rfidUID.Length < 9) { if (this.db1ValsToSnd[1] != 3) { logRecorder.AddDebugLog(nodeName, "读料框ID错误,长度不足9字符!"); } this.db1ValsToSnd[1] = 3; return(true); } string palletCata = "1"; if (this.nodeID == "3002") { palletCata = "2"; } if (this.rfidUID.Substring(2, 1) != palletCata) { if (this.db1ValsToSnd[1] != 3) { logRecorder.AddDebugLog(nodeName, string.Format("料框错误,应该为TP{0}XXXXXX,实际为{1}", palletCata, this.rfidUID)); this.currentTaskDescribe = string.Format("料框错误,应该为TP{0}XXXXXX,实际为{1}", palletCata, this.rfidUID); } this.db1ValsToSnd[1] = 3; return(true); } if (this.rfidUID.Length > 9) { //this.rfidUID = this.rfidUID.Substring(this.rfidUID.Length - 9, 9); this.rfidUID = this.rfidUID.Substring(0, 9); } logRecorder.AddDebugLog(this.nodeName, "读到托盘号:" + this.rfidUID); //解绑 currentTaskDescribe = "开始解绑"; if (!productOnlineBll.UnbindPallet(this.rfidUID, ref reStr)) { logRecorder.AddDebugLog(nodeName, reStr); return(false); } //生成新任务 this.currentTaskPhase = 1; ControlTaskModel task = new ControlTaskModel(); task.DeviceID = this.nodeID; task.CreateMode = "自动"; task.CreateTime = System.DateTime.Now; task.TaskID = System.Guid.NewGuid().ToString("N"); task.TaskStatus = SysCfg.EnumTaskStatus.待执行.ToString(); task.TaskType = (int)SysCfg.EnumAsrsTaskType.托盘装载; task.TaskParam = this.rfidUID; task.TaskPhase = this.currentTaskPhase; task.TaskStatus = SysCfg.EnumTaskStatus.执行中.ToString(); this.ctlTaskBll.Add(task); this.currentTask = task; currentTaskDescribe = "装载任务生成"; return(true); } if (db2Vals[0] == 1 && this.currentTask == null) { this.db1ValsToSnd[1] = 1; } return(true); }
private void buttonGenerateTask_Click(object sender, EventArgs e) { string taskName = this.comboBoxTaskType.Text; ControlTaskModel task = new ControlTaskModel(); task.TaskID = long.Parse(this.textBoxTaskManID.Text); //task.StartDevice = devID; task.TaskTypeName = taskName; task.ControlCode = ctlTaskIFBll.GetNewTaskCode();//.textBoxControlCode.Text; task.CreateTime = System.DateTime.Now; task.TaskStatus = EnumTaskStatus.待执行.ToString(); task.CreateMode = EnumTaskMode.手动.ToString(); task.TaskParameter = this.textBoxTaskParam.Text; task.TaskPhase = "0"; if (taskName == EnumTaskName.电芯入库_A1.ToString()) { task.StartArea = "装箱区"; task.TargetArea = "老化区A1"; task.StartDevice = "2002"; task.TargetDevice = this.textBoxTaskParam.Text; task.TaskType = "入库"; task.TaskTypeCode = 3; } else if (taskName == EnumTaskName.电芯出库_A1.ToString()) { task.StartArea = this.textBoxTaskParam.Text; task.TargetArea = "一次检测区"; task.StartDevice = "老化区A1"; task.TargetDevice = "2005"; task.TaskType = "出库"; task.TaskTypeCode = 6; } else if (taskName == EnumTaskName.分容入库_A1.ToString()) { task.StartArea = "装箱区"; task.TargetArea = "老化区"; task.StartDevice = "2004"; task.TargetDevice = this.textBoxTaskParam.Text; task.TaskType = "入库"; task.TaskTypeCode = 5; } else if (taskName == EnumTaskName.分容出库_A1.ToString()) { task.StartArea = "老化区A1"; task.TargetArea = "老化区"; task.StartDevice = this.textBoxTaskParam.Text; task.TargetDevice = "2003"; task.TaskType = "出库"; task.TaskTypeCode = 4; } else if (taskName == EnumTaskName.电芯入库_B1.ToString()) { task.StartArea = "装箱区"; task.TargetArea = "老化区"; task.StartDevice = "2006"; task.TargetDevice = this.textBoxTaskParam.Text; task.TaskType = "入库"; task.TaskTypeCode = 8; } else if (taskName == EnumTaskName.电芯出库_B1.ToString()) { task.StartArea = "老化区A1"; task.TargetArea = "老化区"; task.StartDevice = this.textBoxTaskParam.Text; task.TargetDevice = "2007"; task.TaskType = "出库"; task.TaskTypeCode = 9; } else if (taskName == EnumTaskName.空料框入库.ToString()) { task.StartArea = "老化区A1"; task.TargetArea = "老化区"; task.StartDevice = "2008"; task.TargetDevice = this.textBoxTaskParam.Text; task.TaskType = "入库"; task.TaskTypeCode = 1; } else if (taskName == EnumTaskName.空料框出库.ToString()) { task.StartArea = "老化区A1"; task.TargetArea = "老化区"; task.StartDevice = this.textBoxTaskParam.Text; task.TargetDevice = "2009"; task.TaskType = "出库"; task.TaskTypeCode = 2; } else if (taskName == EnumTaskName.电芯装箱组盘.ToString()) { task.StartArea = "老化区A1"; task.TargetArea = "老化区"; task.StartDevice = "5001"; task.TargetDevice = "2001"; task.TaskType = "入库"; task.TaskTypeCode = 11; } else if (taskName == EnumTaskName.电芯一次拣选.ToString()) { task.StartArea = "老化区A1"; task.TargetArea = "老化区"; task.StartDevice = "4001"; task.TargetDevice = "5002"; task.TaskType = "出库"; task.TaskTypeCode = 7; } else if (taskName == EnumTaskName.电芯二次拣选.ToString()) { task.StartArea = "老化区A1"; task.TargetArea = "老化区"; task.StartDevice = "4002"; task.TargetDevice = "5003"; task.TaskType = "出库"; task.TaskTypeCode = 7; } try { ctlTaskBll.Add(task); AddLog("增加一条控制任务:" + taskName); } catch (System.Exception ex) { AddLog("出现异常:" + ex.Message); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ControlTaskModel model) { return(dal.Update(model)); }
/// <summary> ///DCR出库和产品出库 /// </summary> /// <param name="xweModel"></param> /// <param name="testType"></param> /// <returns></returns> private bool AutoOutHouseGsTask(XWEDBAccess.Model.GoodsSiteModel xweModel, SysCfg.EnumTestType testType) { string[] rcl = xweModel.GoodsSiteName.Split('-'); CellCoordModel cell = new CellCoordModel(int.Parse(rcl[0]), int.Parse(rcl[1]), int.Parse(rcl[2])); CellCoordModel cell2 = null; // 上传MES Start Report2Mes(xweModel); // 上传MES END if (testType == SysCfg.EnumTestType.充放电测试) { ControlTaskModel dcrWaitOrRunningTask = null; if (this.AsrsModel.HouseName == EnumStoreHouse.A1库房.ToString()) { dcrWaitOrRunningTask = bllControlTask.GetProcessWaitOrRunningTask(EnumStoreHouse.A1库房.ToString(), 4, "1001"); cell2 = AHouseDCRStation;//特殊固定的位置 } else//b1库房 { dcrWaitOrRunningTask = bllControlTask.GetProcessWaitOrRunningTask(EnumStoreHouse.B1库房.ToString(), 4, "1002"); cell2 = BHouseDCRStation; //特殊固定的位置 } if (dcrWaitOrRunningTask != null) //如果已经有dcr执行中或者待执行的任务就不在生成了,同一个工位的锁定 { return(false); } //在生成dcr测试的时候要判断下DCR测试工位是否有料,在新威尔交互的数据表中记录dcr工位的测试类型为无的时候证明已经测试完并出库完成 if (IsDCRStationValid(this.AsrsModel.HouseName) == false) { return(false); } if (this.AsrsModel.GenerateOutputTask(cell, cell2, SysCfg.EnumAsrsTaskType.DCR测试, true) == false) { this.AsrsModel.LogRecorder.AddDebugLog("库存控制模块", "生成DCR测试任务失败!"); return(false); } if (xweGsBll.UpdateGs(this.AsrsModel.HouseName, xweModel.GoodsSiteName, EnumOperateStatus.锁定.ToString()) == false)//将出库的货位锁定,根据锁定状态循环生成任务 { this.AsrsModel.LogRecorder.AddDebugLog("库存控制模块", "更新新威尔中间库的锁定状态失败!"); return(false); } // 将测试结果保存到数据库中 START AddXWEHistroy(xweModel); // 将测试结果保存到数据库中 END return(true); } else if (testType == SysCfg.EnumTestType.DCR测试)//正常出库 { ControlTaskModel dcrOutWaitOrRunningTask = null; if (this.AsrsModel.HouseName == EnumStoreHouse.A1库房.ToString()) { dcrOutWaitOrRunningTask = bllControlTask.GetProcessWaitOrRunningTask(EnumStoreHouse.A1库房.ToString(), 3, "1001"); } else//b1库房 { dcrOutWaitOrRunningTask = bllControlTask.GetProcessWaitOrRunningTask(EnumStoreHouse.B1库房.ToString(), 3, "1002"); } if (dcrOutWaitOrRunningTask != null)//如果已经有dcr执行中或者待执行的任务就不在生成了,同一个工位的锁定 { return(false); } if (this.AsrsModel.GenerateOutputTask(cell, null, SysCfg.EnumAsrsTaskType.DCR出库, true) == false) { this.AsrsModel.LogRecorder.AddDebugLog("库存控制模块", "生成DCR测试任务失败!"); return(false); } if (xweGsBll.UpdateGs(this.AsrsModel.HouseName, xweModel.GoodsSiteName, EnumOperateStatus.锁定.ToString()) == false)//将出库的货位锁定,根据锁定状态循环生成任务 { this.AsrsModel.LogRecorder.AddDebugLog("库存控制模块", "更新新威尔中间库的锁定状态失败!"); return(false); } return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ControlTaskModel DataRowToModel(DataRow row) { ControlTaskModel model = new ControlTaskModel(); if (row != null) { if (row["TaskID"] != null) { model.TaskID = row["TaskID"].ToString(); } if (row["TaskType"] != null && row["TaskType"].ToString() != "") { model.TaskType = int.Parse(row["TaskType"].ToString()); } if (row["TaskParam"] != null) { model.TaskParam = row["TaskParam"].ToString(); } if (row["TaskStatus"] != null) { model.TaskStatus = row["TaskStatus"].ToString(); } if (row["TaskPhase"] != null && row["TaskPhase"].ToString() != "") { model.TaskPhase = int.Parse(row["TaskPhase"].ToString()); } if (row["CreateTime"] != null && row["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(row["CreateTime"].ToString()); } if (row["FinishTime"] != null && row["FinishTime"].ToString() != "") { model.FinishTime = DateTime.Parse(row["FinishTime"].ToString()); } if (row["CreateMode"] != null) { model.CreateMode = row["CreateMode"].ToString(); } if (row["Remark"] != null) { model.Remark = row["Remark"].ToString(); } if (row["DeviceID"] != null) { model.DeviceID = row["DeviceID"].ToString(); } if (row["tag1"] != null) { model.tag1 = row["tag1"].ToString(); } if (row["tag2"] != null) { model.tag2 = row["tag2"].ToString(); } if (row["tag3"] != null) { model.tag3 = row["tag3"].ToString(); } if (row["tag4"] != null) { model.tag4 = row["tag4"].ToString(); } if (row["tag5"] != null) { model.tag5 = row["tag5"].ToString(); } } return(model); }
/// <summary> /// 装载任务申请 /// </summary> private bool FillTaskRequire(ref string reStr) { //if (db2Vals[0] == 1) //{ // currentTaskPhase = 0; // db1ValsToSnd[0] = 1; // rfidUID = string.Empty; // currentTaskDescribe = "等待新的任务"; // return; //} if (db2Vals[0] == 2 && db1ValsToSnd[0] != 2) { if (ExistUnCompletedTask((int)SysCfg.EnumAsrsTaskType.托盘装载)) { return(true); } //先读RFID卡 currentTaskDescribe = "开始读RFID"; this.rfidUID = ""; if (SysCfg.SysCfgModel.SimMode || SysCfg.SysCfgModel.RfidSimMode) { this.rfidUID = this.SimRfidUID; } else { this.rfidUID = rfidRW.ReadStrData();// // this.rfidUID = "TP2" + this.rfidUID.Substring(this.rfidUID.Length - 6, 6); } if (string.IsNullOrWhiteSpace(this.rfidUID)) { if (this.db1ValsToSnd[1] != 3) { logRecorder.AddDebugLog(nodeName, "读RFID失败"); } this.db1ValsToSnd[1] = 3; return(true); } //验证RFID的格式START //if (this.rfidUID.Length < 9) //{ // if (this.db1ValsToSnd[1] != 3) // { // logRecorder.AddDebugLog(nodeName, "读料框RFID错误,长度不足9字符!"); // } // this.db1ValsToSnd[1] = 3; // return true; //} //if (this.rfidUID.Length > 9) //{ // //this.rfidUID = this.rfidUID.Substring(this.rfidUID.Length - 9, 9); // this.rfidUID = this.rfidUID.Substring(0, 9); //} logRecorder.AddDebugLog(this.nodeName, "读到托盘号:" + this.rfidUID); //验证RFID的格式END //解绑 currentTaskDescribe = "开始解绑"; // ZP 20171220: 如果数据库中存在,需先解绑。 if (!productOnlineBll.UnbindPallet(this.rfidUID, ref reStr)) { logRecorder.AddDebugLog(nodeName, reStr); return(false); } //生成新任务 this.currentTaskPhase = 1; ControlTaskModel task = new ControlTaskModel(); task.DeviceID = this.nodeID; task.CreateMode = "自动"; task.CreateTime = System.DateTime.Now; task.TaskID = System.Guid.NewGuid().ToString("N"); task.TaskStatus = SysCfg.EnumTaskStatus.待执行.ToString(); task.TaskType = (int)SysCfg.EnumAsrsTaskType.托盘装载; task.TaskParam = this.rfidUID; task.TaskPhase = this.currentTaskPhase; task.TaskStatus = SysCfg.EnumTaskStatus.执行中.ToString(); task.Remark = SysCfg.EnumAsrsTaskType.托盘装载.ToString(); this.ctlTaskBll.Add(task); this.currentTask = task; currentTaskDescribe = "装载任务生成"; return(true); } if (db2Vals[0] == 1 && this.currentTask == null) { this.db1ValsToSnd[1] = 1; } return(true); }
protected override bool NodeStatParse(ref string reStr) { //if(!base.NodeStatParse(ref reStr)) //{ // return false; //} if (db2Vals[0] == 1) { if (!productChecked) { logRecorder.AddDebugLog(nodeName, "检测到有产品"); } productChecked = true; if (!graspBegin) { if (currentTaskPhase == 0) { ControlTaskModel task = new ControlTaskModel(); task.TaskID = System.Guid.NewGuid().ToString("N"); task.TaskParam = string.Empty; task.TaskPhase = 1; task.CreateTime = System.DateTime.Now; task.DeviceID = this.nodeID; task.CreateMode = "自动"; task.TaskStatus = EnumTaskStatus.执行中.ToString(); ctlTaskBll.Add(task); this.currentTask = task; currentTaskPhase = 1; //开始流程 checkEnable = true; DevCmdReset(); this.currentStat.Status = EnumNodeStatus.设备空闲; this.currentStat.ProductBarcode = ""; this.currentStat.StatDescribe = "设备空闲"; checkFinished = false; currentTaskDescribe = "等待有板信号"; } } } else if (db2Vals[0] == 0) { if (productChecked) { logRecorder.AddDebugLog(nodeName, "产品离开工位"); } productChecked = false; if (!graspBegin) //非抓取状态 { if (!ctlTaskBll.ClearTask(string.Format("DeviceID='{0}'", this.nodeID))) { logRecorder.AddDebugLog(nodeName, "清理任务失败"); return(false); } this.currentTask = null; this.currentTaskPhase = 0; checkEnable = true; DevCmdReset(); rfidUID = string.Empty; this.currentStat.Status = EnumNodeStatus.设备空闲; this.currentStat.ProductBarcode = ""; this.currentStat.StatDescribe = "设备空闲"; checkFinished = false; currentTaskDescribe = "等待有板信号"; } } return(true); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ControlTaskModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ControlTask set "); strSql.Append("TaskType=@TaskType,"); strSql.Append("TaskParam=@TaskParam,"); strSql.Append("TaskStatus=@TaskStatus,"); strSql.Append("TaskPhase=@TaskPhase,"); strSql.Append("CreateTime=@CreateTime,"); strSql.Append("FinishTime=@FinishTime,"); strSql.Append("CreateMode=@CreateMode,"); strSql.Append("Remark=@Remark,"); strSql.Append("DeviceID=@DeviceID,"); strSql.Append("tag1=@tag1,"); strSql.Append("tag2=@tag2,"); strSql.Append("tag3=@tag3,"); strSql.Append("tag4=@tag4,"); strSql.Append("tag5=@tag5"); strSql.Append(" where TaskID=@TaskID "); SqlParameter[] parameters = { new SqlParameter("@TaskType", SqlDbType.Int, 4), new SqlParameter("@TaskParam", SqlDbType.NVarChar, 255), new SqlParameter("@TaskStatus", SqlDbType.NVarChar, 50), new SqlParameter("@TaskPhase", SqlDbType.Int, 4), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@FinishTime", SqlDbType.DateTime), new SqlParameter("@CreateMode", SqlDbType.NVarChar, 50), new SqlParameter("@Remark", SqlDbType.NVarChar, 50), new SqlParameter("@DeviceID", SqlDbType.NVarChar, 50), new SqlParameter("@tag1", SqlDbType.NVarChar, 255), new SqlParameter("@tag2", SqlDbType.NVarChar, 255), new SqlParameter("@tag3", SqlDbType.NVarChar, 255), new SqlParameter("@tag4", SqlDbType.NVarChar, 255), new SqlParameter("@tag5", SqlDbType.NVarChar, 255), new SqlParameter("@TaskID", SqlDbType.NVarChar, 255) }; parameters[0].Value = model.TaskType; parameters[1].Value = model.TaskParam; parameters[2].Value = model.TaskStatus; parameters[3].Value = model.TaskPhase; parameters[4].Value = model.CreateTime; parameters[5].Value = model.FinishTime; parameters[6].Value = model.CreateMode; parameters[7].Value = model.Remark; parameters[8].Value = model.DeviceID; parameters[9].Value = model.tag1; parameters[10].Value = model.tag2; parameters[11].Value = model.tag3; parameters[12].Value = model.tag4; parameters[13].Value = model.tag5; parameters[14].Value = model.TaskID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 装载任务申请 /// </summary> private bool FillTaskRequire(ref string reStr) { if (db2Vals[0] == 2 && db1ValsToSnd[0] != 2) { if (ExistUnCompletedTask((int)SysCfg.EnumAsrsTaskType.托盘装载)) { return(true); } //先读RFID卡 currentTaskDescribe = "开始读RFID"; this.rfidUID = ""; if (SysCfg.SysCfgModel.SimMode) { this.rfidUID = this.SimRfidUID; } else { this.rfidUID = rfidRW.ReadStrData();// } this.rfidUID = this.rfidUID.TrimEnd('\0'); this.rfidUID = this.rfidUID.Trim(); if (string.IsNullOrWhiteSpace(this.rfidUID)) { if (this.db1ValsToSnd[1] != 3) { this.logRecorder.AddDebugLog(nodeName, "读RFID失败"); } this.db1ValsToSnd[1] = 3; return(true); } //if (this.db1ValsToSnd[1] != 3) { this.logRecorder.AddDebugLog(this.nodeName, "读到托盘号:" + this.rfidUID.Trim()); } //验证RFID的格式START if (!VerifyRFID(this.rfidUID)) { if (this.db1ValsToSnd[1] != 3) { this.logRecorder.AddDebugLog(nodeName, string.Format("{0} RFID验证失败", this.rfidUID.Trim())); } this.db1ValsToSnd[1] = 3; return(true); } //验证RFID的格式END //解绑 currentTaskDescribe = "开始解绑"; // ZP 20171220: 如果数据库中存在,需先解绑。 if (!productOnlineBll.UnbindPallet(this.rfidUID, ref reStr)) { this.logRecorder.AddDebugLog(nodeName, reStr); return(false); } //生成新任务 this.currentTaskPhase = 1; ControlTaskModel task = new ControlTaskModel(); task.DeviceID = this.nodeID; task.CreateMode = "自动"; task.CreateTime = System.DateTime.Now; task.TaskID = System.Guid.NewGuid().ToString("N"); task.TaskType = (int)SysCfg.EnumAsrsTaskType.托盘装载; task.TaskParam = this.rfidUID; task.TaskPhase = this.currentTaskPhase; task.TaskStatus = SysCfg.EnumTaskStatus.执行中.ToString(); task.Remark = SysCfg.EnumAsrsTaskType.托盘装载.ToString(); task.tag1 = stockName; this.ctlTaskBll.Add(task); this.currentTask = task; currentTaskDescribe = "装载任务生成"; return(true); } if (db2Vals[0] == 1 && this.currentTask == null) { this.db1ValsToSnd[1] = 1; } return(true); }
/// <summary> /// 任务申请 /// </summary> private bool FillTaskRequire(ref string reStr) { EnumAsrsTaskType taskType = EnumAsrsTaskType.扫码工位; //if (taskType != EnumAsrsTaskType.空) //{ // if (ExistUnCompletedTask((int)taskType)) // { // return true; // } //} string getBarcode = string.Empty; if (SysCfg.SysCfgModel.SimMode) { getBarcode = StartBarcode; } else { if (((this.db1ValsToSnd[0] == 1 || this.db1ValsToSnd[0] == 0) && this.currentTask == null) || ((this.db1ValsToSnd[1] == 1 || this.db1ValsToSnd[1] == 0) && this.currentTaskPhase == 3) || ((this.currentTaskPhase == 0) && (this.currentTask != null))) { //getBarcode = barcodeRW.ReadBarcode();// getBarcode = StartBarcode; if (string.IsNullOrWhiteSpace(getBarcode)) { if (this.currentTask == null) { this.db1ValsToSnd[0] = 1; } return(true); } // 如果读取到的的Barcode 不是开始 if (getBarcode.ToLower() != StartBarcode) { return(false); } else { if (this.db2Vals[0] == 2 || this.db2Vals[1] == 2) { this.logRecorder.AddDebugLog(nodeName, "扫描到Start条形码,DB2的状态错误!"); return(false); } } if (((this.db1ValsToSnd[0] == 1) && (this.currentTask == null)) || ((this.currentTaskPhase == 0) && (this.currentTask != null))) { this.logRecorder.AddDebugLog(nodeName, "已扫描Start条形码!"); this.db1ValsToSnd[0] = 2; if (((this.currentTaskPhase == 0) && (this.currentTask != null))) { this.currentTaskPhase = 1; } } } } if (this.currentTask == null) { //生成新任务 this.currentTaskPhase = 1; ControlTaskModel task = new ControlTaskModel(); task.DeviceID = this.nodeID; task.CreateMode = "自动"; task.CreateTime = System.DateTime.Now; task.TaskParam = this.nodeID; task.TaskID = System.Guid.NewGuid().ToString("N"); task.TaskType = (int)taskType; task.TaskPhase = this.currentTaskPhase; task.TaskStatus = SysCfg.EnumTaskStatus.执行中.ToString(); task.Remark = nodeName.ToString(); this.ctlTaskBll.Add(task); this.currentTask = task; currentTaskDescribe = "扫码任务生成"; } return(true); }
/// <summary> /// 处理业务 /// </summary> /// <returns></returns> public virtual bool ExeBusiness() { if (currentTask == null || currentTask.TaskStatus == EnumTaskStatus.待执行.ToString()) { return(true); } //判断是否有任务撤销 if (currentTask != null && currentTaskPhase < 5) { int taskFinish = int.Parse(dicCommuDataDB2[5].Val.ToString()); int taskRes = int.Parse(dicCommuDataDB1[3].Val.ToString()); if (taskFinish == 3 && taskRes != 3) { //任务清理 ClearDevCmd(); currentTask.TaskStatus = EnumTaskStatus.任务撤销.ToString(); ctlTaskBll.Update(currentTask); currentTaskDescribe = "任务撤销,等待'撤销信号'复位"; taskCompletedReq = 3; if (!DevCmdCommit()) { AddLog(devName + "发送命令失败", EnumLogType.错误); return(false); } // AddLog(devName + ",Test:任务撤销,发送‘任务完成应答信息:" + dicCommuDataDB1[3].Val.ToString(), EnumLogType.调试信息); return(true); } if (taskFinish == 1 && taskRes == 3) { taskCompletedReq = 1; if (!DevCmdCommit()) { AddLog(devName + "发送命令失败", EnumLogType.错误); return(false); } //AddLog(devName + ",Test:任务撤销应答复位,发送‘任务完成应答信息:" + dicCommuDataDB1[3].Val.ToString(), EnumLogType.调试信息); currentTaskPhase = 0; currentTask = null; currentTaskDescribe = "当前无任务"; return(true); } } //if (currentTask != null && (taskElapseCounter > taskTimeOutCounts)) taskElapseTimespan = System.DateTime.Now - currentTaskStartTime; if (taskElapseTimespan.TotalMinutes > taskTimeOutMinutes) { currentTaskStartTime = System.DateTime.Now; if (currentTask.TaskStatus == EnumTaskStatus.执行中.ToString()) { currentTask.TaskStatus = EnumTaskStatus.超时.ToString(); ctlTaskBll.Update(currentTask); } //任务超时,错误码2202 int errCode = 2202; string reStr = ""; if (!ECAMWCS.GetErrorContent(errCode, ref reStr)) { reStr = devName + "控制任务ID:" + currentTask.ControlTaskID + "任务超时"; AddLog(reStr, EnumLogType.错误); } else { reStr = (devName + "控制任务ID:" + currentTask.ControlTaskID + " 执行任务超时"); OnErrorHappen(errCode, reStr, false); } } return(true); }