Example #1
0
 /// <summary>
 /// 检查小车入库状态
 /// </summary>
 /// <param name="piCrnNo"></param>
 /// <returns></returns>
 private bool Check_Car_Status_IsOk(string carNo, string serviceName)
 {
     try
     {
         object[] obj      = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CarStatus" + carNo));
         object[] obj1     = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "WriteFinished"));
         object[] obj2     = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "TaskFinished" + carNo));
         int      TaskFlag = int.Parse(obj1[0].ToString());
         int      CarMode  = int.Parse(obj[0].ToString());
         int      TaskType = int.Parse(obj[12].ToString());
         //int CraneAlarmCode = int.Parse(obj[0].ToString());
         string TaskNo = ConvertStringChar.BytesToString(obj2);
         if (CarMode == 1 && TaskType == 0 && TaskFlag == 0 && TaskNo == "")
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         Logger.Error("检查小车" + carNo + "状态时出现错误:" + ex.Message);
         return(false);
     }
 }
Example #2
0
 /// <summary>
 /// 检查堆垛机入库状态
 /// </summary>
 /// <param name="piCrnNo"></param>
 /// <returns></returns>
 private bool CheckCraneStatus(int craneNo, bool blnOut)
 {
     try
     {
         string serviceName = "CranePLC" + craneNo;
         string nState      = ObjectUtil.GetObject(WriteToService(serviceName, "nState")).ToString();
         if (nState.Equals("0"))
         {
             //堆垛机就地模式指示(值:0-工作模式或1-就地模式,不接受任务)
             string b_I_Local = ObjectUtil.GetObject(WriteToService(serviceName, "b_I_Local")).ToString();
             //堆垛机当前运行模式指示1:自动模式0:半自动模式
             string b_I_Auto = ObjectUtil.GetObject(WriteToService(serviceName, "b_I_Auto")).ToString();
             //任务号
             string ReadTaskNo    = ConvertStringChar.BytesToString((byte[])WriteToService(serviceName, "ReadTaskNo"));
             string b_I_Fork_Zero = ObjectUtil.GetObject(WriteToService(serviceName, "b_I_Fork_Zero")).ToString();
             string ErrCode       = ObjectUtil.GetObject(WriteToService(serviceName, "nAlarmCode")).ToString();
             string TaskFinish    = ObjectUtil.GetObject(WriteToService(serviceName, "TaskFinish")).ToString();
             string CarTaskNo     = "";
             if (blnOut)
             {
             }
             if (nState.Equals("0") && b_I_Local.Equals("0") && b_I_Auto.Equals("1") && ReadTaskNo == "" && CarTaskNo == "" && b_I_Fork_Zero == "1" && ErrCode == "0" && (TaskFinish.ToLower().Equals("false") || TaskFinish.Equals("0"))) //  && TaskFinish.Equals("1")
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex.Message);
         return(false);
     }
 }
