Exemple #1
0
 private void btnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         IList <CallBoxInfo> AllCallBox = bsDetail.List as IList <CallBoxInfo>;
         int NewBoxID = 1;
         if (AllCallBox != null && AllCallBox.Count > 0)
         {
             NewBoxID = AllCallBox.Max(p => p.CallBoxID) + 1;
         }
         CallBoxInfo NewBoxInfo = new CallBoxInfo();
         NewBoxInfo.CallBoxID = NewBoxID;
         NewBoxInfo.IsNew     = true;
         using (FrmCallBoxDetail frm = new FrmCallBoxDetail(AllCallBox, NewBoxInfo))
         {
             frm.ShowDialog();
             if (frm.DialogResult == DialogResult.OK)
             {
                 bsDetail.DataSource = AGVDAccess.AGVClientDAccess.LoadAllCallBoxs();
                 bsDetail.ResetBindings(false);
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
        private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                gvDetail.CloseEditor();
                labelControl1.Focus();
                if (!Valid())
                {
                    return;
                }
                CallBoxInfo           CurrCallBox      = bsCallBox.Current as CallBoxInfo;
                IList <CallBoxDetail> AllCallBoxDetail = bsCallDetail.List as IList <CallBoxDetail>;
                if (CurrCallBox != null && AllCallBoxDetail != null && AllCallBoxDetail.Count > 0)
                {
                    if (CurrCallBox.IsNew && AllCallBox.Where(p => p.CallBoxID == CurrCallBox.CallBoxID).Count() > 0)
                    {
                        MsgBox.ShowWarn("呼叫器ID已存在!");
                        return;
                    }

                    CurrCallBox.CallBoxDetails = AllCallBoxDetail;
                    OperateReturnInfo opr = AGVDAccess.AGVClientDAccess.SaveCallBox(CurrCallBox);
                    MsgBox.Show(opr);
                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            { MsgBox.ShowError(ex.Message); }
        }
 /// <summary>
 /// 服务端接收消息回调
 /// </summary>
 private void _server_ReceiveMes(object e)
 {
     try
     {
         lock (HandCallBoxlockObj)
         {
             NetEventArgs einfo = e as NetEventArgs;
             if (einfo == null)
             {
                 return;
             }
             List <byte> Message       = einfo.MesContent;
             AppSession  ClientSession = einfo.Session;
             if (Message == null || ClientSession == null)
             {
                 return;
             }
             //读开关输入状态
             LogHelper.WriteCallBoxLog("已接受到按钮呼叫!");
             string IP = ((IPEndPoint)ClientSession.ClientSocket.RemoteEndPoint).Address.ToString();
             LogHelper.WriteCallBoxLog("接受到按钮盒" + IP + "呼叫!");
             CallBoxInfo CallBox = CoreData.AllCallBoxes.FirstOrDefault(p => p.CallBoxIP == IP);
             if (CallBox != null && Message[0] == 0x01 && Message[1] == 0x02)//按钮盒呼叫
             {
                 LogHelper.WriteCallBoxLog("开始处理按钮盒子呼叫!");
                 HandleCallBoxRequest(e, CallBox);
             }
         }
     }
     catch (Exception ex)
     { LogHelper.WriteErrorLog(ex); }
 }
        /// <summary>
        /// 处理呼叫盒呼叫
        /// </summary>
        /// <param name="CallBoxID">呼叫盒ID</param>
        /// <param name="BtnID">按钮ID</param>
        /// <returns></returns>
        private bool HandleCallBoxMonitor(CallBoxInfo CallBox, CallBoxDetail CurrBoxDetail, int BtnID)
        {
            try
            {
                #region 处理监控功能
                //处理监控功能
                //监控功能则为更新储位的状态
                StorageInfo CallStore = CoreData.StorageList.FirstOrDefault(q => q.ID == CurrBoxDetail.LocationID);
                if (CallStore == null)
                {
                    LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "对应的监控储位");
                    return(false);
                }
                int StoreState = CurrBoxDetail.LocationState;
                if (CallStore.StorageState != StoreState)
                {
                    //更新数据库中的对应监控的储位状态信息
                    AGVServerDAccess.UpdateStorageState(StoreState, -1, CallStore.ID);
                    CallStore.StorageState = StoreState;
                }
                return(true);

                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteCallBoxLog("处理呼叫器监控异常:" + ex.Message);
                return(false);
            }
        }
 public FrmCallBoxDetail(IList <CallBoxInfo> AllCallBoxs, CallBoxInfo NewCallBoxInfo)
 {
     InitializeComponent();
     if (AllCallBoxs != null)
     {
         AllCallBox = AllCallBoxs;
     }
     if (NewCallBoxInfo != null)
     {
         NewCallBox = NewCallBoxInfo;
     }
 }
        /// <summary>
        /// 处理呼叫盒放行逻辑
        /// </summary>
        /// <returns></returns>
        private bool HandleCallBoxRelease(CallBoxInfo CallBox, CallBoxDetail CurrBoxDetail, int BtnID)
        {
            try
            {
                #region 处理呼叫器放行逻辑
                //接收到按钮盒放行命令
                //取出按钮对应监控的储位
                StorageInfo CallStore = CoreData.StorageList.FirstOrDefault(q => q.ID == CurrBoxDetail.LocationID);
                if (CallStore == null)
                {
                    LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "对应的监控储位");
                    return(false);
                }
                //然后将停靠监控储位地标上的AGV允许放行
                string WaintLandCode = CallStore.LankMarkCode;
                if (string.IsNullOrEmpty(WaintLandCode))
                {
                    LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "对应的监控储位地标");
                    return(false);
                }
                CarInfo WaitCar = CoreData.CarList.FirstOrDefault(p => p.CurrSite == Convert.ToInt32(WaintLandCode));
                if (WaitCar == null)
                {
                    LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应的监控储位地标上没有小车");
                    return(false);
                }
                if (string.IsNullOrEmpty(WaitCar.ExcuteTaksNo))
                {
                    LogHelper.WriteCreatTaskLog("放行地标上的小车没有可执行任务");
                    return(false);
                }
                AGVServerDAccess.ReleaseCarByCallBox(WaitCar.ExcuteTaksNo, WaitCar.CurrSite.ToString());
                return(true);

                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteCallBoxLog("处理呼叫器放行异常:" + ex.Message);
                return(false);
            }
        }
        private bool HandleCallBoxMonitor(CallBoxInfo CallBox, CallBoxDetail CurrBoxDetail, int staragestate, string codes = "")
        {
            try
            {
                lock (lockstorage)
                {
                    #region 处理监控功能
                    //处理监控功能
                    //监控功能则为更新储位的状态
                    DataTable dtstorage = CoreData.dbOperator.LoadDatas("QueryAllStore");
                    CoreData.StorageList = DataToObject.TableToEntity <StorageInfo>(dtstorage);
                    StorageInfo CallStore = CoreData.StorageList.FirstOrDefault(q => q.ID == CurrBoxDetail.LocationID);
                    if (CallStore == null)
                    {
                        LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "对应的监控储位");
                        return(false);
                    }
                    int StoreState = staragestate;
                    if (CallStore.StorageState != StoreState)
                    {
                        //更新数据库中的对应监控的储位状态信息
                        AGVServerDAccess.UpdateStorageState(StoreState, -1, CallStore.ID);
                        if (!string.IsNullOrEmpty(codes))
                        {
                            //更新备注
                            AGVServerDAccess.UpdteStorageRemark(CallStore.ID, codes);
                        }
                        //更新储位的名称 逗号分隔
                        CallStore.StorageState = StoreState;
                        CallStore.Remark       = codes;
                    }
                    return(true);

                    #endregion
                }
            }
            catch (Exception ex)
            {
                DelegateState.InvokeDispatchStateEvent(ex.Message);
                return(false);
            }
        }
