Пример #1
0
        /// <summary>
        /// 发送任务
        /// </summary>
        /// <param name="tr"></param>
        /// <param name="fl"></param>
        public int sendTask(TaskRecord tr, ForkLift fl)
        {
            string cmd = null;

            int result = 0;

            Console.WriteLine("ready to send task: " + tr.singleTask.taskName + "forklist stat:" + fl.taskStep + "forklift finished:" + fl.finishStatus);
            cmd = "cmd=set task by name;name=" + tr.taskRecordName; //发送命令格式,如果有多个对应值用;隔开,如果后面没有命令了,不需要再加;号
            Console.WriteLine("send msg :" + cmd + "to " + fl.forklift_number);

            lock (fl.tcpClient.clientLock)
            {
                try
                {
                    fl.tcpClient.SendMessage(cmd);  //确保发送成功

                    tr.taskRecordStat      = TASKSTAT_T.TASK_SEND;
                    tr.singleTask.taskStat = TASKSTAT_T.TASK_SEND;
                    AGVInitialize.getInitialize().getMainFrm().updateFrm(); //设置更新界面
                    tr.forkLift    = fl;
                    fl.taskStep    = ForkLift.TASK_STEP.TASK_SENDED;
                    fl.currentTask = tr.singleTask.taskText;
                    AGVInitialize.getInitialize().getDBConnect().UpdateTaskRecord(tr);
                    AGVInitialize.getInitialize().getDBConnect().updateForkLift(fl);  //更新车子状态
                }catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    AGVLog.WriteError("发送" + tr.singleTask.taskText + " 任务到" + fl.forklift_number + "号车 失败", new StackFrame(true));
                    result = -1;
                }
            }

            AGVLog.WriteError("发送" + tr.singleTask.taskText + " 任务到" + fl.forklift_number + "号车 成功", new StackFrame(true));
            return(result);
        }
Пример #2
0
        public bool setForkCtrl(ForkLift fl, int ctrl)
        {
            string cmd   = "cmd=pause;pauseStat=" + ctrl;
            int    times = 0;

            while (times < 3)
            {
                try
                {
                    fl.tcpClient.SendMessage(cmd);
                    break;
                }
                catch
                {
                    Message message = new Message();
                    message.setMessageType(AGVMESSAGE_TYPE_T.AGVMESSAGE_SENDPAUSE_ERR);
                    message.setMessageStr("发送中断错误");

                    AGVInitialize.getInitialize().getAGVMessage().setMessage(message);
                }

                times++;
            }


            Console.WriteLine("setForkCtrl forklift " + fl.id + "cmd = " + cmd);
            AGVLog.WriteInfo("setForkCtrl forklift " + fl.id + "cmd = " + cmd, new StackFrame(true));
            return(true);
        }
Пример #3
0
        private void handleDataSerialPort()
        {
            int count;

            byte[] response = null;
            while (!isStop)
            {
                byte[] readBuffer = new byte[1];
                try
                {
                    sp.Write(common, 0, 4);

                    while ((count = sp.BytesToRead) != 8)
                    {
                        //            Console.WriteLine("wait to read bytes count = " + count); //等待反馈
                        Thread.Sleep(10);
                    }


                    response = new byte[count];
                    sp.Read(response, 0, count);

                    outCommand = readDataCommand(response);

                    /*if (outCommand == LIFT_OUT_COMMAND_T.LIFT_OUT_COMMAND_loushang_baojing || outCommand == LIFT_OUT_COMMAND_T.LIFT_OUT_COMMAND_louxia_baojing)
                     * {
                     *  if (dataCommand[0] == 0)  //当前没有命令的时候才去发送复位信号,否则会覆盖之前的信号
                     *  {
                     *      dataCommand[0] = 0x4;
                     *  }
                     *
                     *  Console.WriteLine("will to reset");
                     * }*/

                    if (outCommand > LIFT_OUT_COMMAND_T.LIFT_OUT_COMMAND_UP_DOWN) //如果读取到升降机异常, 不再向升降机发送命令
                    {
                        AGVLog.WriteInfo("升降机异常 " + outCommand, new StackFrame(true));
                        continue;
                    }

                    if (dataCommand[0] > 0)
                    {
                        sendCommand(dataCommand);
                        dataCommand[0] = 0;
                        dataCommand[1] = 0;   //清空数据
                    }
                } catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    handleLiftComException();
                }

                Thread.Sleep(200);
            }
        }
Пример #4
0
        public static bool setForkCtrlWithPrompt(ForkLiftWrapper fl, int ctrl)
        {
            string cmd = "cmd=pause;pauseStat=" + ctrl;

            try {
                fl.getAGVSocketClient().SendMessage(cmd);
            } catch {
                Console.WriteLine("setForkCtrlWithPrompt forklift " + fl.getForkLift().id + "cmd = " + cmd + "failed");
                AGVLog.WriteInfo("setForkCtrlWithPrompt forklift " + fl.getForkLift().id + "cmd = " + cmd + "failed", new StackFrame(true));
            }

            Console.WriteLine("setForkCtrlWithPrompt forklift " + fl.getForkLift().id + "cmd = " + cmd + "success");
            AGVLog.WriteInfo("setForkCtrlWithPrompt forklift " + fl.getForkLift().id + "cmd = " + cmd + "success", new StackFrame(true));
            return(true);
        }
Пример #5
0
        public static bool setForkCtrl(ForkLiftWrapper fl, int ctrl)
        {
            string cmd   = "cmd=pause;pauseStat=" + ctrl;
            int    times = 0;

            while (times < 3)
            {
                try {
                    fl.getAGVSocketClient().SendMessage(cmd);
                    break;
                } catch {
                    AGVMessage message = new AGVMessage();
                    message.setMessageType(AGVMessageHandler_TYPE_T.AGVMessageHandler_SENDPAUSE_ERR);
                    message.setMessageStr("发送中断错误");
                    AGVMessageHandler.getMessageHandler().setMessage(message);
                }
                times++;
            }
            Console.WriteLine("setForkCtrl forklift " + fl.getForkLift().id + "cmd = " + cmd);
            AGVLog.WriteInfo("setForkCtrl forklift " + fl.getForkLift().id + "cmd = " + cmd, new StackFrame(true));
            return(true);
        }