private void CreateMainTask() { taskSimpleScheduler = new TaskSimpleScheduler(); autoResetEvent.Reset(); taskSimpleScheduler.StartNewTask("模拟业务", () => { if (!this.IsStartSimulator) { return; } // 心跳 this.EquDber.Execute("update " + EntityReflectionUtil.GetTableName <EquQZDZYJSignal>() + " set TagValue=@TagValue where TagName=@TagName", new { TagName = GlobalVars.EquHeartbeatName, TagValue = DateTime.Now.ToString() }); // 更新采样计划 this.EquDber.Execute("update " + EntityReflectionUtil.GetTableName <EquQZDZYJPlan>() + " set DataFlag=1 where DataFlag=0"); // 控制命令 EquQZDZYJCmd pDCYJCmd = this.EquDber.Entity <EquQZDZYJCmd>("where DataFlag=0 order by CreateDate desc"); if (pDCYJCmd != null) { CmdHandle(pDCYJCmd); autoResetEvent.WaitOne(); } }, 3000); }
/// <summary> /// 翻车业务逻辑入口 /// </summary> private void CreateMainTask() { taskSimpleScheduler = new TaskSimpleScheduler(); autoResetEvent.Reset(); taskSimpleScheduler.StartNewTask("翻车业务逻辑", () => { // 获取待处理的车号识别记录 - 入厂方向 CmcsTrainCarriagePass inTrainCarriagePass = carriageRecognitionerDAO.GetUnHandleTrainCarriagePass(this.carriageRecognitionerMachineCode, eTrainPassDirection.进厂); if (inTrainCarriagePass != null) { this.CurrentTrainCarriagePass = inTrainCarriagePass; // 检测采样机系统的状态 string samplerSystemStatue = commonDAO.GetSignalDataValue(this.trainBeltSampler.EquipmentCode, eSignalDataName.系统.ToString()); if (samplerSystemStatue == eEquInfSamplerSystemStatus.发生故障.ToString() || samplerSystemStatue == eEquInfSamplerSystemStatus.正在卸样.ToString()) { MessageBoxEx2Show("禁止翻车, " + this.trainBeltSampler.EquipmentName + "发生故障或正在卸样,已暂停运行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); btnStartTurnover.Enabled = true; // 取消任务 this.taskSimpleScheduler.Cancal(); return; } StartTippingTask(this.CurrentTrainCarriagePass); autoResetEvent.WaitOne(); } }, 4000); }
/// <summary> /// 发送存样柜命令并监听执行结果 /// </summary> /// <returns></returns> private void SendCYGCmd(string MakeCode, string machineCode, eCZPLX OperType, string OperUser) { taskSimpleScheduler = new TaskSimpleScheduler(); autoResetEvent.Reset(); taskSimpleScheduler.StartNewTask("存样柜命令", () => { this.IsWorking = true; // 发送取样命令 if (autoCupboardDAO.SaveAutoCupboardCmd(MakeCode, machineCode, OperType, OperUser)) { ShowMessage(string.Format("{0}命令发送成功,等待存样柜执行", OperType), eOutputType.Normal); int waitCount = 0; eEquInfCYGCmdResultCode equInfCmdResultCode = eEquInfCYGCmdResultCode.默认; do { Thread.Sleep(10000); if (waitCount % 5 == 0) { ShowMessage("等待执行...执行结果:" + equInfCmdResultCode.ToString().Replace("默认", "执行中"), eOutputType.Normal); } waitCount++; // 获取卸样命令的执行结果 equInfCmdResultCode = autoCupboardDAO.GetAutoCupboardResult(MakeCode); }while (equInfCmdResultCode == eEquInfCYGCmdResultCode.气动执行成功); ShowMessage(equInfCmdResultCode.ToString(), eOutputType.Important); } else { ShowMessage("存样柜命令发送失败", eOutputType.Error); } autoResetEvent.Set(); }); }
/// <summary> /// 监听机械采样机返回结果 /// </summary> /// <returns></returns> private void SendJxSamplerUnloadCmd() { taskSimpleScheduler = new TaskSimpleScheduler(); autoResetEvent.Reset(); taskSimpleScheduler.StartNewTask("卸样业务逻辑", () => { this.IsWorking = true; // 发送卸样命令 if (qcjxcySamplerDAO.SendSampleUnloadCmd(this.CurrentSampler.EquipmentCode, this.CurrentRCSampling.Id, this.currentSampleCode, (eEquInfSamplerUnloadType)Convert.ToInt16(flpanUnloadType.Controls.OfType <RadioButton>().First(a => a.Checked).Tag), out this.currentUnloadCmdId)) { rTxtOutputer.Output("卸样命令发送成功,等待采样机执行", eOutputType.Normal); int waitCount = 0; eEquInfCmdResultCode equInfCmdResultCode; do { Thread.Sleep(10000); if (waitCount % 5 == 0) { rTxtOutputer.Output("正在等待采样机返回结果", eOutputType.Normal); } waitCount++; // 获取卸样命令的执行结果 equInfCmdResultCode = UnloadSamplerDAO.GetInstance().GetQCJXCYUnloadSamplerState(this.currentUnloadCmdId); }while (equInfCmdResultCode == eEquInfCmdResultCode.默认); if (equInfCmdResultCode == eEquInfCmdResultCode.成功) { rTxtOutputer.Output("采样机返回:卸样成功", eOutputType.Normal); // 检测制样机系统状态 if (rbtnToMaker.Checked) { string makerSystemStatus = commonDAO.GetSignalDataValue(this.makerMachineCode, eSignalDataName.系统.ToString()); if (makerSystemStatus == eEquInfSamplerSystemStatus.就绪待机.ToString()) { if (MessageBoxEx.Show("卸样成功,检测到制样机已就绪,立刻开始制样?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { if (SendMakePlan(this.CurrentRCSampling.Id, this.CurrentRCSampling.InFactoryBatchId)) { rTxtOutputer.Output("制样命令发送成功", eOutputType.Normal); } else { rTxtOutputer.Output("制样命令发送失败", eOutputType.Error); } } } } } else if (equInfCmdResultCode == eEquInfCmdResultCode.失败) { rTxtOutputer.Output("采样机返回:卸样失败", eOutputType.Error); } } else { rTxtOutputer.Output("卸样命令发送失败", eOutputType.Error); } this.IsWorking = false; LoadSampleBarrel(superGridControl1, this.CurrentSampler.EquipmentCode); LoadLatestSampleUnloadCmd(this.CurrentSampler); autoResetEvent.Set(); }); }
/// <summary> /// 监听采样机返回结果 /// </summary> /// <returns></returns> private void SendSamplerUnloadCmd() { taskSimpleScheduler = new TaskSimpleScheduler(); autoResetEvent.Reset(); taskSimpleScheduler.StartNewTask("卸样业务逻辑", () => { this.IsWorking = true; if (rbtnToMaker.Checked) { #region 启动制样进料皮带 if (beltSamplerDAO.SendPDUnLoadCmd(this.CurrentMaker, "开始卸料")) { rTxtOutputer.Output("卸样皮带命令发送成功,等待制样机执行", eOutputType.Normal); int waitCount = 0; eEquInfCmdResultCode equInfCmdResultCode; do { Thread.Sleep(10000); if (waitCount % 5 == 0) { rTxtOutputer.Output("正在等待制样机返回结果", eOutputType.Normal); } waitCount++; // 获取卸样命令的执行结果 equInfCmdResultCode = UnloadSamplerDAO.GetInstance().GetPDUnloadState(); }while (equInfCmdResultCode == eEquInfCmdResultCode.默认); if (equInfCmdResultCode == eEquInfCmdResultCode.成功) { rTxtOutputer.Output("制样机返回:皮带启动成功", eOutputType.Normal); } else if (equInfCmdResultCode == eEquInfCmdResultCode.失败) { rTxtOutputer.Output("制样机返回:执行失败", eOutputType.Error); } } else { rTxtOutputer.Output("卸样皮带命令发送失败", eOutputType.Error); } #endregion } #region 发送采样机卸样命令 // 发送卸样命令 if (beltSamplerDAO.SendSampleUnloadCmd(this.currentSampler.EquipmentCode, this.CurrentRCSampling.Id, this.currentSampleCode, (eEquInfSamplerUnloadType)Convert.ToInt16(flpanUnloadType.Controls.OfType <RadioButton>().First(a => a.Checked).Tag), out this.currentUnloadCmdId)) { rTxtOutputer.Output("卸样命令发送成功,等待采样机执行", eOutputType.Normal); int waitCount = 0; eEquInfCmdResultCode equInfCmdResultCode; do { Thread.Sleep(10000); if (waitCount % 5 == 0) { rTxtOutputer.Output("正在等待采样机返回结果", eOutputType.Normal); } waitCount++; // 获取卸样命令的执行结果 equInfCmdResultCode = UnloadSamplerDAO.GetInstance().GetUnloadSamplerState(this.currentUnloadCmdId); }while (equInfCmdResultCode == eEquInfCmdResultCode.默认); if (equInfCmdResultCode == eEquInfCmdResultCode.成功) { rTxtOutputer.Output("采样机返回:卸样成功", eOutputType.Normal); } else if (equInfCmdResultCode == eEquInfCmdResultCode.失败) { rTxtOutputer.Output("采样机返回:卸样失败", eOutputType.Error); return; } } else { rTxtOutputer.Output("卸样命令发送失败", eOutputType.Error); return; } #endregion #region 停止制样机进料皮带 if (beltSamplerDAO.SendPDUnLoadCmd(this.CurrentMaker, "停止卸料")) //卸样完成后 卸料皮带停止 { rTxtOutputer.Output("卸样皮带停止命令发送成功,等待制样机执行", eOutputType.Normal); int waitCount = 0; eEquInfCmdResultCode equInfCmdResultCode; do { Thread.Sleep(10000); if (waitCount % 5 == 0) { rTxtOutputer.Output("正在等待制样机返回结果", eOutputType.Normal); } waitCount++; // 获取卸样命令的执行结果 equInfCmdResultCode = UnloadSamplerDAO.GetInstance().GetPDUnloadState(); }while (equInfCmdResultCode == eEquInfCmdResultCode.默认); if (equInfCmdResultCode == eEquInfCmdResultCode.成功) { rTxtOutputer.Output("制样机返回:皮带停止成功", eOutputType.Normal); } else if (equInfCmdResultCode == eEquInfCmdResultCode.失败) { rTxtOutputer.Output("制样机返回:执行失败", eOutputType.Error); return; } } else { rTxtOutputer.Output("卸样皮带命令发送失败", eOutputType.Error); return; } #endregion #region 检测制样机状态,若已就绪提示发送制样计划 // 检测制样机系统状态 if (rbtnToMaker.Checked && this.currentEquInfSampleBarrels != null && this.currentEquInfSampleBarrels[0].BarrelType == "底卸式") { string makerSystemStatus = commonDAO.GetSignalDataValue(this.CurrentMaker, eSignalDataName.设备状态.ToString()); if (makerSystemStatus == eEquInfSamplerSystemStatus.就绪待机.ToString()) { if (MessageBoxEx.Show("卸样成功,检测到制样机已就绪,立刻开始制样?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { if (SendMakePlan(this.CurrentRCSampling.SampleCode, this.CurrentRCSampling.InFactoryBatchId)) { rTxtOutputer.Output("制样命令发送成功", eOutputType.Normal); } else { rTxtOutputer.Output("制样命令发送失败", eOutputType.Error); } } } } #endregion this.IsWorking = false; LoadBeltSampleBarrel(superGridControl1, this.CurrentSampler.EquipmentCode); LoadLatestSampleUnloadCmd(this.CurrentSampler.EquipmentCode); autoResetEvent.Set(); }); }
/// <summary> /// 发送存样柜命令并监听执行结果 /// </summary> /// <returns></returns> private void SendCYGCmd(List <String> MakeCodes, String OperType, string OperUser, string machineCode) { taskSimpleScheduler = new TaskSimpleScheduler(); autoResetEvent.Reset(); taskSimpleScheduler.StartNewTask("存样柜命令", () => { this.IsWorking = true; // 发送取样命令 if (!string.IsNullOrEmpty(autoCupboardDAO.AddAutoCupboard(MakeCodes, OperType, OperUser, machineCode))) { //pneumaticTransferDAO.SaveQDCmd(); ShowMessage(string.Format("{0}命令发送成功,等待存样柜执行", OperType), eOutputType.Normal); int waitCount = 0; eEquInfCmdResultCode equInfCmdResultCode; do { Thread.Sleep(10000); if (waitCount % 5 == 0) { ShowMessage("正在等待存样柜返回结果", eOutputType.Normal); } waitCount++; // 获取卸样命令的执行结果 equInfCmdResultCode = autoCupboardDAO.GetAutoCupboardResult(MakeCodes[0]); }while (equInfCmdResultCode == eEquInfCmdResultCode.默认); if (equInfCmdResultCode == eEquInfCmdResultCode.成功) { ShowMessage("存样柜返回:执行成功", eOutputType.Normal); if (SendQDCSCmd(MakeCodes[0], machineCode)) { do { Thread.Sleep(10000); if (waitCount % 5 == 0) { ShowMessage("正在等待气动传输返回结果", eOutputType.Normal); } waitCount++; // 获取卸样命令的执行结果 equInfCmdResultCode = pneumaticTransferDAO.GetQDCSResult(MakeCodes[0]); }while (equInfCmdResultCode == eEquInfCmdResultCode.默认); } if (equInfCmdResultCode == eEquInfCmdResultCode.成功) { ShowMessage("气动传输返回:执行成功", eOutputType.Normal); } } } else { ShowMessage("存样柜命令发送失败", eOutputType.Error); } autoResetEvent.Set(); }); }