Exemple #8
0
 private void btnDele_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         CallBoxInfo NewBoxInfo = bsDetail.Current as CallBoxInfo;
         if (NewBoxInfo != null)
         {
             if (MsgBox.ShowQuestion("确定删除当前项?") == DialogResult.Yes)
             {
                 OperateReturnInfo opr = AGVDAccess.AGVClientDAccess.DeleCallBox(NewBoxInfo);
                 MsgBox.Show(opr);
                 if (opr.ReturnCode == OperateCodeEnum.Success)
                 {
                     bsDetail.DataSource = AGVDAccess.AGVClientDAccess.LoadAllCallBoxs();
                     bsDetail.ResetBindings(false);
                 }
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
Exemple #9
0
 private void btnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         IList <CallBoxInfo> AllCallBox = bsDetail.List as IList <CallBoxInfo>;
         CallBoxInfo         NewBoxInfo = bsDetail.Current as CallBoxInfo;
         if (NewBoxInfo != null)
         {
             NewBoxInfo.IsNew          = false;
             NewBoxInfo.CallBoxDetails = AGVDAccess.AGVClientDAccess.LoadCallBoxDetails(NewBoxInfo);
             using (FrmCallBoxDetail frm = new FrmCallBoxDetail(AllCallBox, NewBoxInfo))
             {
                 frm.ShowDialog();
                 if (frm.DialogResult == DialogResult.OK)
                 {
                     bsDetail.DataSource = AGVDAccess.AGVClientDAccess.LoadAllCallBoxs();
                     bsDetail.ResetBindings(false);
                 }
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
Exemple #10
0
        /// <summary>
        /// 创建任务
        /// </summary>
        public string CreatTask(int CallBoxID, int BtnID)
        {
            try
            {
                CallBoxInfo BoxInfo = AGVSimulationDAccess.LoadAllCallBoxByID(CallBoxID);
                if (BoxInfo == null)
                {
                    return("未配置按钮盒档案信息");
                }
                IList <CallBoxDetail> BoxDetails = AGVSimulationDAccess.LoadCallBoxDetails(CallBoxID);
                if (BoxDetails == null || (BoxDetails != null && BoxDetails.Count <= 0))
                {
                    return("未配置按钮盒明细档案信息");
                }


                CallBoxDetail CurrBoxDetail = BoxDetails.FirstOrDefault(p => p.CallBoxID == CallBoxID && p.ButtonID == BtnID);
                if (CurrBoxDetail == null)
                {
                    return("当前按钮没有配置信息");
                }
                if (CurrBoxDetail.OperaType == 0)
                {
                    IList <TaskConfigDetail> TaskConfigDetails = AGVClientDAccess.load_TaskDetail(CurrBoxDetail.TaskConditonCode);
                    if (TaskConfigDetails == null && (TaskConfigDetails != null && TaskConfigDetails.Count <= 0))
                    {
                        return("当前按钮未配置任务信息");
                    }
                    //开始创建任务
                    StorageInfo CallStore = Stores.FirstOrDefault(q => q.ID == CurrBoxDetail.LocationID);
                    if (CallStore == null)
                    {
                        return("未设置当前按钮的监控储位!");
                    }
                    //CallStore.StorageState = CurrBoxDetail.LocationState;

                    ///后面再处理
                    if (AGVSimulationDAccess.ChekAllowCreatTask(CallBoxID, CallStore.LankMarkCode, 0) > 0)
                    {
                        return("存在未完成任务,请稍后再试!");
                    }
                    string           dispatchNo = Guid.NewGuid().ToString();
                    DispatchTaskInfo TaskInfo   = new DispatchTaskInfo();
                    TaskInfo.dispatchNo = dispatchNo;
                    TaskInfo.taskType   = 0;
                    TaskInfo.TaskState  = 0;
                    TaskInfo.CallLand   = CallStore.LankMarkCode;
                    TaskInfo.stationNo  = CallBoxID;
                    //创建任务明细
                    int DetailID      = 1;
                    int PreStoreState = -1;
                    foreach (TaskConfigDetail item in TaskConfigDetails)
                    {
                        DispatchTaskDetail taskDetail = new DispatchTaskDetail();
                        taskDetail.dispatchNo = dispatchNo;
                        taskDetail.DetailID   = DetailID;
                        //寻找目标地表
                        StorageInfo ArmStore = null;
                        if (item.ArmOwnArea == -1)
                        {
                            ArmStore = CallStore;
                        }
                        else
                        {
                            ArmStore = Stores.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType);
                        }
                        if (ArmStore == null)
                        {
                            return("任务条件不满足!");
                        }
                        taskDetail.LandCode      = ArmStore.LankMarkCode;
                        taskDetail.OperType      = item.Action;
                        taskDetail.PutType       = PreStoreState == -1 ? 0 : (PreStoreState == 1 ? 0 : 1);
                        taskDetail.IsAllowExcute = item.IsWaitPass;
                        taskDetail.State         = 0;
                        TaskInfo.TaskDetail.Add(taskDetail);
                        DetailID     += 1;
                        PreStoreState = ArmStore.StorageState;
                    }
                    OperateReturnInfo opr = AGVSimulationDAccess.SaveTask(TaskInfo);
                    if (opr.ReturnCode == OperateCodeEnum.Success)
                    {
                        foreach (TaskConfigDetail item in TaskConfigDetails)
                        {
                            StorageInfo ArmStore = Stores.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType);
                            if (ArmStore != null)
                            {
                                ArmStore.LockState = 2;
                            }
                        }
                    }
                    else
                    {
                        return(opr.ReturnInfo.ToString());
                    }
                }
                else if (CurrBoxDetail.OperaType == 1)
                {
                    CurrBoxDetail = BoxDetails.FirstOrDefault(p => p.CallBoxID == CallBoxID && p.ButtonID == BtnID);
                    if (CurrBoxDetail == null)
                    {
                        return("当前按钮没有配置信息");
                    }
                    IList <TaskConfigDetail> TaskConfigDetails = AGVClientDAccess.load_TaskDetail(CurrBoxDetail.TaskConditonCode);
                    if (TaskConfigDetails == null && (TaskConfigDetails != null && TaskConfigDetails.Count <= 0))
                    {
                        return("当前按钮未配置任务信息");
                    }
                    //开始创建任务
                    StorageInfo CallStore = Stores.FirstOrDefault(q => q.ID == CurrBoxDetail.LocationID);
                    if (CallStore == null)
                    {
                        return("未设置当前按钮的监控储位!");
                    }
                    CallStore.StorageState = CurrBoxDetail.LocationState;
                    AGVSimulationDAccess.UpdateStore(CallStore.ID, CallStore.StorageState);
                }
                else if (CurrBoxDetail.OperaType == 2)//放行
                {
                    StorageInfo CheckStore = Stores.FirstOrDefault(p => p.ID == CurrBoxDetail.LocationID);
                    if (CheckStore == null)
                    {
                        return("监控放行储位不存在!");
                    }
                    CarMonitor ReleaseCar = MoniCars.FirstOrDefault(p => p.CurrSite.ToString() == CheckStore.LankMarkCode);
                    if (ReleaseCar == null)
                    {
                        return("当前没有放行车辆!");
                    }
                    OperateReturnInfo opr = AGVSimulationDAccess.ReleaseCar(ReleaseCar.ExcuteTaksNo, ReleaseCar.ArmLand);
                    if (opr.ReturnCode != OperateCodeEnum.Success)
                    {
                        return(opr.ReturnInfo.ToString());
                    }
                }
                else//取消任务
                {
                }
                return("操作成功!");
            }
            catch (Exception ex)
            {
                return("发送异常!" + ex.Message);
            }
        }
Exemple #11
0
        /// <summary>
        /// 处理呼叫盒呼叫
        /// </summary>
        /// <param name="CallBoxID">呼叫盒ID</param>
        /// <param name="BtnID">按钮ID</param>
        /// <returns></returns>
        private bool HandleCallBoxCall(CallBoxInfo CallBox, CallBoxDetail CurrBoxDetail, int BtnID)
        {
            try
            {
                #region 处理呼叫逻辑
                //加载是否启用储位状态
                string IsUserStoreState = CoreData.SysParameter["IsUserStoreState"].ToString();
                if (string.IsNullOrEmpty(IsUserStoreState))
                {
                    IsUserStoreState = "否";
                }
                int CallBoxID = CallBox.CallBoxID;
                IList <TaskConfigDetail> TaskConfigDetails = AGVClientDAccess.load_TaskDetail(CurrBoxDetail.TaskConditonCode);
                if (TaskConfigDetails == null && (TaskConfigDetails != null && TaskConfigDetails.Count <= 0))
                {
                    LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "任务信息");
                    return(false);
                }

                //开始根据任务配置信息创建任务
                StorageInfo CallStore = CoreData.StorageList.FirstOrDefault(q => q.ID == CurrBoxDetail.LocationID);
                if (CallStore == null)
                {
                    LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "对应的监控储位");
                    return(false);
                }
                //验证当前按钮盒下是否存在未完成的任务
                if (AGVSimulationDAccess.ChekAllowCreatTask(CallBoxID, CallStore.LankMarkCode, BtnID) > 0)
                {
                    LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫存在未完成任务,请稍后再试!");
                    return(false);
                }

                //组装任务信息
                string           dispatchNo = Guid.NewGuid().ToString();
                DispatchTaskInfo TaskInfo   = new DispatchTaskInfo();
                TaskInfo.dispatchNo = dispatchNo;
                TaskInfo.TaskState  = 0;
                TaskInfo.CallLand   = CallStore.LankMarkCode;
                TaskInfo.stationNo  = CallBoxID;
                TaskInfo.CallID     = BtnID;
                TaskInfo.taskType   = 0;

                //创建任务明细
                int DetailID   = 1;
                int PrePutType = -1;
                foreach (TaskConfigDetail item in TaskConfigDetails)
                {
                    //通过任务任务配置明细寻找目标地标
                    StorageInfo ArmStore = null;
                    LogHelper.WriteCallBoxLog("呼叫储位为:" + item.ArmOwnArea.ToString());
                    if (item.ArmOwnArea == -1)
                    {
                        ArmStore = CallStore;
                        LogHelper.WriteCallBoxLog("呼叫储位地标为:" + CallStore.LankMarkCode);
                    }
                    else
                    {
                        if (IsUserStoreState == "否")
                        {
                            ArmStore = CoreData.StorageList.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType);
                        }
                        else
                        {
                            ArmStore = CoreData.StorageList.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType && p.LockState == 0);
                        }
                    }
                    if (ArmStore == null)
                    {
                        LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫,目的储位不存在[原因:不存在或被占用]");
                        return(false);
                    }

                    //再通过配置任务号来处理必经地标
                    IList <TaskConfigMustPass> ConfigMustPasses = AGVServerDAccess.LoadTaskMustPass(item.TaskConditonCode, item.DetailID);
                    if (ConfigMustPasses != null && ConfigMustPasses.Count > 0)
                    {
                        ////如果配置的必经地标则需要产生任务经过必经地标
                        foreach (TaskConfigMustPass MustPassItem in ConfigMustPasses)
                        {
                            foreach (IOActionInfo Action in MustPassItem.MustPassIOAction)
                            {
                                IOActionInfo CurrIOActionInfo = AGVServerDAccess.LoadAllIOAction(Action.ActionID);
                                if (CurrIOActionInfo == null)
                                {
                                    LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫,必经地标中的IO动作" + Action.ActionID.ToString() + "档案信息不存在");
                                    continue;
                                }
                                DispatchTaskDetail newTaskDetail = new DispatchTaskDetail();
                                newTaskDetail.dispatchNo         = dispatchNo;
                                newTaskDetail.DetailID           = DetailID;
                                newTaskDetail.LandCode           = MustPassItem.MustPassLandCode;
                                newTaskDetail.IsAllowExcute      = Action.IsPass;
                                newTaskDetail.IsSensorStop       = 0;
                                newTaskDetail.OperType           = -1;
                                newTaskDetail.IsWait             = Action.IsWait;
                                newTaskDetail.WaitTime           = Action.WaitTime;
                                newTaskDetail.TaskConditonCode   = MustPassItem.TaskConditonCode;
                                newTaskDetail.TaskConfigDetailID = item.DetailID;
                                TaskInfo.TaskDetail.Add(newTaskDetail);
                            }
                        }



                        //foreach (TaskConfigMustPass MustPassItem in ConfigMustPasses)
                        //{
                        //    //根据配置的IO动作ID加载对应的IO动作明细信息
                        //    IOActionInfo CurrIOActionInfo = AGVServerDAccess.LoadAllIOAction(MustPassItem.Action);
                        //    if (CurrIOActionInfo == null)
                        //    {
                        //        LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫,必经地标中的IO动作" + MustPassItem.Action.ToString() + "档案信息不存在");
                        //        continue;
                        //    }
                        //    //找到必经地标中的IO动作后组装任务体
                        //    DispatchTaskDetail dispathDetail_MustPas = new DispatchTaskDetail();
                        //    dispathDetail_MustPas.dispatchNo = dispatchNo;
                        //    dispathDetail_MustPas.DetailID = DetailID;
                        //    dispathDetail_MustPas.LandCode = MustPassItem.MustPassLandCode;
                        //    dispathDetail_MustPas.OperType = -1;
                        //    dispathDetail_MustPas.IsAllowExcute = CurrIOActionInfo.IsWait;
                        //    dispathDetail_MustPas.PutType = -1;
                        //    dispathDetail_MustPas.IOActionID = CurrIOActionInfo.ActionID;
                        //    TaskInfo.TaskDetail.Add(dispathDetail_MustPas);
                        //    DetailID += 1;
                        //}//结束循环处理必经地标配置
                    }

                    //如果没有必经地标或者添加完必经地标后需要继续添加后续的任务配置明细
                    DispatchTaskDetail dispathDetail_TaskConfig = new DispatchTaskDetail();
                    dispathDetail_TaskConfig.dispatchNo    = dispatchNo;
                    dispathDetail_TaskConfig.DetailID      = DetailID;
                    dispathDetail_TaskConfig.LandCode      = ArmStore.LankMarkCode;
                    dispathDetail_TaskConfig.OperType      = item.Action;
                    dispathDetail_TaskConfig.IsAllowExcute = item.IsWaitPass;
                    dispathDetail_TaskConfig.PassType      = item.PassType;
                    if (PrePutType == -1)
                    {
                        dispathDetail_TaskConfig.PutType = ArmStore.StorageState;
                    }
                    else
                    {
                        dispathDetail_TaskConfig.PutType = PrePutType;
                    }
                    dispathDetail_TaskConfig.IsSensorStop = item.IsSensorStop;
                    TaskInfo.TaskDetail.Add(dispathDetail_TaskConfig);
                    PrePutType = ArmStore.StorageState;
                    DetailID  += 1;
                }//结束循环处理任务配置

                //循环组装完任务信息后保存到数据库
                if (TaskInfo != null && TaskInfo.TaskDetail.Count > 0)
                {
                    AGVServerDAccess.CreatTaskInfo(TaskInfo, IsUserStoreState == "是" ? true : false);
                }
                return(true);

                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteCallBoxLog("处理呼叫器呼叫异常:" + ex.Message);
                return(false);
            }
        }