Example #3
0
        private void ShowAlarm(StateItem Item)
        {
            try
            {
                object o = ObjectUtil.GetObject(Item.State);
                if (o == null)
                {
                    return;
                }
                string CraneNo        = Item.Name.Replace("CranePLC", "");
                string strWarningCode = ObjectUtil.GetObject(Item.State).ToString();
                if (strWarningCode != "0")
                {
                    string strTaskNo = ConvertStringChar.BytesToString((byte[])WriteToService(Item.Name, "ReadTaskNo"));

                    DataRow[] drs = dtCraneErr.Select(string.Format("WARNCODE='{0}'", strWarningCode));

                    string strError = "";
                    if (drs.Length > 0)
                    {
                        strError = drs[0]["WARNDESC"].ToString();
                    }
                    else
                    {
                        strError = "未知错误!错误号:" + strWarningCode;
                    }
                    Logger.Error("第" + CraneNo + "堆垛机 " + strError);
                    if (strWarningCode == "505" || strWarningCode == "506")//重入异常
                    {
                        bll.ExecNonQueryTran("WCS.SPHandleTaskError", new DataParameter[] { new DataParameter("VTASKNO", strTaskNo), new DataParameter("VERRORCODE", strWarningCode) });
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("CraneProcess处理堆垛机ShowAlarm异常:" + ex.Message);
            }
        }
Example #4
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            switch (stateItem.ItemName)
            {
            case "101_TaskNo":
                object[] obj = ObjectUtil.GetObjects(stateItem.State);
                if (obj == null)
                {
                    return;
                }
                string TaskNo = obj[0].ToString() + obj[1].ToString().PadLeft(4, '0') + obj[2].ToString().PadLeft(4, '0');
                if (TaskNo.Length > 0)
                {
                    string StationNo     = stateItem.ItemName.Substring(0, 3);
                    string PalletBarcode = ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService(stateItem.Name, StationNo + "_RPalletCode")));

                    try
                    {
                        DataParameter[] param = new DataParameter[] { new DataParameter("{0}", "State='2',Covey_FinishDate=getdate()"), new DataParameter("{1}", string.Format("TaskNo='{0}'", TaskNo)) };
                        bll.ExecNonQueryTran("WCS.UpdateTaskState", param);
                        Logger.Info("任务号:" + TaskNo + " 聊箱号:" + PalletBarcode + " 到达入库站台:" + StationNo);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("InStockToStationProcess出错,原因:" + ex.Message);
                    }
                }
                break;

            case "TaskNo":
                string ReadTaskNo = stateItem.State.ToString();
                //下达输送线入库任务

                try
                {
                    DataParameter[] parameter = new DataParameter[] { new DataParameter("{0}", string.Format("WCS_Task.TaskType='11'and WCS_Task.State='0' and TaskNo='{0}'", ReadTaskNo)) };
                    DataTable       dt        = bll.FillDataTable("WCS.SelectTask", parameter);
                    if (dt.Rows.Count > 0)
                    {
                        string ConveyID    = dt.Rows[0]["ConveyFromStation"].ToString();
                        string PalletCode  = dt.Rows[0]["PalletCode"].ToString();
                        string Destination = dt.Rows[0]["ConveyToStation"].ToString();
                        int[]  iTaskNo     = new int[3];
                        iTaskNo[0] = int.Parse(ReadTaskNo.Substring(0, 2));
                        iTaskNo[1] = int.Parse(ReadTaskNo.Substring(2, 4));
                        iTaskNo[2] = int.Parse(ReadTaskNo.Substring(6, 4));
                        WriteToService(ConveyServer, ConveyID + "_WTaskNo", iTaskNo);
                        WriteToService(ConveyServer, ConveyID + "_WPalletCode", PalletCode);
                        WriteToService(ConveyServer, ConveyID + "_Destination", Destination);     //目的地
                        if (WriteToService(ConveyServer, ConveyID + "_WriteFinished", 1))
                        {
                            bll.ExecNonQuery("WCS.UpdateTaskState", new DataParameter[] { new DataParameter("{0}", "State=1,Convey_StartDate=getdate()"), new DataParameter("{1}", string.Format("TaskNo='{0}'", ReadTaskNo)) });
                            Logger.Info("任务号:" + ReadTaskNo + " 料箱号:" + PalletCode + " 已下输送线:" + ConveyID + " 目的地址:" + Destination);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("InStockToStationProcess出错,下达输送入库任务出错,原因:" + ex.Message);
                }


                break;
            }
        }
Example #5
0
        private void tmCraneWorker(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                tmCraneErr.Stop();

                for (int i = 1; i <= dtCrane.Rows.Count; i++)
                {
                    if (dtCrane.Rows[i - 1]["ISENABLED"].ToString() == "0")
                    {
                        continue;
                    }

                    string serviceName = "CranePLC" + i;
                    int    ErrCode     = int.Parse(ObjectUtil.GetObject(context.ProcessDispatcher.WriteToService(serviceName, "nAlarmCode")).ToString());

                    if (ErrCode == 0)
                    {
                        continue;
                    }
                    if (ErrCode == 505)
                    {
                        string    plcTaskNo = ConvertStringChar.BytesToString(ObjectUtil.GetObjects(context.ProcessDispatcher.WriteToService(serviceName, "ReadTaskNo")));
                        DataTable dtTask    = bll.FillDataTable("WCS.SelectWmsTask", new DataParameter[] { new DataParameter("{0}", string.Format("TASKID='{0}' and ASRSID='{1}'", plcTaskNo, i)) });
                        if (dtTask.Rows.Count > 0)
                        {
                            string    TaskType      = dtTask.Rows[0]["TASKTYPE"].ToString();
                            string    plcPalletCode = dtTask.Rows[0]["PALLETID"].ToString();
                            DataTable dtErr         = bll.FillDataTable("WCS.SelectWmsSend", new DataParameter[] { new DataParameter("{0}", string.Format("TASKID='{0}'", plcTaskNo)) });
                            if (dtErr.Rows.Count > 0)
                            {
                                string Taskstatus = dtErr.Rows[0]["TASKSTATUS"].ToString();
                                if (Taskstatus == "4")
                                {
                                    //crane.ErrCode == 505,重入异常
                                    if (TaskType == "OB")
                                    {
                                        continue;
                                    }

                                    bll.ExecNonQueryTran("WCS.SPCancelTask", new DataParameter[] { new DataParameter("VTASKNO", plcTaskNo) });
                                    Logger.Info("入库任务:" + plcTaskNo + "托盘编号:" + plcPalletCode + "取消!");
                                    DataTable dtTaskNew = bll.FillDataTable("WCS.SelectWmsTask", new DataParameter[] { new DataParameter("{0}", string.Format("PALLETID='{0}' AND TASKSTATUS='0' AND ASRSID='{1}'", plcPalletCode, i)) });
                                    if (dtTaskNew.Rows.Count > 0)
                                    {
                                        string  TaskNo  = dtTaskNew.Rows[0]["TASKID"].ToString();
                                        sbyte[] staskNo = new sbyte[20];
                                        Util.ConvertStringChar.stringToBytes(TaskNo, 12).CopyTo(staskNo, 0);
                                        Util.ConvertStringChar.stringToBytes(plcPalletCode, 8).CopyTo(staskNo, 12);
                                        string strDLocation = dtTaskNew.Rows[0]["DLOCATION"].ToString();
                                        int[]  Location     = new int[6];
                                        Location[0] = 0;
                                        Location[1] = 0;
                                        Location[2] = 0;
                                        Location[3] = int.Parse(strDLocation.Split('-')[0]);
                                        Location[4] = int.Parse(strDLocation.Split('-')[1]);
                                        int ToRow = int.Parse(strDLocation.Split('-')[2]);
                                        if (ToRow > 1)
                                        {
                                            ToRow += 1;
                                        }
                                        Location[5] = ToRow;

                                        context.ProcessDispatcher.WriteToService(serviceName, "Address", Location);
                                        context.ProcessDispatcher.WriteToService(serviceName, "WriteTask", staskNo);
                                        if (context.ProcessDispatcher.WriteToService(serviceName, "WriteFinish", true))
                                        {
                                            bll.ExecNonQueryTran("WCS.SPReciveWmsTask", new DataParameter[] { new DataParameter("VTASKNO", TaskNo) });
                                            //更新WCSTask状态为3
                                            bll.ExecNonQuery("WCS.UpdateWCSTaskState", new DataParameter[] { new DataParameter("{0}", 3), new DataParameter("{1}", TaskNo) });
                                            Logger.Info("入库任务:" + TaskNo + " 托盘编号:" + plcPalletCode + " 位:" + strDLocation + " 已下发给" + i + "堆垛机");
                                        }
                                        else
                                        {
                                            Logger.Error("入库任务:" + TaskNo + " 托盘编号:" + plcPalletCode + " 无法写入堆垛机" + i);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("MainServer中tmCraneWorker出现异常:" + ex.Message);
            }
            finally
            {
                tmCraneErr.Start();
            }
        }
Example #6
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            object obj = ObjectUtil.GetObject(stateItem.State);

            if (obj == null)
            {
                return;
            }

            if (stateItem.ItemName.IndexOf("nAlarmCode") >= 0)
            {
                int CraneNo = int.Parse(stateItem.Name.Replace("CranePLC", "")) * 2;
                ShowLedMessage(CraneNo.ToString(), stateItem);
                return;
            }
            string ItemNo = stateItem.ItemName.Split('_')[0];

            ShowLedMessage(GetLedNo(int.Parse(ItemNo)), stateItem);

            try
            {
                if (stateItem.ItemName.IndexOf("TaskNo") >= 0 && (ItemNo == "102" || ItemNo == "106" || ItemNo == "110" || ItemNo == "114" || ItemNo == "118" || ItemNo == "103" || ItemNo == "107" || ItemNo == "111" || ItemNo == "115" || ItemNo == "119"))
                {
                    string Tasks = ConvertStringChar.BytesToString(ObjectUtil.GetObjects(stateItem.State));
                    Tasks = Tasks.PadRight(26, ' ');
                    string TaskNo = Tasks.Substring(0, 10).Trim();
                    if (TaskNo.Length > 0)
                    {
                        BLL.BLLBase bll    = new BLL.BLLBase();
                        DataTable   dtTask = bll.FillDataTable("WCS.SelectWCSTask", new DataParameter[] { new DataParameter("{0}", string.Format("TaskID='{0}'", TaskNo)) });
                        if (dtTask.Rows.Count > 0)
                        {
                            string PalletCode = dtTask.Rows[0]["PALLETID"].ToString();
                            switch (ItemNo)
                            {
                            case "102":
                            case "106":
                            case "110":
                            case "114":
                            case "118":
                                //更新WCS_Task入库状态
                                bll.ExecNonQuery("WCS.UpdateWCSTaskStateByStatus", new DataParameter[] { new DataParameter("{0}", "2"), new DataParameter("{1}", TaskNo), new DataParameter("{2}", 1) });
                                Logger.Info("入库任务:" + TaskNo + "托盘编号:" + PalletCode + "到达入库端!");
                                break;

                            case "103":
                            case "107":
                            case "111":
                            case "115":
                            case "119":
                                //更新出库完成
                                bll.ExecNonQueryTran("WCS.SpTaskFinished", new DataParameter[] { new DataParameter("VTaskNo", TaskNo) });
                                Logger.Info("出库任务:" + TaskNo + "托盘编号:" + PalletCode + "完成任务!");
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("LEDProcess中StateChanged出现异常" + ex.Message);
            }
        }
Example #7
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            switch (stateItem.ItemName)
            {
            case "TaskFinished01":
            case "TaskFinished02":
                object[] obj = ObjectUtil.GetObjects(stateItem.State);

                if (obj == null)
                {
                    return;
                }
                string TaskNo = ConvertStringChar.BytesToString(obj);
                {
                    //存储过程处理
                    if (TaskNo.Length > 0)
                    {
                        byte[] b = new byte[30];
                        ConvertStringChar.stringToByte("", 30).CopyTo(b, 0);
                        WriteToService(stateItem.Name, stateItem.ItemName, b);

                        Logger.Info(stateItem.ItemName + "完成标志,任务号:" + TaskNo);
                        DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", TaskNo) };
                        bll.ExecNonQueryTran("WCS.Sp_TaskProcess", param);
                    }
                    //上报总控WCS,下架完成
                }
                break;

            case "CarAlarm01":
            case "CarAlarm02":
                object obj1 = ObjectUtil.GetObject(stateItem.State);
                if (obj1 == null)
                {
                    return;
                }
                if (obj1.ToString() != "0")
                {
                    string    strError = "";
                    DataRow[] drs      = dtDeviceAlarm.Select(string.Format("Flag=2 and AlarmCode={0}", obj1.ToString()));
                    if (drs.Length > 0)
                    {
                        strError = drs[0]["AlarmCode"].ToString();
                    }
                    else
                    {
                        strError = "穿梭车未知错误!";
                    }
                    Logger.Error(strError);
                }
                break;

            case "ElevatorAlarm":
                object obj2 = ObjectUtil.GetObject(stateItem.State);
                if (obj2 == null)
                {
                    return;
                }
                if (obj2.ToString() != "0")
                {
                    string    strError = "";
                    DataRow[] drs      = dtDeviceAlarm.Select(string.Format("Flag=3 and AlarmCode={0}", obj2.ToString()));
                    if (drs.Length > 0)
                    {
                        strError = drs[0]["AlarmCode"].ToString();
                    }
                    else
                    {
                        strError = "提升机未知错误!";
                    }
                    Logger.Error(strError);
                }
                break;

            case "Run":
                blRun = (int)stateItem.State == 1;
                if (blRun)
                {
                    tmWorkTimer.Start();
                    Logger.Info("提升机联机");
                }
                else
                {
                    tmWorkTimer.Stop();
                    Logger.Info("提升机脱机");
                }
                break;

            default:
                break;
            }


            return;
        }
Example #8
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            switch (stateItem.ItemName)
            {
            case "TaskFinished01":
            case "TaskFinished02":
                object[] obj = ObjectUtil.GetObjects(stateItem.State);

                if (obj == null)
                {
                    return;
                }
                string TaskNo = ConvertStringChar.BytesToString(obj);

                //存储过程处理
                if (TaskNo.Length > 0)
                {
                    DataParameter[] para = new DataParameter[] { new DataParameter("{0}", string.Format("Task.TaskNo='{0}'", TaskNo)) };
                    DataTable       dt   = bll.FillDataTable("WCS.SelectElevatorTask", para);
                    if (dt.Rows.Count > 0)
                    {
                        string TaskType = dt.Rows[0]["TaskType"].ToString();


                        if (TaskType == "12")
                        {
                            bll.ExecNonQuery("WCS.UpdateCellEmpty", new DataParameter[] { new DataParameter("@CellCode", dt.Rows[0]["CellCode"].ToString()) });
                            bll.ExecNonQuery("WCS.UpdateTaskByFilter", new DataParameter[] { new DataParameter("{0}", "State=11,Car_FinishDate=getdate()"), new DataParameter("{1}", string.Format("TaskNo='{0}'", TaskNo)) });
                        }
                        else
                        {
                            DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", TaskNo) };
                            bll.ExecNonQueryTran("WCS.Sp_TaskProcess", param);
                        }
                    }

                    byte[] b = new byte[30];
                    ConvertStringChar.stringToByte("", 30).CopyTo(b, 0);
                    WriteToService(stateItem.Name, stateItem.ItemName, b);
                    Logger.Info(stateItem.ItemName + "完成标志,任务号:" + TaskNo);
                }

                break;

            case "Run":
                blRun = (int)stateItem.State == 1;
                if (blRun)
                {
                    tmWorkTimer.Start();
                    Logger.Info("换层提升机联机");
                }
                else
                {
                    tmWorkTimer.Stop();
                    Logger.Info("换层提升机脱机");
                }
                break;

            default:
                break;
            }
        }
Example #9
0
        /// <summary>
        /// 堆垛机任务完成处理
        /// </summary>
        private void TaskFinishProcess(StateItem Item)
        {
            object obj = ObjectUtil.GetObject(Item.State);

            if (obj == null)
            {
                return;
            }
            string TaskFinish = obj.ToString();

            if (TaskFinish.Equals("False") || TaskFinish.Equals("0"))
            {
                return;
            }

            int CraneNo = int.Parse(Item.Name.Replace("CranePLC", ""));

            try
            {
                string TaskNo = ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService(Item.Name, "ReadTaskNo")));

                if ((TaskFinish.Equals("True") || TaskFinish.Equals("1")) && TaskNo != "")
                {
                    DataTable dtTask = bll.FillDataTable("WCS.SelectWCSTask", new DataParameter[] { new DataParameter("{0}", string.Format("TASKID='{0}' and ASRSID='{1}'", TaskNo, CraneNo)) });
                    if (dtTask.Rows.Count > 0)
                    {
                        DataRow dr         = dtTask.Rows[0];
                        string  TaskType   = dtTask.Rows[0]["TASKTYPE"].ToString();
                        string  PalletCode = dtTask.Rows[0]["PALLETID"].ToString();
                        if (TaskType == "IB")//入库
                        {
                            //更新入库完成
                            bll.ExecNonQueryTran("WCS.SpTaskFinished", new DataParameter[] { new DataParameter("VTaskNo", TaskNo) });
                            sbyte[] taskNo = new sbyte[20];
                            ConvertStringChar.stringToBytes("", 20).CopyTo(taskNo, 0);
                            WriteToService(Item.Name, "GetRequest", false);
                            WriteToService(Item.Name, "PutRequest", false);
                            WriteToService(Item.Name, "ClearTaskNo", taskNo);
                            WriteToService(Item.Name, "TaskFinish", false);
                            Logger.Info("第" + CraneNo + "堆垛机入库任务:" + TaskNo + "托盘编号:" + PalletCode + "任务完成!");
                        }
                        else if (TaskType == "OB")//出库
                        {
                            //更新任务状态
                            bll.ExecNonQuery("WCS.UpdateWCSTaskState", new DataParameter[] { new DataParameter("{0}", 2), new DataParameter("{1}", TaskNo) });

                            //更新堆垛机PLC
                            sbyte[] taskNo = new sbyte[20];
                            ConvertStringChar.stringToBytes("", 20).CopyTo(taskNo, 0);

                            WriteToService(Item.Name, "GetRequest", false);
                            WriteToService(Item.Name, "PutRequest", false);
                            WriteToService(Item.Name, "ClearTaskNo", taskNo);
                            WriteToService(Item.Name, "TaskFinish", false);
                            Logger.Info("第" + CraneNo + "堆垛机出库任务:" + TaskNo + "托盘编号:" + PalletCode + "堆垛机任务完成!");
                            //下载任务到输送线。
                            int CarItem = 104 + (CraneNo - 1) * 4;

                            sbyte[]  staskNo = new sbyte[26];
                            string[] LedMsgs = dtTask.Rows[0]["LEDNO"].ToString().Split(',');
                            ConvertStringChar.stringToBytes(TaskNo, 10).CopyTo(staskNo, 0);
                            ConvertStringChar.stringToBytes(LedMsgs[0], 8).CopyTo(staskNo, 10);
                            ConvertStringChar.stringToBytes(LedMsgs[1], 8).CopyTo(staskNo, 18);
                            WriteToService("CarPLC", CarItem + "_WriteTaskNo", staskNo);

                            if (WriteToService("CarPLC", CarItem + "_WriteFinished", 1))
                            {
                                bll.ExecNonQuery("WCS.UpdateWCSTaskState", new DataParameter[] { new DataParameter("{0}", 3), new DataParameter("{1}", TaskNo) });
                                Logger.Info("出库任务:" + TaskNo + "托盘编号:" + PalletCode + "任务下达" + CarItem + "输送线!");
                            }
                        }
                        else
                        {
                            //更新入库完成
                            bll.ExecNonQueryTran("WCS.SpTaskFinished", new DataParameter[] { new DataParameter("VTaskNo", TaskNo) });
                            sbyte[] taskNo = new sbyte[20];
                            WriteToService(Item.Name, "GetRequest", false);
                            WriteToService(Item.Name, "PutRequest", false);
                            ConvertStringChar.stringToBytes("", 20).CopyTo(taskNo, 0);
                            WriteToService(Item.Name, "ClearTaskNo", taskNo);
                            WriteToService(Item.Name, "TaskFinish", false);
                            Logger.Info("第" + CraneNo + "堆垛机任务:" + TaskNo + "托盘编号:" + PalletCode + "任务完成!");
                        }
                    }
                    else
                    {
                        WriteToService(Item.Name, "TaskFinish", false);
                        Logger.Error("CraneProcess第" + CraneNo + "堆垛机任务号:" + TaskNo + "在任务表中没有找到,请查询任务!");
                    }
                }
                else
                {
                    Logger.Error("CraneProcess第" + CraneNo + "堆垛机任务号为空!");
                }
            }
            catch (Exception ex)
            {
                Logger.Error("CraneProcess 第" + CraneNo + "堆垛机Finish:" + ex.Message);
            }
        }
Example #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="craneNo"></param>
        private void CraneIn(int craneNo)
        {
            try
            {
                if (!CheckCraneStatus(craneNo, false))
                {
                    return;
                }
                dicCranStatus[craneNo] = 1;
            }
            catch (Exception e)
            {
                dicCranStatus[craneNo] = 1;
                Logger.Error("CraneProcess中CraneIn状态检查错误:" + e.Message.ToString());
                return;
            }
            try
            {
                string Server  = ServerName + craneNo.ToString();
                int    CarItem = 102 + (craneNo - 1) * 4;
                string TaskNos = ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService("CarPLC", CarItem.ToString() + "_TaskNo"))).PadLeft(27, ' ');
                if (TaskNos != "")
                {
                    string    TaskNo = TaskNos.Substring(0, 10).Trim();
                    DataTable dtTask = bll.FillDataTable("WCS.SelectWCSTask", new DataParameter[] { new DataParameter("{0}", string.Format("TASKID='{0}' AND TASKSTATUS='2' AND ASRSID='{1}'", TaskNo, craneNo)) });

                    if (dtTask.Rows.Count > 0)
                    {
                        string  PalletCode = dtTask.Rows[0]["PALLETID"].ToString();
                        sbyte[] staskNo    = new sbyte[20];
                        Util.ConvertStringChar.stringToBytes(TaskNo, 12).CopyTo(staskNo, 0);
                        Util.ConvertStringChar.stringToBytes(PalletCode, 8).CopyTo(staskNo, 12);
                        string strDLocation = dtTask.Rows[0]["DLOCATION"].ToString();
                        int[]  Location     = new int[6];
                        Location[0] = 2 * craneNo - 1;
                        Location[1] = 0;
                        Location[2] = 2;
                        Location[3] = int.Parse(strDLocation.Split('-')[0]);
                        Location[4] = int.Parse(strDLocation.Split('-')[1]);
                        int ToRow = int.Parse(strDLocation.Split('-')[2]);
                        if (ToRow > 1)
                        {
                            ToRow += 1;
                        }
                        Location[5] = ToRow;
                        WriteToService(Server, "Address", Location);
                        WriteToService(Server, "WriteTask", staskNo);
                        if (WriteToService(Server, "WriteFinish", true))
                        {
                            //更新WCSTask状态为3
                            bll.ExecNonQuery("WCS.UpdateWCSTaskState", new DataParameter[] { new DataParameter("{0}", 3), new DataParameter("{1}", TaskNo) });
                            Logger.Info("入库任务:" + TaskNo + " 托盘编号:" + PalletCode + " 位:" + strDLocation + " 已下发给第" + craneNo + "堆垛机");
                        }
                        else
                        {
                            Logger.Error("CraneProcess入库任务:" + TaskNo + " 托盘编号:" + PalletCode + " 无法写入堆垛机" + craneNo);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("CraneProcess中CraneIn异常:" + ex.Message);
                return;
            }
        }
Example #11
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            object obj = ObjectUtil.GetObject(stateItem.State);

            if (obj == null)
            {
                return;
            }
            int ItemNo = 0;

            if (stateItem.ItemName.IndexOf("nAlarmCode") >= 0)
            {
                int CraneNo = int.Parse(stateItem.Name.Replace("CranePLC", ""));
                ItemNo = 104 + (CraneNo - 1) * 4;
                string Text = GetLedMessage((2 * CraneNo).ToString(), ItemNo.ToString(), stateItem);
                RefreshLedShow(CraneNo.ToString(), Text, false);
                return;
            }
            else
            {
                ItemNo = int.Parse(stateItem.ItemName.Split('_')[0]);
                string LedNo = GetLedNo(ItemNo);
                string Text  = GetLedMessage(LedNo, ItemNo.ToString(), stateItem);
                bool   blnUp = true;
                if (ItemNo % 2 == 0)
                {
                    blnUp = false;
                }
                RefreshLedShow(LedNo, Text, blnUp);
            }
            try
            {
                if (stateItem.ItemName.IndexOf("TaskNo") >= 0 && (ItemNo == 102 || ItemNo == 106 || ItemNo == 110 || ItemNo == 114 || ItemNo == 118 || ItemNo == 103 || ItemNo == 107 || ItemNo == 111 || ItemNo == 115 || ItemNo == 119))
                {
                    string Tasks = ConvertStringChar.BytesToString(ObjectUtil.GetObjects(stateItem.State));
                    Tasks = Tasks.PadRight(26, ' ');
                    if (Tasks.Length > 0)
                    {
                        string      TaskNo = Tasks.Substring(0, 10);
                        BLL.BLLBase bll    = new BLL.BLLBase();
                        DataTable   dtTask = bll.FillDataTable("WCS.SelectWCSTask", new DataParameter[] { new DataParameter("{0}", string.Format("TaskID='{0}'", TaskNo)) });
                        if (dtTask.Rows.Count > 0)
                        {
                            string PalletCode = dtTask.Rows[0]["PALLETID"].ToString();
                            switch (ItemNo)
                            {
                            case 102:
                            case 106:
                            case 110:
                            case 114:
                            case 118:
                                //更新WCS_Task入库状态
                                bll.ExecNonQuery("WCS.UpdateWCSTaskStateByStatus", new DataParameter[] { new DataParameter("{0}", "2"), new DataParameter("{1}", TaskNo), new DataParameter("{2}", 1) });
                                Logger.Info("入库任务:" + TaskNo + "托盘编号:" + PalletCode + "到达入库端!");
                                break;

                            case 103:
                            case 107:
                            case 111:
                            case 115:
                            case 119:
                                //更新出库完成
                                bll.ExecNonQueryTran("WCS.SpTaskFinished", new DataParameter[] { new DataParameter("VTaskNo", TaskNo) });
                                Logger.Info("出库任务:" + TaskNo + "托盘编号:" + PalletCode + "完成任务!");
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("LEDProcess中StateChanged出现异常" + ex.Message);
            }
        }
Example #12
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            switch (stateItem.ItemName)
            {
            case "TaskFinished01":
            case "TaskFinished02":


                try
                {
                    object[] obj = ObjectUtil.GetObjects(stateItem.State);

                    Logger.Debug("收到完成信号,PLC编号:" + stateItem.Name + "小车号:" + stateItem.ItemName + "任务号:" + ConvertStringChar.BytesToString(obj));
                    if (obj == null)
                    {
                        return;
                    }
                    string TaskNo = ConvertStringChar.BytesToString(obj);

                    //存储过程处理
                    if (TaskNo.Length > 0)
                    {
                        byte[] b = new byte[30];
                        ConvertStringChar.stringToByte("", 30).CopyTo(b, 0);
                        WriteToService(stateItem.Name, stateItem.ItemName, b);

                        Logger.Info(stateItem.ItemName + "完成标志,任务号:" + TaskNo);
                        DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", TaskNo) };
                        bll.ExecNonQueryTran("WCS.Sp_TaskProcess", param);

                        DataParameter[] para = new DataParameter[] { new DataParameter("{0}", string.Format("WCS_Task.TaskNo='{0}'", TaskNo)) };
                        DataTable       dt   = bll.FillDataTable("WCS.SelectTask", para);

                        if (dt.Rows.Count > 0)
                        {
                            string TaskType = dt.Rows[0]["TaskType"].ToString();
                            if (TaskType == "12")
                            {
                                string Barcode = dt.Rows[0]["PalletBarcode"].ToString();
                                byte[] barcode = new byte[20];
                                ConvertStringChar.stringToByte(Barcode, 20).CopyTo(barcode, 0);
                                WriteToService(stateItem.Name, "OutLocation01", barcode);
                            }
                        }

                        report.Send2MJWcs(base.Context, 3, TaskNo);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("小车完成过程中出错" + ex.ToString());
                }
                //上报总控WCS,下架完成

                break;

            case "Run":
                blRun = (int)stateItem.State == 1;
                if (blRun)
                {
                    tmWorkTimer.Start();
                    Logger.Info("提升机联机");
                }
                else
                {
                    tmWorkTimer.Stop();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    Logger.Info("提升机脱机");
                }
                break;

            default:
                break;
            }
        }
Example #13
0
 protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
 {
     try
     {
         object obj = ObjectUtil.GetObject(stateItem.State);
         if (obj == null)
         {
             return;
         }
         if (obj.ToString() == "0")
         {
             return;
         }
         string ItemNo     = stateItem.ItemName.Substring(0, 3);
         string PalletCode = ConvertStringChar.BytesToString((byte[])WriteToService(stateItem.Name, ItemNo + "_PalletCode"));
         string RoadNo     = GetRoadNo(ItemNo);
         if (PalletCode.Length > 0)
         {
             BLL.BLLBase bll    = new BLL.BLLBase();
             DataTable   dtTask = bll.FillDataTable("WCS.SelectWMSTask", new DataParameter[] { new DataParameter("{0}", string.Format("TASKSTATUS in ('0','3') AND TASKTYPE='IB' AND PALLETID='{1}' ", RoadNo, PalletCode)) });
             if (dtTask.Rows.Count > 0)
             {
                 string ASRSID = dtTask.Rows[0]["ASRSID"].ToString();
                 if (ASRSID == RoadNo)
                 {
                     string   TaskNo     = dtTask.Rows[0]["TASKID"].ToString();
                     string   TaskStatus = dtTask.Rows[0]["TASKSTATUS"].ToString();
                     sbyte[]  staskNo    = new sbyte[26];
                     string[] LedMsgs    = dtTask.Rows[0]["LEDNO"].ToString().Split(',');
                     ConvertStringChar.stringToBytes(TaskNo, 10).CopyTo(staskNo, 0);
                     ConvertStringChar.stringToBytes(LedMsgs[0], 8).CopyTo(staskNo, 10);
                     ConvertStringChar.stringToBytes(LedMsgs[1], 8).CopyTo(staskNo, 18);
                     WriteToService(stateItem.Name, ItemNo + "_WriteTaskNo", staskNo);
                     if (WriteToService(stateItem.Name, ItemNo + "_WriteFinished", 1))
                     {
                         //插入WCS_Task
                         if (TaskStatus == "0")
                         {
                             bll.ExecNonQueryTran("WCS.SPReciveWmsTask", new DataParameter[] { new DataParameter("VTASKNO", TaskNo) });
                         }
                         Logger.Info("第" + RoadNo.ToString() + "排托盘编号:" + PalletCode + "开始入库");
                     }
                 }
                 else
                 {
                     if (WriteToService(stateItem.Name, ItemNo + "_WriteFinished", 2))
                     {
                         // Logger.Error("第" + RoadNo.ToString() + "排托盘编号:" + PalletCode + "巷道不符!");
                     }
                 }
             }
             else
             {
                 if (WriteToService(stateItem.Name, ItemNo + "_WriteFinished", 6))
                 {
                 }
             }
         }
     }
     catch (Exception e)
     {
         Logger.Error("CarProcess:" + e.Message);
     }
 }