private void mainForm_Closing(Object sender, FormClosingEventArgs e)
        {
            List <TaskRecord> trList = TaskReordService.getInstance().getTaskRecordList();
            DialogResult      dr     = System.Windows.Forms.DialogResult.No;

            if (trList.Count > 0)
            {
                dr = MessageBox.Show("当前有任务没完成,确认退出?", "退出提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
            }
            else if (ElevatorFactory.getElevator().getOutCommand() != elevator.COMMAND_FROME2S.LIFT_OUT_COMMAND_MIN)
            {
                dr = MessageBox.Show("升降机上有任务,确认退出?", "退出提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
            }
            else
            {
                dr = MessageBox.Show("确认退出?", "退出提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2);
            }

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                this.Dispose();
                System.Environment.Exit(0);
            }
            else if (dr == System.Windows.Forms.DialogResult.Cancel)
            {
                e.Cancel = true;
            }
        }
示例#2
0
        /// <summary>
        ///检查升降串口,必要条件,升降机串口不能用,主程序不能运行
        /// </summary>
        private ENV_ERR_TYPE checkRunning()
        {
            ENV_ERR_TYPE err = ENV_ERR_TYPE.ENV_ERR_OK;

            if (ElevatorFactory.getElevator().getStat() == false)
            {
                err = ENV_ERR_TYPE.ENV_LIFT_COM_ERR;
                return(err);
            }

            err = checkCacheTaskRecoreds();

            ///检查3号车是否可用,备选条件,如果不可用,是否存在其它上货方式

            ///检测USB报警灯,如果USB报警灯有问题,切换到电脑声音报警
            try {
                if (JG_OpenUSBAlarmLamp(0) == 0)
                {
                    //MessageBox.Show("打开报警灯失败,切换到电脑声音报警");
                    useUsbAlarm = false;
                }
            } catch (Exception ex) {
                //MessageBox.Show("打开报警灯失败,切换到电脑声音报警");
                useUsbAlarm = false;
            }
            return(err);
        }
		private void sheduleLift() {
			AGVMessage message = new AGVMessage();
			if (ElevatorFactory.getElevator().getOutCommand() == COMMAND_FROME2S.LIFT_OUT_COMMAND_UP_DOWN)  //楼上楼下都有货
			{
				AGVLog.WriteWarn("升降机楼上楼下都有货,楼上的车被暂停", new StackFrame(true));
				message.setMessageType(AGVMessageHandler_TYPE_T.AGVMEASAGE_LIFT_UPDOWN);
				message.setMessageStr("升降机楼上楼下都有货,楼上的车被暂停");

				AGVMessageHandler.getMessageHandler().setMessage(message);  //发送消息
			} else if (ElevatorFactory.getElevator().getOutCommand() > COMMAND_FROME2S.LIFT_OUT_COMMAND_UP_DOWN)  //升降机 卡货
			{
				AGVLog.WriteWarn("升降机卡货,系统被暂停", new StackFrame(true));
				message.setMessageType(AGVMessageHandler_TYPE_T.AGVMessageHandler_LIFT_BUG);
				message.setMessageStr("升降机卡货,系统被暂停");

				AGVMessageHandler.getMessageHandler().setMessage(message);  //发送消息
			}
		}
示例#4
0
        public void agvInit()
        {
            if (FormController.isNeedLogin())
            {
                FormController.getFormController().getLoginFrm().ShowDialog();
            }

            TaskexeDao.getDao().InsertTaskexeSysInfo("AGV通讯服务程序启动!");
            setForkliftStateFirst();

            handleCheckRunning(checkRunning());

            if (isNeedElevator)
            {
                ElevatorFactory.getElevator().startReadSerialPortThread();
            }

            if (isNeedAGVSocketServer)
            {
                AGVSocketServer.getSocketServer().StartAccept();
            }

            if (isNeedSchedule)
            {
                ScheduleFactory.getSchedule().startShedule();
            }

            if (isNeedTaskexe)
            {
                TaskexeService.getInstance().start();
            }

            AGVMessageHandler.getMessageHandler().StartHandleMessage();

            if (isNeedMain)
            {
                FormController.getFormController().getMainFrm().ShowDialog();
            }
            else
            {
                FormController.getFormController().getInfoFrm().ShowDialog();
            }
        }
		private bool checkDownDeliverPeriodOver(int upStep) {
			foreach (ForkLiftWrapper fl in AGVCacheData.getForkLiftWrapperList()) {
				if (fl.getForkLift().isUsed == 1 && fl.getForkLift().taskStep != TASK_STEP.TASK_IDLE) //如果有车在运行
				{
					return false;
				}
			}

			if (ElevatorFactory.getElevator().getOutCommand() != 0) //升降机上有任务, 表示上料没有结束
			{
				return false;
			}

			if (upStep > 0) {
				Console.WriteLine("当前处于上货 " + upStep + " 阶段");
				AGVLog.WriteError("当前处于上货 " + upStep + " 阶段", new StackFrame(true));
				return false;
			}

			return true;
		}
示例#6
0
        private void handleMessage()
        {
            while (!isStop)
            {
                Thread.Sleep(1000);
                if (message_next.getMessageType() == AGVMessageHandler_TYPE_T.AGVMessageHandler_MIN)
                {
                    continue;
                }
                message.setMessageStr(message_next.getMessageStr());
                message.setMessageType(message_next.getMessageType());

                message_next.clear();

                startBeep(message.getMessageType());

                if (message.getMessageType() == AGVMessageHandler_TYPE_T.AGVMessageHandler_LOWPOWER)
                {
                    FormController.getFormController().getMainFrm().setFrmEnable(false);
                    DialogResult dr = MessageBox.Show(message.getMessageStr(), "低电量警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    if (dr == DialogResult.OK)
                    {
                        FormController.getFormController().getMainFrm().setFrmEnable(true);
                        FormController.getFormController().getMainFrm().setWindowState(FormWindowState.Normal);
                        clearBeep();
                    }
                }
                else if (message.getMessageType() == AGVMessageHandler_TYPE_T.AGVMEASAGE_LIFT_UPDOWN)
                {
                    bool ddp = ScheduleFactory.getSchedule().getDownDeliverPeriod();
                    if (ddp)
                    {
                        AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_DOWN_WITH_START);                          //如果当前处于上货阶段,楼上楼下都有货,需要暂停楼下的车
                    }
                    else
                    {
                        AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_UP_WITH_START);                         //如果当前处于下货阶段,楼上楼下都有货,需要暂停楼上的车
                    }

                    DialogResult dr = MessageBox.Show(message.getMessageStr(), "升降机提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    if (dr == DialogResult.OK)
                    {
                        AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_TYPE_MIN);                         //解除楼上或楼下的暂停
                        clearBeep();
                    }
                }
                else if (message.getMessageType() == AGVMessageHandler_TYPE_T.AGVMessageHandler_LIFT_COM)
                {
                    AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_SYSTEM_WITH_START);
                    FormController.getFormController().getMainFrm().setFrmEnable(false);
                    DialogResult dr = MessageBox.Show(message.getMessageStr(), "升降机错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    if (dr == DialogResult.OK)
                    {
                        if (ElevatorFactory.getElevator().isNeed())
                        {
                            ElevatorFactory.getElevator().reStart();                             //重新启动升降机 PLC读取线程
                        }
                        FormController.getFormController().getMainFrm().setFrmEnable(true);
                        AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_TYPE_MIN);                         //解除系统暂停
                        clearBeep();
                    }
                }
                else if (message.getMessageType() == AGVMessageHandler_TYPE_T.AGVMessageHandler_LIFT_BUG)
                {
                    AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_SYSTEM_WITH_START);
                    FormController.getFormController().getMainFrm().setFrmEnable(false);
                    DialogResult dr = MessageBox.Show(message.getMessageStr(), "升降机错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    if (dr == DialogResult.OK)
                    {
                        //AGVInitialize.getInitialize().getAGVElevatorOperator().reStart(); //重新启动升降机 PLC读取线程
                        FormController.getFormController().getMainFrm().setFrmEnable(true);
                        AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_TYPE_MIN);                         //解除系统暂停
                        clearBeep();
                    }
                }
                else if (message.getMessageType() == AGVMessageHandler_TYPE_T.AGVMessageHandler_NET_ERR)
                {
                    AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_SYSTEM_WITH_START);
                    DialogResult dr = MessageBox.Show(message.getMessageStr(), "网络异常", MessageBoxButtons.OK, MessageBoxIcon.Warning);                     //网络中断时,系统暂停
                    if (dr == DialogResult.OK)
                    {
                        AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_TYPE_MIN);
                        clearBeep();
                    }
                }
                else if (message.getMessageType() == AGVMessageHandler_TYPE_T.AGVMessageHandler_SENDPAUSE_ERR)
                {
                    AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_UP_WITHOUT_START);
                    DialogResult dr = MessageBox.Show(message.getMessageStr(), "网络异常", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    if (dr == DialogResult.OK)
                    {
                        AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_TYPE_MIN);                         //清除楼上暂停的标志,但是车子暂停不会解除
                        clearBeep();
                    }
                }
                else if (message.getMessageType() == AGVMessageHandler_TYPE_T.AGVMessageHandler_AGV_ALARM)                    //检测到防撞信号,暂停所有AGV
                {
                    AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_SYSTEM_WITH_START);
                    //DialogResult dr = MessageBox.Show(message.getMessageStr(), "防撞提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    //if (dr == DialogResult.OK) {
                    AGVSystem.getSystem().setPause(SHEDULE_PAUSE_TYPE_T.SHEDULE_PAUSE_TYPE_MIN);                             //清除楼上暂停的标志,但是车子暂停不会解除
                    clearBeep();
                    //}
                }
                message.clear();                  //清除消息
            }
        }
		public void sheduleTask() {
			ForkLiftWrapper tmpForkLiftWrapper = null;
			SingleTask tmpSingleTask = null;
			int upRecordStep = 0;  //没有上货, 该值大于0的时候,表示上货还没有结束,可能存在升降机正在运送,车子当前没有任务
			int downRecordStep = 0;  //没有下货,该值大于0的时候, 表示下货没有结束
			int result = -1;

			///***开始处理任务的循环语句***///
			while (ScheduleFactory.getSchedule().getScheduleFlag()) {

				Thread.Sleep(2000);
				if (AGVSystem.getSystem().getSystemPause()) {  //系统暂停后,调度程序不执行
					Console.WriteLine("system pause");
					continue;
				}

				//Console.WriteLine(" shedule Task");
				lock (LockController.getLockController().getLockTask()) {
					taskRecordList = TaskReordService.getInstance().getTaskRecordList();
					upTaskRecord = checkUpTaskRecord();
				}
				//if (upTaskRecord != null)
				//  Console.WriteLine(" upTaskRecord name = " + upTaskRecord.taskRecordName);

				if (ScheduleFactory.getSchedule().getDownDeliverPeriod()) //当前处于上货阶段,有的话控制升降机上升
				{
					//读取升降机上料信号
					if (ElevatorFactory.getElevator().getOutCommand() == COMMAND_FROME2S.LIFT_OUT_COMMAND_UP)  //检测到楼下有货,发送指令到升降机运货到楼上
					{
						ElevatorFactory.getElevator().setDataCommand(COMMAND_FROMS2E.LIFT_IN_COMMAND_UP);
						while (ElevatorFactory.getElevator().getOutCommand() != COMMAND_FROME2S.LIFT_OUT_COMMAND_DOWN)  //等待升降机送货到楼上
						{
							Console.WriteLine("wait lifter up goods");
							Thread.Sleep(100);
						}

						if (upRecordStep > 0) //升降机将货运到楼上,保证upRecordStep不小于0
						{
							upRecordStep--;
							AGVLog.WriteError("上货期间 升降机将货运送到楼上: step = " + upRecordStep, new StackFrame(true));
						}
					}

					if (ElevatorFactory.getElevator().getOutCommand() == COMMAND_FROME2S.LIFT_OUT_COMMAND_DOWN
						|| ElevatorFactory.getElevator().getOutCommand() == COMMAND_FROME2S.LIFT_OUT_COMMAND_UP_DOWN) //上货期间 楼上楼下都有货, 楼上的车子需要继续运行
					{
						lock (LockController.getLockController().getLockForkLift()) {
							//运动到楼上后,发送指令到楼上AGV,把货取走
							tmpForkLiftWrapper = getSheduleForkLift();
							if (tmpForkLiftWrapper != null) {
								tmpSingleTask = getUpPickSingleTaskOnTurn();
								TaskRecord tr_tmp = new TaskRecord();
								tr_tmp.singleTask = tmpSingleTask;
								tr_tmp.taskRecordName = tmpSingleTask.taskName;
								TaskReordService.getInstance().addTaskRecord(tr_tmp);
								tmpForkLiftWrapper.sendTask(tr_tmp); //发送任务
								upPicSingleTaskkUsed++; //用于下次切换卸货点
							} else {
								Console.WriteLine(" 楼上没有可用的车去卸货");
								AGVLog.WriteError(" 楼上没有可用的车去卸货", new StackFrame(true));
							}
						}
						if (tmpForkLiftWrapper != null) {

							while (ElevatorFactory.getElevator().getOutCommand() == COMMAND_FROME2S.LIFT_OUT_COMMAND_DOWN
								|| ElevatorFactory.getElevator().getOutCommand() == COMMAND_FROME2S.LIFT_OUT_COMMAND_UP_DOWN)  //等待楼上货物被取走,如果车的状态回到idle,说明任务发送失败
							{
								if (tmpForkLiftWrapper.getForkLift().taskStep == TASK_STEP.TASK_IDLE) {
									break;
								}
								Console.WriteLine("wait lifter goods to be pick");
								Thread.Sleep(500);
							}

							if (upRecordStep > 0) //升降机将货运到楼上,保证upRecordStep不小于0
							{
								upRecordStep--;
								AGVLog.WriteError("上货期间 楼上货物被取走: step = " + upRecordStep, new StackFrame(true));
							}
						}
					}


					if (checkDownDeliverPeriodOver(upRecordStep))  //检测上料任务有没有结束 条件1:没有上料任务缓存  条件2:所有车子空闲 条件3:升降机上没有货物
					{
						ScheduleFactory.getSchedule().setDownDeliverPeriod ( false);
					}

					downRecordStep = 0; //下料信号置0
					Console.WriteLine("上料阶段");
				}

				if (upTaskRecord != null) {
					if (!ScheduleFactory.getSchedule().getDownDeliverPeriod() && !checkUpDeliverPeriodOver(downRecordStep)) //检查下货任务有没有结束,升降机从楼上到楼下流程走完,没有正在执行的下货任务
						{
						Console.WriteLine("当前下货任务没有执行完成,执行完后再开始执行上货任务");

					} else if (upTaskRecord.taskRecordStat == TASKSTAT_T.TASK_READY_SEND) {
						tmpForkLiftWrapper = ForkLiftWrappersService.getInstance().getForkLiftByNunber(3);  //获取楼下三号车

						if (tmpForkLiftWrapper.getForkLift().taskStep != TASK_STEP.TASK_IDLE) {
							Console.WriteLine("上料任务正在执行,等待上料任务执行完成");
							continue;
						}

						if (ElevatorFactory.getElevator().getOutCommand() != COMMAND_FROME2S.LIFT_OUT_COMMAND_MIN) //只要升降机上有货或有异常都不发送上货任务,否则容易造成楼上楼下都要货
						{
							Console.WriteLine(" 升降机楼下有货,不发送上货任务");
						} else {
							lock (LockController.getLockController().getLockForkLift())  //锁住车的状态
							{
								result = tmpForkLiftWrapper.sendTask(upTaskRecord); //发送任务
								ScheduleFactory.getSchedule().setDownDeliverPeriod(true);//上货任务发送后,才进入上料阶段

								if (result == 0) //发送成功 才正式进入上货阶段
								{
									if (upRecordStep <= 2) //避免上货 step被加得太多,不能进入下货阶段
									{
										upRecordStep += 2;
										AGVLog.WriteError("上货期间 发送任务: step = " + upRecordStep, new StackFrame(true));
									}
								}
							}
						}
					}
				}

				//检测升降机2楼有货物,发送指令将升降机送货到楼下
				//检测升降机1楼有货物,调度1楼AGV送货
				//读取升降机上料信号
				if (!ScheduleFactory.getSchedule().getDownDeliverPeriod()) {
					Console.WriteLine(" 下料阶段");
					upRecordStep = 0; //上料信号置0
					if (ElevatorFactory.getElevator().getOutCommand() == COMMAND_FROME2S.LIFT_OUT_COMMAND_DOWN)  //检测到楼上有货,发送指令到升降机运货到楼下
					{
						int times_tmp = 0;
						ElevatorFactory.getElevator().setDataCommand(COMMAND_FROMS2E.LIFT_IN_COMMAND_DOWN);
						while (ElevatorFactory.getElevator().getOutCommand() == COMMAND_FROME2S.LIFT_OUT_COMMAND_DOWN && times_tmp < 60)  //等待升降机送货到楼下
						{
							Console.WriteLine("wait lifter down goods"); //光电感应大概10S可以结束
							times_tmp++;
							Thread.Sleep(1000);
						}

						if (times_tmp < 60) {
							if (downRecordStep > 0) //升降机将货运到楼上,保证upRecordStep不小于0
							{
								downRecordStep--;
								AGVLog.WriteError("下货期间 楼上货物送到楼下: step = " + downRecordStep, new StackFrame(true));
							}
						}

						times_tmp = 0;
					}

					if (ElevatorFactory.getElevator().getOutCommand() == COMMAND_FROME2S.LIFT_OUT_COMMAND_UP ||
							ElevatorFactory.getElevator().getOutCommand() == COMMAND_FROME2S.LIFT_OUT_COMMAND_UP_DOWN) //检测到楼下有货,通知AGV来取货
					{
						TaskRecord tr_tmp = new TaskRecord();
						tmpForkLiftWrapper = ForkLiftWrappersService.getInstance().getForkLiftByNunber(3);
						tmpSingleTask = getDownPickSingleTaskOnTurn();
						tr_tmp.singleTask = tmpSingleTask;
						tr_tmp.taskRecordName = tmpSingleTask.taskName;
						if (tmpForkLiftWrapper != null && tmpForkLiftWrapper.getForkLift().taskStep == TASK_STEP.TASK_IDLE) {
							TaskReordService.getInstance().addTaskRecord(tr_tmp); //发货后,才确认添加该记录
							result = tmpForkLiftWrapper.sendTask(tr_tmp);
							if (result == 0) //任务发送成功
							{
								downPicSingleTaskkUsed++; //用于下次切换卸货点
								if (downRecordStep > 0) //升降机将货运到楼上,保证upRecordStep不小于0
								{
									downRecordStep--;
									AGVLog.WriteError("下货期间 楼下货物被取走: step = " + downRecordStep, new StackFrame(true));
								}
							} else {
								TaskReordService.getInstance().removeTaskRecord(tr_tmp.singleTask, tr_tmp.taskRecordStat);  //如果任务没发送成功,删除该条记录
							}
						}

					}

					lock (LockController.getLockController().getLockTask()) {
						foreach (TaskRecord tr in taskRecordList) {
							lock (LockController.getLockController().getLockForkLift()) {
								if (tr.taskRecordStat == TASKSTAT_T.TASK_READY_SEND) {
									tmpForkLiftWrapper = null;
									if (tr.singleTask.taskType == TASKTYPE_T.TASK_TYPE_DOWN_PICK)
										tmpForkLiftWrapper = ForkLiftWrappersService.getInstance().getForkLiftByNunber(3);
									else if (tr.singleTask.taskType == TASKTYPE_T.TASK_TYPE_UP_DILIVERY)
										tmpForkLiftWrapper = getSheduleForkLift();  //有任务执行的时候,才考虑检查车子状态
																					//if (fl.getForkLift().taskStep == TASK_STEP.TASK_IDLE && fl.finishStatus == 1)  //检查车子的状态,向空闲的车子发送任务,如果发送失败,后面会检测发送状态,
																					//并将该任务状态改成待发重新发送
									if (tmpForkLiftWrapper != null && tmpForkLiftWrapper.getForkLift().taskStep == TASK_STEP.TASK_IDLE) {
										result = tmpForkLiftWrapper.sendTask(tr); //发送任务
										if (result == -1) //任务没有发送成功会中断本次循环,防止发送任务到后面的车
										{
											break;
										}

										if (tr.singleTask.taskType == TASKTYPE_T.TASK_TYPE_UP_DILIVERY && downRecordStep < 4) //发送的是楼上送货,并且送货发送次数小于2次
										{
											downRecordStep += 2;
											AGVLog.WriteError("下货期间 发送任务: step = " + downRecordStep, new StackFrame(true));
										}

									}
								}
							}
						}
					}
				}
			}
		}