Exemple #12
0
        private void HandleCallBoxRequest(object obj, CallBoxInfo CallBox)
        {
            try
            {
                //lock (HandCallBoxlockObj)
                //{
                LogHelper.WriteCallBoxLog("接受到:" + CallBox.CallBoxID.ToString() + "号按钮盒信息");
                NetEventArgs einfo = obj as NetEventArgs;
                if (einfo == null)
                {
                    return;
                }
                LogHelper.WriteCallBoxLog("开始解析按钮值");
                List <byte> Message       = einfo.MesContent;
                AppSession  ClientSession = einfo.Session;
                int         CallBoxID     = CallBox.CallBoxID;
                //本次被开的按钮
                List <int> CallBoxBtnList = new List <int>();
                //本次被关闭的按钮
                List <int> CallBoxBtnCloseList = new List <int>();
                //int ButID = (int)Message[3];
                //if (ButID == 0) { return; }
                //CallBoxBtnList.Add(ButID);
                ////最多支持9个按键
                //string BtnPortNextStr = Convert.ToString(Message[4], 2).PadLeft(8, '0');
                //LogHelper.WriteCallBoxLog(BtnPortNextStr);
                //if (BtnPortNextStr.Substring(7, 1) == "1")
                //{ CallBoxBtnList.Add(9); }
                string BtnPortStr = Convert.ToString(Message[3], 2).PadLeft(8, '0');
                if (BtnPortStr.Substring(0, 1) == "1")
                {
                    CallBoxBtnList.Add(8);
                }
                else
                {
                    CallBoxBtnCloseList.Add(8);
                }
                if (BtnPortStr.Substring(1, 1) == "1")
                {
                    CallBoxBtnList.Add(7);
                }
                else
                {
                    CallBoxBtnCloseList.Add(7);
                }
                if (BtnPortStr.Substring(2, 1) == "1")
                {
                    CallBoxBtnList.Add(6);
                }
                else
                {
                    CallBoxBtnCloseList.Add(6);
                }
                if (BtnPortStr.Substring(3, 1) == "1")
                {
                    CallBoxBtnList.Add(5);
                }
                else
                {
                    CallBoxBtnCloseList.Add(5);
                }
                if (BtnPortStr.Substring(4, 1) == "1")
                {
                    CallBoxBtnList.Add(4);
                }
                else
                {
                    CallBoxBtnCloseList.Add(4);
                }
                if (BtnPortStr.Substring(5, 1) == "1")
                {
                    CallBoxBtnList.Add(3);
                }
                else
                {
                    CallBoxBtnCloseList.Add(3);
                }
                if (BtnPortStr.Substring(6, 1) == "1")
                {
                    CallBoxBtnList.Add(2);
                }
                else
                {
                    CallBoxBtnCloseList.Add(2);
                }
                if (BtnPortStr.Substring(7, 1) == "1")
                {
                    CallBoxBtnList.Add(1);
                }
                else
                {
                    CallBoxBtnCloseList.Add(1);
                }


                //记忆上次被开的按钮
                string OldCallBoxBtnList = CallBox.CallBoxBtnList;
                CallBox.CallBoxBtnList = string.Join(",", CallBoxBtnList.Select(p => p));

                CallBoxInfo           BoxInfo    = AGVServerDAccess.LoadAllCallBoxByID(CallBoxID);
                IList <CallBoxDetail> BoxDetails = AGVServerDAccess.LoadCallBoxDetails(CallBoxID);
                //根据按钮盒信息处理业务逻辑
                foreach (int BtnID in CallBoxBtnList)
                {
                    CallBoxDetail CurrBoxDetail = BoxDetails.FirstOrDefault(p => p.CallBoxID == CallBoxID && p.ButtonID == BtnID);
                    if (CurrBoxDetail.OperaType != 3)
                    {
                        LightContrl(ClientSession, BtnID, 1);
                    }

                    //抽取当前按钮盒当前按钮对应的操作类型
                    LogHelper.WriteCallBoxLog("接受到" + CallBox.CallBoxID + "号按钮盒按键" + BtnID);

                    //处理按钮盒的过程为:
                    //1.接受到按钮盒的请求后,产生任务后将对应的按钮灯点亮
                    //2.当有车领取了该任务后将按钮等熄灭
                    #region 根据配置生成任务
                    if (BoxInfo == null)
                    {
                        LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "档案信息");
                        Thread.Sleep(1000 * 3);
                        LightContrl(ClientSession, BtnID, 0);
                        continue;
                    }

                    if (BoxDetails == null || (BoxDetails != null && BoxDetails.Count <= 0))
                    {
                        LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "明细档案信息1");
                        Thread.Sleep(1000 * 3);
                        LightContrl(ClientSession, BtnID, 0);
                        continue;
                    }


                    if (CurrBoxDetail == null)
                    {
                        LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "明细档案信息2");
                        Thread.Sleep(1000 * 3);
                        LightContrl(ClientSession, BtnID, 0);
                        continue;
                    }

                    if (CurrBoxDetail.OperaType == 0)//呼叫
                    {
                        bool HandleCallResult = HandleCallBoxCall(CallBox, CurrBoxDetail, BtnID);
                        if (!HandleCallResult)
                        {
                            Thread.Sleep(1000 * 3);
                            LightContrl(ClientSession, BtnID, 0);
                            continue;
                        }
                        else
                        {
                            Thread.Sleep(3000);
                            LightContrl(ClientSession, BtnID, 0);
                        }
                    }
                    else if (CurrBoxDetail.OperaType == 1)//监控
                    {
                        bool HandleCallBoxMonitorResult = HandleCallBoxMonitor(CallBox, CurrBoxDetail, BtnID);
                        if (!HandleCallBoxMonitorResult)
                        {
                            Thread.Sleep(1000 * 3);
                            LightContrl(ClientSession, BtnID, 0);
                            continue;
                        }
                        else
                        {
                            Thread.Sleep(3000);
                            LightContrl(ClientSession, BtnID, 0);
                        }
                    }
                    else if (CurrBoxDetail.OperaType == 3)//传感器监控
                    {
                        if (string.IsNullOrEmpty(OldCallBoxBtnList) || (!string.IsNullOrEmpty(OldCallBoxBtnList) && !OldCallBoxBtnList.Contains(BtnID.ToString())))
                        {
                            hs_PreReciveSensorTime[CurrBoxDetail.CallBoxID.ToString() + "," + CurrBoxDetail.ButtonID.ToString()] = DateTime.Now;
                        }
                        else
                        {
                            double FilterTime = 0;
                            //传感器监控需要增加滤波功能
                            string FilterTimeStr = CoreData.SysParameter["FilterTime"].ToString();
                            if (!string.IsNullOrEmpty(FilterTimeStr))
                            {
                                try
                                {
                                    FilterTime = Convert.ToDouble(FilterTimeStr);
                                }
                                catch
                                { }
                            }
                            ArrayList keyList = new ArrayList(hs_PreReciveSensorTime.Keys);
                            if (!keyList.Contains(CurrBoxDetail.CallBoxID.ToString() + "," + CurrBoxDetail.ButtonID.ToString()))
                            {
                                hs_PreReciveSensorTime[CurrBoxDetail.CallBoxID.ToString() + "," + CurrBoxDetail.ButtonID.ToString()] = DateTime.Now;
                            }
                            else
                            {
                                DateTime PreReciveSensorTime = Convert.ToDateTime(hs_PreReciveSensorTime[CurrBoxDetail.CallBoxID.ToString() + "," + CurrBoxDetail.ButtonID.ToString()]);
                                double   SpanTime            = (DateTime.Now - PreReciveSensorTime).TotalSeconds;
                                if (FilterTime <= SpanTime)
                                {
                                    HandleCallBoxMonitor(CallBox, CurrBoxDetail, BtnID);
                                    hs_PreReciveSensorTime[CurrBoxDetail.CallBoxID.ToString() + "," + CurrBoxDetail.ButtonID.ToString()] = DateTime.Now;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                    }
                    else//确认放行
                    {
                        bool HandleCallBoxReleaseResult = HandleCallBoxRelease(CallBox, CurrBoxDetail, BtnID);
                        if (!HandleCallBoxReleaseResult)
                        {
                            Thread.Sleep(1000 * 3);
                            LightContrl(ClientSession, BtnID, 0);
                            continue;
                        }
                        else
                        {
                            Thread.Sleep(3000);
                            LightContrl(ClientSession, BtnID, 0);
                        }
                    }
                    #endregion
                    //Thread.Sleep(3000);
                    //LightContrl(ClientSession, BtnID, 0);
                }

                ///将传感器没有物品时需要将对应储位状态清空
                foreach (int BtnID in CallBoxBtnCloseList)
                {
                    if (BoxDetails == null || (BoxDetails != null && BoxDetails.Count <= 0))
                    {
                        LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "明细档案信息4");
                        continue;
                    }
                    CallBoxDetail CurrBoxDetail = BoxDetails.FirstOrDefault(p => p.CallBoxID == CallBoxID && p.ButtonID == BtnID);
                    if (CurrBoxDetail == null)
                    {
                        //LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "明细档案信息");
                        continue;
                    }
                    if (CurrBoxDetail.OperaType == 3)//传感器监控
                    {
                        ArrayList keyList = new ArrayList(hs_PreReciveSensorTime.Keys);
                        if (!keyList.Contains(CurrBoxDetail.CallBoxID.ToString() + "," + CurrBoxDetail.ButtonID.ToString()))
                        {
                            if (string.IsNullOrEmpty(OldCallBoxBtnList) || (!string.IsNullOrEmpty(OldCallBoxBtnList) && OldCallBoxBtnList.Contains(BtnID.ToString())))
                            {
                                hs_PreReciveSensorTime[CurrBoxDetail.CallBoxID.ToString() + "," + CurrBoxDetail.ButtonID.ToString()] = DateTime.Now;
                            }
                        }
                        else
                        {
                            double FilterTime = 0;
                            //传感器监控需要增加滤波功能
                            string FilterTimeStr = CoreData.SysParameter["FilterTime"].ToString();
                            if (!string.IsNullOrEmpty(FilterTimeStr))
                            {
                                try
                                {
                                    FilterTime = Convert.ToDouble(FilterTimeStr);
                                }
                                catch
                                { }
                            }
                            keyList = new ArrayList(hs_PreReciveSensorTime.Keys);
                            if (!keyList.Contains(CurrBoxDetail.CallBoxID.ToString() + "," + CurrBoxDetail.ButtonID.ToString()))
                            {
                                hs_PreReciveSensorTime[CurrBoxDetail.CallBoxID.ToString() + "," + CurrBoxDetail.ButtonID.ToString()] = DateTime.Now;
                            }
                            else
                            {
                                DateTime PreReciveSensorTime = Convert.ToDateTime(hs_PreReciveSensorTime[CurrBoxDetail.CallBoxID.ToString() + "," + CurrBoxDetail.ButtonID.ToString()]);
                                double   SpanTime            = (DateTime.Now - PreReciveSensorTime).TotalSeconds;
                                if (FilterTime <= SpanTime)
                                {
                                    CurrBoxDetail.LocationState = 0;
                                    HandleCallBoxMonitor(CallBox, CurrBoxDetail, BtnID);
                                    hs_PreReciveSensorTime[CurrBoxDetail.CallBoxID.ToString() + "," + CurrBoxDetail.ButtonID.ToString()] = DateTime.Now;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                    }
                }
                //}
            }
            catch (Exception ex)
            { LogHelper.WriteCallBoxLog("呼叫器处理异常:" + ex.Message); }
        }
        /// <summary>
        /// 处理呼叫器呼叫任务
        /// </summary>
        /// <param name="CallBox"></param>
        /// <param name="CurrBoxDetail"></param>
        /// <param name="BtnID"></param>
        /// <returns></returns>
        private bool HandleCallBoxCall(CallBoxInfo CallBox, CallBoxDetail CurrBoxDetail, int BtnID)
        {
            try
            {
                lock (lockstorage)
                {
                    #region 处理呼叫逻辑
                    //加载是否启用储位状态
                    string IsUserStoreState = CoreData.SysParameter["IsUserStoreState"].ToString();
                    if (string.IsNullOrEmpty(IsUserStoreState))
                    {
                        IsUserStoreState = "否";
                    }
                    int CallBoxID = CallBox.CallBoxID;
                    IList <TaskConfigDetail> TaskConfigDetails = AGVClientDAccess.load_TaskDetail(CurrBoxDetail.TaskConditonCode);
                    if (TaskConfigDetails == null && (TaskConfigDetails != null && TaskConfigDetails.Count <= 0))
                    {
                        LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "任务信息");
                        return(false);
                    }
                    DataTable dtstorage = CoreData.dbOperator.LoadDatas("QueryAllStore");
                    CoreData.StorageList = DataToObject.TableToEntity <StorageInfo>(dtstorage);
                    //开始根据任务配置信息创建任务
                    StorageInfo CallStore = CoreData.StorageList.FirstOrDefault(q => q.ID == CurrBoxDetail.LocationID);
                    if (CallStore == null)
                    {
                        LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "对应的监控储位");
                        return(false);
                    }
                    //验证当前按钮盒下是否存在未完成的任务
                    if (AGVSimulationDAccess.ChekAllowCreatTask(CallBoxID, CallStore.LankMarkCode, CurrBoxDetail.ButtonID) > 0)
                    {
                        LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫存在未完成任务,请稍后再试!");
                        return(false);
                    }
                    //验证当前按钮盒下是否存在未完成的任务
                    if (AGVSimulationDAccess.ChekAllowCreatTask2(CallBoxID, CallStore.LankMarkCode, CurrBoxDetail.ButtonID) > 0)
                    {
                        LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫存在未完成任务 未回写的任务,请稍后再试!");
                        return(false);
                    }
                    AreaInfo callarea = CoreData.AllAreaList.FirstOrDefault(p => p.OwnArea == CallStore.OwnArea);
                    if (callarea != null && callarea.MaxTaskCount > 0)
                    {
                        if (AGVSimulationDAccess.ChekAllowCreatTask3(callarea.OwnArea) >= callarea.MaxTaskCount)
                        {
                            LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxIP.ToString() + " 地址" + CurrBoxDetail.DBAddress + " 对应的区域任务数量达到最大,不产生任务");
                            return(false);
                        }
                    }
                    if (!string.IsNullOrEmpty(CallStore.StorageName))
                    {
                        LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxIP.ToString() + " 地址" + CurrBoxDetail.DBAddress + "对应储位未启用");
                        return(false);
                    }

                    //组装任务信息
                    string           dispatchNo = Guid.NewGuid().ToString();
                    DispatchTaskInfo TaskInfo   = new DispatchTaskInfo();
                    TaskInfo.dispatchNo = dispatchNo;
                    TaskInfo.TaskState  = 0;
                    TaskInfo.CallLand   = CallStore.LankMarkCode;
                    TaskInfo.stationNo  = CallBoxID;
                    TaskInfo.CallID     = BtnID;
                    TaskInfo.taskType   = 0;
                    TaskInfo.OwerArea   = CallStore.OwnArea;
                    //创建任务明细
                    int DetailID   = 1;
                    int PrePutType = -1;
                    foreach (TaskConfigDetail item in TaskConfigDetails)
                    {
                        //通过任务任务配置明细寻找目标地标
                        StorageInfo ArmStore = null;
                        LogHelper.WriteCallBoxLog("呼叫储位为:" + item.ArmOwnArea.ToString());
                        if (item.ArmOwnArea == -1)
                        {
                            ArmStore = CallStore;
                            LogHelper.WriteCallBoxLog("呼叫储位地标为:" + CallStore.LankMarkCode);
                        }
                        else
                        {
                            if (IsUserStoreState == "否")
                            {
                                ArmStore = CoreData.StorageList.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType);
                            }
                            else
                            {
                                ArmStore = CoreData.StorageList.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType && p.LockState == 0);
                            }
                        }
                        if (ArmStore == null)
                        {
                            LogHelper.WriteCallBoxLog(string.Format("按钮盒{0}   地址:{1}   BtnID{2}   对应呼叫,目的储位不存在[原因:不存在或被占用]", CallBox.CallBoxID, CurrBoxDetail.DBAddress, CurrBoxDetail.ButtonID));
                            return(false);
                        }

                        #region  用
                        //再通过配置任务号来处理必经地标
                        IList <TaskConfigMustPass> ConfigMustPasses = AGVServerDAccess.LoadTaskMustPass(item.TaskConditonCode, item.DetailID);
                        if (ConfigMustPasses != null && ConfigMustPasses.Count > 0)
                        {
                            ////如果配置的必经地标则需要产生任务经过必经地标
                            foreach (TaskConfigMustPass MustPassItem in ConfigMustPasses)
                            {
                                foreach (IOActionInfo Action in MustPassItem.MustPassIOAction)
                                {
                                    IOActionInfo CurrIOActionInfo = AGVServerDAccess.LoadAllIOAction(Action.ActionID);
                                    if (CurrIOActionInfo == null)
                                    {
                                        LogHelper.WriteCallBoxLog("按钮器" + CallBox.CallBoxID.ToString() + "对应呼叫,必经地标中的IO动作" + Action.ActionID.ToString() + "档案信息不存在");
                                        continue;
                                    }
                                    DispatchTaskDetail newTaskDetail = new DispatchTaskDetail();
                                    newTaskDetail.dispatchNo         = dispatchNo;
                                    newTaskDetail.DetailID           = DetailID;
                                    newTaskDetail.LandCode           = MustPassItem.MustPassLandCode;
                                    newTaskDetail.IsAllowExcute      = Action.IsPass;
                                    newTaskDetail.IsSensorStop       = 0;
                                    newTaskDetail.OperType           = -1;
                                    newTaskDetail.IsWait             = Action.IsWait;
                                    newTaskDetail.WaitTime           = Action.WaitTime;
                                    newTaskDetail.TaskConditonCode   = MustPassItem.TaskConditonCode;
                                    newTaskDetail.TaskConfigDetailID = item.DetailID;
                                    TaskInfo.TaskDetail.Add(newTaskDetail);
                                }
                            }
                        }
                        #endregion


                        //如果没有必经地标或者添加完必经地标后需要继续添加后续的任务配置明细
                        DispatchTaskDetail dispathDetail_TaskConfig = new DispatchTaskDetail();
                        dispathDetail_TaskConfig.dispatchNo = dispatchNo;
                        dispathDetail_TaskConfig.DetailID   = DetailID;
                        dispathDetail_TaskConfig.LandCode   = ArmStore.LankMarkCode;
                        dispathDetail_TaskConfig.StorageID  = ArmStore.ID;
                        if (!string.IsNullOrEmpty(ArmStore.Remark))
                        {
                            TaskInfo.GoodsInfo = ArmStore.Remark;
                        }
                        dispathDetail_TaskConfig.OperType       = item.Action;
                        dispathDetail_TaskConfig.IsAllowExcute  = item.IsWaitPass;
                        dispathDetail_TaskConfig.PassType       = item.PassType;
                        dispathDetail_TaskConfig.IsNeedCallBack = item.IsNeedCallBack;
                        dispathDetail_TaskConfig.IsCallGoods    = item.IsCallGoods;

                        if (PrePutType == -1)
                        {
                            dispathDetail_TaskConfig.PutType = ArmStore.StorageState;
                        }
                        else
                        {
                            dispathDetail_TaskConfig.PutType = PrePutType;
                        }
                        dispathDetail_TaskConfig.IsSensorStop = item.IsSensorStop;
                        TaskInfo.TaskDetail.Add(dispathDetail_TaskConfig);
                        PrePutType = ArmStore.StorageState;
                        DetailID  += 1;
                    }//结束循环处理任务配置

                    //循环组装完任务信息后保存到数据库
                    if (TaskInfo != null && TaskInfo.TaskDetail.Count > 0)
                    {
                        AGVServerDAccess.CreatTaskInfo(TaskInfo, IsUserStoreState == "是" ? true : false);
                    }
                    return(true);

                    #endregion
                }
            }
            catch (Exception ex)
            {
                DelegateState.InvokeDispatchStateEvent(ex.Message);
                return(false);
            }
        }
        /// <summary>
        /// 轮询
        /// </summary>
        private void Polling()
        {
            //定时轮询PLC
            while (true)
            {
                try
                {
                    //根据PLCCode加载呼叫盒子信息
                    CallBoxInfo CallInfo = CoreData.AllCallBoxes.FirstOrDefault(P => P.CallBoxID == PLCCode);
                    if (CallInfo == null)
                    {
                        LogHelper.WriteCallBoxLog("未匹配到呼叫器:" + PLCCode + "档案信息!");
                        return;
                    }

                    int readLen = CallInfo.ReadLenth;
                    if (readLen == 0)
                    {
                        LogHelper.WriteCallBoxLog("未配置呼叫器:" + PLCCode + "读取长度!");
                        return;
                    }
                    if (CallInfo.CallType == 1)//呼叫类型的
                    {
                        var t = CoreData.AllCallBoxDetail.Where(z => z.CallBoxID == PLCCode).Select(k => k.DBAddress).Distinct();
                        foreach (var address in t)
                        {
                            OperateResult <short[]> read = melsecMc.ReadInt16(address, (ushort)readLen);
                            if (!read.IsSuccess)
                            {
                                LogHelper.WriteCallBoxLog("读取呼叫器失败!  " + string.Format("[{0},{2},{1}]", PLCCode, address, ConnParam.ServerIP));
                                OperateResult opr = melsecMc.ConnectServer();
                                melsecMc.ConnectClose();
                                melsecMc.Dispose();
                                Thread.Sleep(5000);
                                melsecMc = new SiemensS7Net(SiemensPLCS.S1200)
                                {
                                    IpAddress = this.ConnParam.ServerIP, Port = this.ConnParam.Port
                                };
                                melsecMc.SetPersistentConnection();

                                LogHelper.WriteCallBoxLog("重连呼叫器!  " + string.Format("[{0},{2},{1}] ", PLCCode, address, ConnParam.ServerIP));
                                continue;
                            }
                            string SenDLog = "";
                            foreach (short item in read.Content)
                            {
                                SenDLog += ((int)item).ToString("X") + " ";
                            }
                            LogHelper.WriteCallBoxLog("读取呼叫器 " + string.Format("[{0},{2},{1}]", PLCCode, address, ConnParam.ServerIP) + "内容为:" + SenDLog);
                            int site            = Convert.ToInt32(read.Content[0]);
                            int PlcRequestState = Convert.ToInt32(read.Content[2]);
                            if (PlcRequestState == 1)
                            {
                                int  RequestContent   = Convert.ToInt32(read.Content[1]);
                                var  cdetail          = CoreData.AllCallBoxDetail.FirstOrDefault(p => p.CallBoxID == PLCCode && p.DBAddress == address && p.ButtonID == RequestContent);
                                bool HandleCallResult = HandleCallBoxCall(CallInfo, cdetail, cdetail.ButtonID);
                                if (!HandleCallResult)
                                {
                                    LogHelper.WriteCallBoxLog("呼叫器:" + PLCCode + "地址 :" + address + " 呼叫失败!");
                                }
                                #region 处理需要回写的子任务
                                IList <DispatchTaskDetail> detaillist = AGVClientDAccess.LoadTaskDetailByPLCCode(PLCCode, cdetail.LocationID);
                                foreach (var detail in detaillist)
                                {
                                    if (detail != null && (!string.IsNullOrEmpty(detail.dispatchNo)))
                                    {
                                        //写确认信息
                                        List <byte> write = new List <byte>();
                                        //{ BitConverter.GetBytes(read.Content[0]), BitConverter.GetBytes(read.Content[1]) , BitConverter.GetBytes(read.Content[2])}
                                        write.Add(BitConverter.GetBytes(read.Content[0])[1]);
                                        write.Add(BitConverter.GetBytes(read.Content[0])[0]);
                                        write.Add(BitConverter.GetBytes(read.Content[1])[1]);
                                        write.Add(BitConverter.GetBytes(read.Content[1])[0]);
                                        write.Add(BitConverter.GetBytes(read.Content[2])[1]);
                                        write.Add(BitConverter.GetBytes(read.Content[2])[0]);
                                        OperateResult opr       = melsecMc.Write(address.Replace(".0", ".6"), write.ToArray());
                                        int           writcount = 1;
                                        while (!opr.IsSuccess)
                                        {
                                            if (writcount > 3)
                                            {
                                                opr = melsecMc.Write(address, write.ToArray());
                                                LogHelper.WriteCallBoxLog("回写呼叫器:" + PLCCode + "地址 :" + address + "失败!");
                                                break;
                                            }
                                            writcount++;
                                            Thread.Sleep(1000);
                                        }
                                        if (opr.IsSuccess)
                                        {
                                            AGVClientDAccess.UpdatePlcCallBackState(detail.dispatchNo, detail.DetailID);
                                            LogHelper.WriteCallBoxLog("回写呼叫器:" + PLCCode + "地址 :" + address + "成功!");
                                        }
                                    }
                                }
                                #endregion

                                #region 处理需要回写物料信息的子任务
                                IList <DispatchTaskDetail> goodsdetaillist = AGVClientDAccess.LoadGoodsInfoTaskDetailByPLCCode(PLCCode, cdetail.LocationID);
                                foreach (var detail in goodsdetaillist)
                                {
                                    if (detail != null && (!string.IsNullOrEmpty(detail.dispatchNo)) && (!string.IsNullOrEmpty(detail.GoodsInfo)))
                                    {
                                        //写确认信息
                                        List <byte> write = new List <byte>();
                                        string[]    arr   = detail.GoodsInfo.Split(',');
                                        foreach (var s in arr)
                                        {
                                            if (!string.IsNullOrEmpty(s))
                                            {
                                                short ts = short.Parse(s);
                                                write.Add(BitConverter.GetBytes(ts)[1]);
                                                write.Add(BitConverter.GetBytes(ts)[0]);
                                            }
                                        }
                                        OperateResult opr       = melsecMc.Write(address.Replace(".0", ".12"), write.ToArray());
                                        int           writcount = 1;
                                        while (!opr.IsSuccess)
                                        {
                                            if (writcount > 3)
                                            {
                                                opr = melsecMc.Write(address.Replace(".0", ".12"), write.ToArray());
                                                LogHelper.WriteCallBoxLog("回写呼叫器 物料编码:" + PLCCode + "地址 :" + address + "失败!");
                                                break;
                                            }
                                            writcount++;
                                            Thread.Sleep(1000);
                                        }
                                        if (opr.IsSuccess)
                                        {
                                            AGVClientDAccess.UpdateGoodsCallBackState(detail.dispatchNo, detail.DetailID);
                                            LogHelper.WriteCallBoxLog("回写呼叫器 物料编码:" + PLCCode + "地址 :" + address + "成功!");
                                        }
                                    }
                                }
                                #endregion
                            }
                        }

                        #region OlD
                        ////根据当前呼叫器ID加载呼叫器明细
                        //OperateResult<short[]> read = melsecMc.ReadInt16(ReadAddr, (ushort)readLen);
                        //if (!read.IsSuccess)
                        //{
                        //    LogHelper.WriteCallBoxLog("读取呼叫器:" + PLCCode + "失败!");
                        //    return;
                        //}

                        //string SenDLog = "";
                        //foreach (byte item in read.Content)
                        //{ SenDLog += ((int)item).ToString("X") + " "; }
                        //LogHelper.WriteCallBoxLog("读取呼叫器:" + PLCCode + "内容为:" + SenDLog);

                        //int site = Convert.ToInt32(read.Content[0]);
                        //int PlcRequestState = Convert.ToInt32(read.Content[1]);
                        //string[] codes = GetCode(read.Content);
                        //if (codes.Length != 2)
                        //{
                        //    LogHelper.WriteCallBoxLog("读取呼叫器:" + PLCCode + " 物料编码获取失败");
                        //}
                        //if (PlcRequestState == 1)
                        //{
                        //    int RequestContent = Convert.ToInt32(read.Content[2]);
                        //    CallBoxDetail CallDetail = CoreData.AllCallBoxDetail.FirstOrDefault(p => p.CallBoxID == PLCCode && p.ButtonID == RequestContent);
                        //    if (CallDetail == null)
                        //    {
                        //        LogHelper.WriteCallBoxLog("未配置呼叫器:" + PLCCode + "按钮号:" + RequestContent.ToString() + "明细!");
                        //        return;
                        //    }
                        //    bool HandleCallResult = HandleCallBoxCall(CallInfo, CallDetail, RequestContent, codes);

                        //    if (HandleCallResult)
                        //    {
                        //        ////写确认信息
                        //        //byte[] write = new byte[] { (byte)site, 0x00, (byte)RequestContent, (byte)site, 0x01, (byte)RequestContent };
                        //        //OperateResult opr = melsecMc.Write(ReadAddr, write);
                        //        //int writcount = 1;
                        //        //while (!opr.IsSuccess)
                        //        //{
                        //        //    if (writcount > 3)
                        //        //    {
                        //        //        opr = melsecMc.Write(ReadAddr, write);
                        //        //        LogHelper.WriteCallBoxLog("回写呼叫器:" + PLCCode + "失败!");
                        //        //        break;
                        //        //    }
                        //        //    writcount++;
                        //        //    Thread.Sleep(1000);
                        //        //}
                        //        //if (opr.IsSuccess)
                        //        //{
                        //        //    LogHelper.WriteCallBoxLog("回写呼叫器:" + PLCCode + "成功!");
                        //        //}

                        //        //LogHelper.WriteCallBoxLog("呼叫器:" + PLCCode + "呼叫成功!");
                        //    }
                        //    else
                        //    {
                        //        LogHelper.WriteCallBoxLog("呼叫器:" + PLCCode + "呼叫失败!");
                        //    }


                        //    #region 处理需要回写的子任务
                        //    IList<DispatchTaskDetail> detaillist = AGVClientDAccess.LoadTaskDetailByPLCCode(PLCCode, CallDetail.LocationID);
                        //    foreach (var detail in detaillist)
                        //    {
                        //        if (detail != null && (!string.IsNullOrEmpty(detail.dispatchNo)))
                        //        {
                        //            //写确认信息
                        //            List<byte> write = new List<byte>();
                        //            //{ BitConverter.GetBytes(read.Content[0]), BitConverter.GetBytes(read.Content[1]) , BitConverter.GetBytes(read.Content[2])}
                        //            write.Add(BitConverter.GetBytes(read.Content[0])[1]);
                        //            write.Add(BitConverter.GetBytes(read.Content[0])[0]);
                        //            write.Add(BitConverter.GetBytes(read.Content[1])[1]);
                        //            write.Add(BitConverter.GetBytes(read.Content[1])[0]);
                        //            write.Add(BitConverter.GetBytes(read.Content[2])[1]);
                        //            write.Add(BitConverter.GetBytes(read.Content[2])[0]);


                        //            OperateResult opr = melsecMc.Write(ReadAddr.Replace(".0", ".6"), write.ToArray());
                        //            int writcount = 1;
                        //            while (!opr.IsSuccess)
                        //            {
                        //                if (writcount > 3)
                        //                {
                        //                    opr = melsecMc.Write(ReadAddr, write.ToArray());
                        //                    LogHelper.WriteCallBoxLog("回写呼叫器:" + PLCCode + "失败!");
                        //                    break;
                        //                }
                        //                writcount++;
                        //                Thread.Sleep(1000);
                        //            }
                        //            if (opr.IsSuccess)
                        //            {
                        //                AGVClientDAccess.UpdatePlcCallBackState(detail.dispatchNo, detail.DetailID);
                        //                LogHelper.WriteCallBoxLog("回写呼叫器:" + PLCCode + "成功!");
                        //            }
                        //            LogHelper.WriteCallBoxLog("呼叫器:" + PLCCode + "呼叫成功!");
                        //        }
                        //    }
                        //    #endregion

                        //}
                        #endregion
                    }
                    else if (CallInfo.CallType == 2)//监控
                    {
                        var t = CoreData.AllCallBoxDetail.Where(p => p.CallBoxID == CallInfo.CallBoxID);
                        foreach (var d in t)
                        {
                            //if (d.DBAddress != "DB1000.0")
                            //{
                            //    continue;
                            //}
                            if (d.LocationState == 0)
                            {
                                //根据当前呼叫器ID加载呼叫器明细
                                OperateResult <short[]> read = melsecMc.ReadInt16(d.DBAddress, 1);
                                if (!read.IsSuccess)
                                {
                                    LogHelper.WriteCallBoxLog("读取呼叫器失败!  " + string.Format("[{0},{2},{1}]", PLCCode, d.DBAddress, ConnParam.ServerIP));


                                    melsecMc.ConnectClose();
                                    melsecMc.Dispose();
                                    Thread.Sleep(5000);
                                    melsecMc = new SiemensS7Net(SiemensPLCS.S1200)
                                    {
                                        IpAddress = this.ConnParam.ServerIP, Port = this.ConnParam.Port
                                    };
                                    melsecMc.SetPersistentConnection();

                                    LogHelper.WriteCallBoxLog("重连呼叫器!  " + string.Format("[{0},{2},{1}] ", PLCCode, d.DBAddress, ConnParam.ServerIP));
                                    continue;
                                }
                                string SenDLog = "";
                                foreach (short item in read.Content)
                                {
                                    SenDLog += ((int)item).ToString("X") + " ";
                                }
                                LogHelper.WriteCallBoxLog("读取呼叫器 " + string.Format("[{0},{2},{1}]", PLCCode, d.DBAddress, ConnParam.ServerIP) + "内容为:" + SenDLog);
                                if (Convert.ToInt32(read.Content[0]) == 1)
                                {
                                    HandleCallBoxMonitor(CallInfo, d, 0);
                                }
                                else
                                {
                                    HandleCallBoxMonitor(CallInfo, d, 1);
                                }
                            }
                            else if (d.LocationState == 2)
                            {
                                //根据当前呼叫器ID加载呼叫器明细
                                OperateResult <short[]> read = melsecMc.ReadInt16(d.DBAddress, 15);
                                if (!read.IsSuccess)
                                {
                                    LogHelper.WriteCallBoxLog("读取呼叫器 " + string.Format("[{0},{2},{1}]", PLCCode, d.DBAddress, ConnParam.ServerIP) + "失败!");
                                    continue;
                                }
                                string SenDLog = "";
                                foreach (short item in read.Content)
                                {
                                    SenDLog += ((int)item).ToString("X") + " ";
                                }
                                LogHelper.WriteCallBoxLog("读取呼叫器 " + string.Format("[{0},{2},{1}]", PLCCode, d.DBAddress, ConnParam.ServerIP) + "内容为:" + SenDLog);
                                string codes = "";
                                foreach (short s in read.Content.Skip(3))
                                {
                                    codes += s.ToString() + ",";
                                }
                                if (Convert.ToInt32(read.Content[0]) == 1)
                                {
                                    HandleCallBoxMonitor(CallInfo, d, 2, codes);
                                }
                                else
                                {
                                    HandleCallBoxMonitor(CallInfo, d, 0, codes);
                                }
                            }
                        }
                    }
                    else//无,呼叫器类型按照按钮来区分,秦川不支持
                    {
                    }
                }
                catch (Exception ex)
                { LogHelper.WriteCallBoxLog("处理呼叫器:" + PLCCode + "任务失败->" + ex.Message); }

                Thread.Sleep(1000 * 2);
            }
        }