Esempio n. 1
0
 /// <summary>
 /// 删行
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnDele_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         IODeviceInfo CurrentIOInfo = this.bsDetail.Current as IODeviceInfo;
         if (CurrentIOInfo != null)
         {
             if (MsgBox.ShowQuestion("是否确认删除当前行") != DialogResult.No)
             {
                 OperateReturnInfo opr = AGVClientDAccess.Delete_IODeviceInfo(CurrentIOInfo);
                 if (opr.ReturnCode == OperateCodeEnum.Success)
                 {
                     bsDetail.DataSource = AGVDAccess.AGVClientDAccess.LoadIODeviceInfo();
                     bsDetail.ResetBindings(false);
                 }
                 else
                 {
                     MsgBox.Show(opr);
                 }
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
Esempio n. 2
0
 //更新储位信息
 private void UpdateStock()
 {
     try
     {
         this.Invoke((EventHandler)(delegate
         {
             IList <StorageInfo> all_stocks = AGVClientDAccess.LoadStorages();
             if (all_stocks != null)
             {
                 foreach (StorageInfo item in all_stocks)
                 {
                     StorageTool storage = m_data.ActiveLayer.Objects.Where(p => p.Id == "StorageTool" && (p as StorageTool).StcokID == item.ID).FirstOrDefault() as StorageTool;
                     if (storage != null)
                     {
                         storage.OwnArea = item.OwnArea;
                         storage.SubOwnArea = item.SubOwnArea;
                         storage.matterType = item.matterType;
                         storage.StorageState = item.StorageState;
                         storage.LockState = item.LockState;
                         storage.MaterielType = item.MaterielType;
                     }
                 }
             }
             m_canvas.DoInvalidate(true);
         }));
         ClearMemory();
         ReConnect();
     }
     catch (Exception ex)
     { }
 }
Esempio n. 3
0
        private void FrmAGVAchive_Shown(object sender, EventArgs e)
        {
            try
            {
                IList <CarBaseStateInfo> cars = AGVClientDAccess.LoadAGVAchive();
                if (cars == null)
                {
                    return;
                }
                if (cars.Count > 0)
                {
                    this.bsDetail.DataSource = cars;
                    bsDetail.ResetBindings(false);

                    IList <AreaInfo> allAreas = AGVDAccess.AGVClientDAccess.LoadAllArea();
                    allAreas.Insert(0, new AreaInfo {
                        OwnArea = 0, AreaName = "全局"
                    });
                    this.bsArea.DataSource = allAreas;
                    this.bsArea.ResetBindings(false);
                }
            }
            catch (Exception ex)
            { MsgBox.ShowError(ex.Message); }
        }
Esempio n. 4
0
 private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         gvDetail.CloseEditor();
         gvDetail.CloseEditForm();
         gvDetail.FocusedColumn = colSegmentID;
         if (Valid())
         {
             IList <TraJunctionSegInfo> traffics = bsDetail.List as IList <TraJunctionSegInfo>;
             if (traffics != null)
             {
                 TraInfo.Segments = traffics;
                 OperateReturnInfo opr;
                 using (WaitDialogForm dialog = new WaitDialogForm("正在保存,请稍后...", "提示"))
                 {
                     opr = AGVClientDAccess.SaveTraJunctionByOne(TraInfo);
                 }
                 MsgBox.Show(opr);
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
Esempio n. 5
0
 private void FrmTraJunction_Shown(object sender, EventArgs e)
 {
     try
     {
         IList <TraJunction> Traffics = AGVClientDAccess.GetTraJunction();
         this.bsDetail.DataSource = Traffics;
         bsDetail.ResetBindings(false);
         bsDetail.MoveLast();
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
Esempio n. 6
0
 /// <summary>
 /// 加载所有的物料类型
 /// </summary>
 private void CreatBtnByMaterials()
 {
     try
     {
         IList <MaterialInfo> AllMaterials = AGVClientDAccess.LoadAllMaterial();
         if (AllMaterials != null)
         {
             int TotalWidth = this.Width;
             int RowAcount  = TotalWidth / (150 + 5);
             int Amount     = 0;
             int HasWidth   = 0;
             int RowCount   = 1;
             foreach (MaterialInfo MaterialInfo in AllMaterials)
             {
                 Amount++;
                 Button btn = new Button();
                 btn.Tag       = MaterialInfo.MaterialType;
                 btn.Anchor    = AnchorStyles.Left;
                 btn.Text      = MaterialInfo.MaterialName;
                 btn.Click    += Btn_Click;
                 btn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                 btn.FlatAppearance.BorderSize = 0;
                 btn.BackColor = Color.DarkRed;
                 btn.ForeColor = Color.White;
                 btn.Font      = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                 btn.Size      = new System.Drawing.Size(150, 60);
                 if (Amount == 1)
                 {
                     btn.Location = new Point(5, 5);
                     HasWidth     = btn.Width + 5;
                 }
                 else if (Amount <= RowAcount)
                 {
                     btn.Location = new Point(HasWidth + 5, ((RowCount - 1) < 0 ? 0 : RowCount - 1) * btn.Height + (5 * RowCount));
                     HasWidth    += btn.Width + 5;
                 }
                 else
                 {
                     HasWidth     = 0;
                     RowCount    += 1;
                     btn.Location = new Point(HasWidth + 5, ((RowCount - 1) < 0 ? 0 : RowCount - 1) * btn.Height + (5 * RowCount));
                     HasWidth    += btn.Width + 5;
                     Amount       = 1;
                 }
                 this.pnlBtn.Controls.Add(btn);
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
Esempio n. 7
0
 private void FrmAGVAchive_Shown(object sender, EventArgs e)
 {
     try
     {
         IList <CarBaseStateInfo> cars = AGVClientDAccess.LoadAGVAchive();
         if (cars == null)
         {
             return;
         }
         if (cars.Count > 0)
         {
             this.bsDetail.DataSource = cars;
             bsDetail.ResetBindings(false);
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
Esempio n. 8
0
 private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         if (Valid())
         {
             List <string> Parameters = new List <string>();
             Parameters.Add("0," + cbxBei.SelectedItem.ToString());
             Parameters.Add("1," + cbxDong.SelectedItem.ToString());
             Parameters.Add("2," + cbxNan.SelectedItem.ToString());
             Parameters.Add("3," + cbxXi.SelectedItem.ToString());
             OperateReturnInfo opr = AGVClientDAccess.SaveAGVCoordinate(Parameters);
             MsgBox.Show(opr);
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
Esempio n. 9
0
 private void FrmActionDetail_Shown(object sender, EventArgs e)
 {
     try
     {
         this.bsIOActionSet.DataSource = ActionInfo;
         this.bsIOActionSet.ResetBindings(false);
         if (IsView)
         {
             txtActionID.ReadOnly     = true;
             txtActionName.ReadOnly   = true;
             txtDeviceID.ReadOnly     = true;
             txtTerminalID.ReadOnly   = true;
             cbxTerminalType.ReadOnly = true;
             cbxIOUseState.ReadOnly   = true;
             txtTerminalData.ReadOnly = true;
             cbxIsPass.ReadOnly       = true;
             txtWaitTime.ReadOnly     = true;
             cbxIsWait.ReadOnly       = true;
             btnClear.Enabled         = false;
             btnSave.Enabled          = false;
         }
         else
         {
             txtActionID.ReadOnly     = false;
             txtActionName.ReadOnly   = false;
             txtDeviceID.ReadOnly     = false;
             txtTerminalID.ReadOnly   = false;
             cbxTerminalType.ReadOnly = false;
             cbxIOUseState.ReadOnly   = false;
             txtTerminalData.ReadOnly = false;
             cbxIsPass.ReadOnly       = false;
             txtWaitTime.ReadOnly     = false;
             cbxIsWait.ReadOnly       = false;
             btnClear.Enabled         = true;
             btnSave.Enabled          = true;
         }
         this.bsIODevices.DataSource = AGVClientDAccess.LoadIODeviceInfo();
         bsIODevices.ResetBindings(false);
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
Esempio n. 10
0
 public void OnMouseUp(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
 {
     try
     {
         SysParameter sys = AGVClientDAccess.GetParameterByCode("DefaultLenth");
         if (sys != null)
         {
             double DefaultLenth = 0;
             try
             {
                 DefaultLenth = Convert.ToDouble(sys.ParameterValue);
             }
             catch (Exception ex)
             { return; }
             this.Lenth = DefaultLenth;
         }
     }
     catch (Exception ex)
     { throw ex; }
 }
Esempio n. 11
0
 private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         labelControl1.Focus();
         if (!Valid())
         {
             return;
         }
         IOActionInfo      CurrentActionInfo = this.bsIOActionSet.Current as IOActionInfo;
         OperateReturnInfo opr = AGVClientDAccess.SaveIOAction(CurrentActionInfo);
         MsgBox.Show(opr);
         if (opr.ReturnCode == OperateCodeEnum.Success)
         {
             this.DialogResult = DialogResult.OK;
             this.Close();
             return;
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
Esempio n. 12
0
        private void FrmDirectionSet_Shown(object sender, EventArgs e)
        {
            try
            {
                DataTable dt = AGVClientDAccess.LoadAGVCoordinate();
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        switch (Convert.ToInt16(dr["Direction"]))
                        {
                        case 0:
                            cbxBei.SelectedItem = dr["Angle"].ToString();
                            break;

                        case 1:
                            cbxDong.SelectedItem = dr["Angle"].ToString();
                            break;

                        case 2:
                            cbxNan.SelectedItem = dr["Angle"].ToString();;
                            break;

                        case 3:
                            cbxXi.SelectedItem = dr["Angle"].ToString();
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            { MsgBox.ShowError(ex.Message); }
        }
Esempio n. 13
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);
            }
        }
Esempio n. 14
0
        //计算转向和前进和后退
        public void AcountDirect(ref List <LandmarkInfo> Routes)
        {
            try
            {
                if (Routes.Count <= 1)
                {
                    return;
                }
                IList <AllSegment> AllSegs     = AGVClientDAccess.LoadAllSegment();
                DataTable          dtCoor      = AGVClientDAccess.LoadAGVCoordinate();
                LandmarkInfo       UpLand      = null;
                LandmarkInfo       InflectLand = null;
                LandmarkInfo       NextLand    = null;
                int          IsCountAngel      = 0;
                SysParameter sys = AGVClientDAccess.GetParameterByCode("CountTurnType");
                if (sys != null && sys.ParameterValue == "角度")
                {
                    IsCountAngel = 1;
                }

                if (Routes.Count >= 3)
                {
                    for (int i = 2; i < Routes.Count; i++)
                    {
                        UpLand      = Routes[i - 2];
                        InflectLand = Routes[i - 1];
                        NextLand    = Routes[i];


                        if (i != Routes.Count - 1)
                        {
                            #region 计算转向
                            if (IsCountAngel == 0)
                            {
                                AllSegment Segment = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == UpLand.LandmarkCode && p.EndLandMarkCode == InflectLand.LandmarkCode);
                                if (Segment != null && Segment.ExcuteTurnDirect != -1)
                                {
                                    UpLand.sway = (SwayEnum)Segment.ExcuteTurnDirect;
                                }
                                else
                                {
                                    if (AllSegs.Count(p => p.BeginLandMakCode == UpLand.LandmarkCode) > 1)
                                    {
                                        //double SP = (Math.Round(UpLand.LandX, 3) - Math.Round(NextLand.LandX, 3)) * (Math.Round(InflectLand.LandY, 3) - Math.Round(NextLand.LandY, 3)) - (Math.Round(UpLand.LandY, 3) - Math.Round(NextLand.LandY, 3)) * (Math.Round(InflectLand.LandX, 3) - Math.Round(NextLand.LandX, 3));
                                        double SP = (UpLand.LandX - NextLand.LandX) * (InflectLand.LandY - NextLand.LandY) - (UpLand.LandY - NextLand.LandY) * (InflectLand.LandX - NextLand.LandX);
                                        if (SP > 0.05)
                                        {
                                            UpLand.sway = SwayEnum.Left;
                                        }
                                        else if (SP < -0.05)
                                        {
                                            UpLand.sway = SwayEnum.Right;
                                        }
                                        else
                                        {
                                            UpLand.sway = SwayEnum.None;
                                        }
                                    }
                                }
                                if (Segment != null && Segment.ExcuteMoveDirect != -1)
                                {
                                    UpLand.movedirect = (MoveDirectEnum)Segment.ExcuteMoveDirect;
                                }
                            }
                            #endregion

                            #region 计算角度
                            else
                            {
                                //if (Math.Round(UpLand.LandX, 1, MidpointRounding.AwayFromZero) == Math.Round(InflectLand.LandX, 1, MidpointRounding.AwayFromZero))
                                if (UpLand.LandX == InflectLand.LandX)
                                {
                                    //找对应的行走线段
                                    AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == UpLand.LandmarkCode && p.EndLandMarkCode == InflectLand.LandmarkCode);
                                    if (Seg != null && Seg.ExcuteAngle != -1)
                                    {
                                        UpLand.Angle = Seg.ExcuteAngle;
                                    }
                                    else
                                    {
                                        if (InflectLand.LandY > UpLand.LandY)//地图上北
                                        {
                                            if (dtCoor.Rows.Count > 0)
                                            {
                                                DataRow dr = dtCoor.Select("Direction=" + 0).FirstOrDefault();
                                                UpLand.Angle = Convert.ToInt16(dr["Angle"]);
                                            }
                                            else
                                            {
                                                UpLand.Angle = 90;
                                            }
                                        }
                                        else//地图下南
                                        {
                                            if (dtCoor.Rows.Count > 0)
                                            {
                                                DataRow dr = dtCoor.Select("Direction=" + 2).FirstOrDefault();
                                                UpLand.Angle = Convert.ToInt16(dr["Angle"]);
                                            }
                                            else
                                            {
                                                UpLand.Angle = 270;
                                            }
                                        }
                                    }
                                }
                                //else if (Math.Round(UpLand.LandY, 1, MidpointRounding.AwayFromZero) == Math.Round(InflectLand.LandY, 1, MidpointRounding.AwayFromZero))
                                else if (UpLand.LandY == InflectLand.LandY)
                                {
                                    //找对应的行走线段
                                    AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == UpLand.LandmarkCode && p.EndLandMarkCode == InflectLand.LandmarkCode);
                                    if (Seg != null && Seg.ExcuteAngle != -1)
                                    {
                                        UpLand.Angle = Seg.ExcuteAngle;
                                    }
                                    else
                                    {
                                        if (InflectLand.LandX > UpLand.LandX)//地图右东
                                        {
                                            if (dtCoor.Rows.Count > 0)
                                            {
                                                DataRow dr = dtCoor.Select("Direction=" + 1).FirstOrDefault();
                                                UpLand.Angle = Convert.ToInt16(dr["Angle"]);
                                            }
                                            else
                                            {
                                                UpLand.Angle = 0;
                                            }
                                        }
                                        else//地图左西
                                        {
                                            if (dtCoor.Rows.Count > 0)
                                            {
                                                DataRow dr = dtCoor.Select("Direction=" + 3).FirstOrDefault();
                                                UpLand.Angle = Convert.ToInt16(dr["Angle"]);
                                            }
                                            else
                                            {
                                                UpLand.Angle = 180;
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            #region 计算转向
                            if (IsCountAngel == 0)
                            {
                                AllSegment SegmentUPLand = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == UpLand.LandmarkCode && p.EndLandMarkCode == InflectLand.LandmarkCode);
                                if (SegmentUPLand != null && SegmentUPLand.ExcuteTurnDirect != -1)
                                {
                                    UpLand.sway = (SwayEnum)SegmentUPLand.ExcuteTurnDirect;
                                }
                                else
                                {
                                    if (AllSegs.Count(p => p.BeginLandMakCode == UpLand.LandmarkCode) > 1)
                                    {
                                        //double SP = (Math.Round(UpLand.LandX, 3) - Math.Round(NextLand.LandX, 3)) * (Math.Round(InflectLand.LandY, 3) - Math.Round(NextLand.LandY, 3)) - (Math.Round(UpLand.LandY, 3) - Math.Round(NextLand.LandY, 3)) * (Math.Round(InflectLand.LandX, 3) - Math.Round(NextLand.LandX, 3));
                                        double SP = (UpLand.LandX - NextLand.LandX) * (InflectLand.LandY - NextLand.LandY) - (UpLand.LandY - NextLand.LandY) * (InflectLand.LandX - NextLand.LandX);
                                        if (SP > 0.05)
                                        {
                                            UpLand.sway = SwayEnum.Left;
                                        }
                                        else if (SP < -0.05)
                                        {
                                            UpLand.sway = SwayEnum.Right;
                                        }
                                        else
                                        {
                                            UpLand.sway = SwayEnum.None;
                                        }
                                    }
                                }
                                if (SegmentUPLand != null && SegmentUPLand.ExcuteMoveDirect != -1)
                                {
                                    UpLand.movedirect = (MoveDirectEnum)SegmentUPLand.ExcuteMoveDirect;
                                }

                                AllSegment Segment = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == InflectLand.LandmarkCode && p.EndLandMarkCode == NextLand.LandmarkCode);
                                if (Segment != null && Segment.ExcuteTurnDirect != -1)
                                {
                                    InflectLand.sway = (SwayEnum)Segment.ExcuteTurnDirect;
                                }
                                if (Segment != null && Segment.ExcuteMoveDirect != -1)
                                {
                                    InflectLand.movedirect = (MoveDirectEnum)Segment.ExcuteMoveDirect;
                                }
                            }
                            #endregion

                            #region 计算角度
                            else
                            {
                                //if (Math.Round(InflectLand.LandX, 1, MidpointRounding.AwayFromZero) == Math.Round(NextLand.LandX, 1, MidpointRounding.AwayFromZero))
                                if (InflectLand.LandX == NextLand.LandX)
                                {
                                    //找对应的行走线段
                                    AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == InflectLand.LandmarkCode && p.EndLandMarkCode == NextLand.LandmarkCode);
                                    if (Seg != null && Seg.ExcuteAngle != -1)
                                    {
                                        InflectLand.Angle = Seg.ExcuteAngle;
                                    }
                                    else
                                    {
                                        if (NextLand.LandY > InflectLand.LandY)//地图上北
                                        {
                                            if (dtCoor.Rows.Count > 0)
                                            {
                                                DataRow dr = dtCoor.Select("Direction=" + 0).FirstOrDefault();
                                                InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                            }
                                            else
                                            {
                                                InflectLand.Angle = 90;
                                            }
                                        }
                                        else//地图下南
                                        {
                                            if (dtCoor.Rows.Count > 0)
                                            {
                                                DataRow dr = dtCoor.Select("Direction=" + 2).FirstOrDefault();
                                                InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                            }
                                            else
                                            {
                                                InflectLand.Angle = 270;
                                            }
                                        }
                                    }
                                }
                                //else if (Math.Round(InflectLand.LandY, 1, MidpointRounding.AwayFromZero) == Math.Round(NextLand.LandY, 1, MidpointRounding.AwayFromZero))
                                else if (InflectLand.LandY == NextLand.LandY)
                                {
                                    AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == InflectLand.LandmarkCode && p.EndLandMarkCode == NextLand.LandmarkCode);
                                    if (Seg != null && Seg.ExcuteAngle != -1)
                                    {
                                        InflectLand.Angle = Seg.ExcuteAngle;
                                    }
                                    else
                                    {
                                        if (NextLand.LandX > InflectLand.LandX)//地图右东
                                        {
                                            if (dtCoor.Rows.Count > 0)
                                            {
                                                DataRow dr = dtCoor.Select("Direction=" + 1).FirstOrDefault();
                                                InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                            }
                                            else
                                            {
                                                InflectLand.Angle = 0;
                                            }
                                        }
                                        else//地图左西
                                        {
                                            if (dtCoor.Rows.Count > 0)
                                            {
                                                DataRow dr = dtCoor.Select("Direction=" + 3).FirstOrDefault();
                                                InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                            }
                                            else
                                            {
                                                InflectLand.Angle = 180;
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                    }//end foreach
                }
                else
                {
                    #region 计算转向
                    if (IsCountAngel == 0)
                    {
                        InflectLand = Routes[0];
                        NextLand    = Routes[1];
                        AllSegment Segment = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == InflectLand.LandmarkCode && p.EndLandMarkCode == NextLand.LandmarkCode);
                        if (Segment != null && Segment.ExcuteTurnDirect != -1)
                        {
                            InflectLand.sway = (SwayEnum)Segment.ExcuteTurnDirect;
                        }
                        if (Segment != null && Segment.ExcuteMoveDirect != -1)
                        {
                            InflectLand.movedirect = (MoveDirectEnum)Segment.ExcuteMoveDirect;
                        }
                    }
                    #endregion

                    #region 计算角度
                    else
                    {
                        InflectLand = Routes[0];
                        NextLand    = Routes[1];
                        //if (Math.Round(InflectLand.LandX, 1, MidpointRounding.AwayFromZero) == Math.Round(NextLand.LandX, 1, MidpointRounding.AwayFromZero))
                        if (InflectLand.LandX == NextLand.LandX)
                        {
                            //找对应的行走线段
                            AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == InflectLand.LandmarkCode && p.EndLandMarkCode == NextLand.LandmarkCode);
                            if (Seg != null && Seg.ExcuteAngle != -1)
                            {
                                InflectLand.Angle = Seg.ExcuteAngle;
                            }
                            else
                            {
                                if (NextLand.LandY > InflectLand.LandY)//地图上北
                                {
                                    if (dtCoor.Rows.Count > 0)
                                    {
                                        DataRow dr = dtCoor.Select("Direction=" + 0).FirstOrDefault();
                                        InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                    }
                                    else
                                    {
                                        InflectLand.Angle = 90;
                                    }
                                }
                                else//地图下南
                                {
                                    if (dtCoor.Rows.Count > 0)
                                    {
                                        DataRow dr = dtCoor.Select("Direction=" + 2).FirstOrDefault();
                                        InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                    }
                                    else
                                    {
                                        InflectLand.Angle = 270;
                                    }
                                }
                            }
                        }
                        //else if (Math.Round(InflectLand.LandY, 1, MidpointRounding.AwayFromZero) == Math.Round(NextLand.LandY, 1, MidpointRounding.AwayFromZero))
                        else if (InflectLand.LandY == NextLand.LandY)
                        {
                            AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == InflectLand.LandmarkCode && p.EndLandMarkCode == NextLand.LandmarkCode);
                            if (Seg != null && Seg.ExcuteAngle != -1)
                            {
                                InflectLand.Angle = Seg.ExcuteAngle;
                            }
                            else
                            {
                                if (NextLand.LandX > InflectLand.LandX)//地图右东
                                {
                                    if (dtCoor.Rows.Count > 0)
                                    {
                                        DataRow dr = dtCoor.Select("Direction=" + 1).FirstOrDefault();
                                        InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                    }
                                    else
                                    {
                                        InflectLand.Angle = 0;
                                    }
                                }
                                else//地图左西
                                {
                                    if (dtCoor.Rows.Count > 0)
                                    {
                                        DataRow dr = dtCoor.Select("Direction=" + 3).FirstOrDefault();
                                        InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                    }
                                    else
                                    {
                                        InflectLand.Angle = 180;
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            { throw ex; }
        }
Esempio n. 15
0
 public RoutePlanData(IList <AllSegment> Segs)
 {
     Segments = Segs;
     AllLands = AGVClientDAccess.LoadLandByCondition("1=1");
 }
Esempio n. 16
0
        //计算转向和前进和后退
        public void AcountDirect(ref List <LandmarkInfo> Routes)
        {
            try
            {
                IList <AllSegment> AllSegs     = AGVClientDAccess.LoadAllSegment();
                DataTable          dtCoor      = AGVClientDAccess.LoadAGVCoordinate();
                LandmarkInfo       UpLand      = null;
                LandmarkInfo       InflectLand = null;
                LandmarkInfo       NextLand    = null;
                if (Routes.Count <= 1)
                {
                    return;
                }
                else if (Routes.Count >= 3)
                {
                    for (int i = 2; i < Routes.Count; i++)
                    {
                        UpLand      = Routes[i - 2];
                        InflectLand = Routes[i - 1];
                        NextLand    = Routes[i];
                        //判断退进
                        //    var A = Math.Atan2(Math.Round(NextLand.LandY, 3) - Math.Round(InflectLand.LandY, 3), Math.Round(NextLand.LandX, 3) - Math.Round(InflectLand.LandX, 3));
                        //    var B = Math.Atan2(Math.Round(UpLand.LandY, 3) - Math.Round(InflectLand.LandY, 3), Math.Round(UpLand.LandX, 3) - Math.Round(InflectLand.LandX, 3));
                        //    var C = B - A;
                        //    double angel = (180 * (float)C) / Math.PI;
                        //    if (Math.Abs(angel) < 90)
                        //    { InflectLand.IsBack = true; }


                        double SP = (Math.Round(UpLand.LandX, 3) - Math.Round(NextLand.LandX, 3)) * (Math.Round(InflectLand.LandY, 3) - Math.Round(NextLand.LandY, 3)) - (Math.Round(UpLand.LandY, 3) - Math.Round(NextLand.LandY, 3)) * (Math.Round(InflectLand.LandX, 3) - Math.Round(NextLand.LandX, 3));
                        if (SP > 0.05)
                        {
                            InflectLand.sway = SwayEnum.Left;
                        }
                        else if (SP < -0.05)
                        {
                            InflectLand.sway = SwayEnum.Right;
                        }
                        else
                        {
                            InflectLand.sway = SwayEnum.None;
                        }

                        //判断第一个地标角度
                        if (i == 2)//计算开始行走的角度
                        {
                            if (Math.Round(UpLand.LandX, 1, MidpointRounding.AwayFromZero) == Math.Round(InflectLand.LandX, 1, MidpointRounding.AwayFromZero))
                            {
                                //找对应的行走线段
                                AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == UpLand.LandmarkCode && p.EndLandMarkCode == InflectLand.LandmarkCode);
                                if (Seg != null && Seg.ExcuteAngle != -1)
                                {
                                    UpLand.Angle = Seg.ExcuteAngle;
                                }
                                else
                                {
                                    if (InflectLand.LandY > UpLand.LandY)//地图上北
                                    {
                                        if (dtCoor.Rows.Count > 0)
                                        {
                                            DataRow dr = dtCoor.Select("Direction=" + 0).FirstOrDefault();
                                            UpLand.Angle = Convert.ToInt16(dr["Angle"]);
                                        }
                                        else
                                        {
                                            UpLand.Angle = 90;
                                        }
                                    }
                                    else//地图下南
                                    {
                                        if (dtCoor.Rows.Count > 0)
                                        {
                                            DataRow dr = dtCoor.Select("Direction=" + 2).FirstOrDefault();
                                            UpLand.Angle = Convert.ToInt16(dr["Angle"]);
                                        }
                                        else
                                        {
                                            UpLand.Angle = 270;
                                        }
                                    }
                                }
                            }
                            else if (Math.Round(UpLand.LandY, 1, MidpointRounding.AwayFromZero) == Math.Round(InflectLand.LandY, 1, MidpointRounding.AwayFromZero))
                            {
                                //找对应的行走线段
                                AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == UpLand.LandmarkCode && p.EndLandMarkCode == InflectLand.LandmarkCode);
                                if (Seg != null && Seg.ExcuteAngle != -1)
                                {
                                    UpLand.Angle = Seg.ExcuteAngle;
                                }
                                else
                                {
                                    if (InflectLand.LandX > UpLand.LandX)//地图右东
                                    {
                                        if (dtCoor.Rows.Count > 0)
                                        {
                                            DataRow dr = dtCoor.Select("Direction=" + 1).FirstOrDefault();
                                            UpLand.Angle = Convert.ToInt16(dr["Angle"]);
                                        }
                                        else
                                        {
                                            UpLand.Angle = 0;
                                        }
                                    }
                                    else//地图左西
                                    {
                                        if (dtCoor.Rows.Count > 0)
                                        {
                                            DataRow dr = dtCoor.Select("Direction=" + 3).FirstOrDefault();
                                            UpLand.Angle = Convert.ToInt16(dr["Angle"]);
                                        }
                                        else
                                        {
                                            UpLand.Angle = 180;
                                        }
                                    }
                                }
                            }
                        }

                        //判断最后一个地标的角度
                        if (i == Routes.Count - 1)//计算开始行走的角度
                        {
                            NextLand.Angle = InflectLand.Angle;
                        }


                        if (SP > 0.05 || SP < -0.05)
                        {
                            if (Math.Round(InflectLand.LandX, 1, MidpointRounding.AwayFromZero) == Math.Round(NextLand.LandX, 1, MidpointRounding.AwayFromZero))
                            {
                                //找对应的行走线段
                                AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == InflectLand.LandmarkCode && p.EndLandMarkCode == NextLand.LandmarkCode);
                                if (Seg != null && Seg.ExcuteAngle != -1)
                                {
                                    InflectLand.Angle = Seg.ExcuteAngle;
                                }
                                else
                                {
                                    if (NextLand.LandY > InflectLand.LandY)//地图上北
                                    {
                                        if (dtCoor.Rows.Count > 0)
                                        {
                                            DataRow dr = dtCoor.Select("Direction=" + 0).FirstOrDefault();
                                            InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                        }
                                        else
                                        {
                                            InflectLand.Angle = 90;
                                        }
                                    }
                                    else//地图下南
                                    {
                                        if (dtCoor.Rows.Count > 0)
                                        {
                                            DataRow dr = dtCoor.Select("Direction=" + 2).FirstOrDefault();
                                            InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                        }
                                        else
                                        {
                                            InflectLand.Angle = 270;
                                        }
                                    }
                                }
                            }
                            else if (Math.Round(InflectLand.LandY, 1, MidpointRounding.AwayFromZero) == Math.Round(NextLand.LandY, 1, MidpointRounding.AwayFromZero))
                            {
                                AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == InflectLand.LandmarkCode && p.EndLandMarkCode == NextLand.LandmarkCode);
                                if (Seg != null && Seg.ExcuteAngle != -1)
                                {
                                    InflectLand.Angle = Seg.ExcuteAngle;
                                }
                                else
                                {
                                    if (NextLand.LandX > InflectLand.LandX)//地图右东
                                    {
                                        if (dtCoor.Rows.Count > 0)
                                        {
                                            DataRow dr = dtCoor.Select("Direction=" + 1).FirstOrDefault();
                                            InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                        }
                                        else
                                        {
                                            InflectLand.Angle = 0;
                                        }
                                    }
                                    else//地图左西
                                    {
                                        if (dtCoor.Rows.Count > 0)
                                        {
                                            DataRow dr = dtCoor.Select("Direction=" + 3).FirstOrDefault();
                                            InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                        }
                                        else
                                        {
                                            InflectLand.Angle = 180;
                                        }
                                    }
                                }
                            }
                        }
                    }//end foreach
                }
                else
                {
                    InflectLand = Routes[0];
                    NextLand    = Routes[1];
                    if (Math.Round(InflectLand.LandX, 1, MidpointRounding.AwayFromZero) == Math.Round(NextLand.LandX, 1, MidpointRounding.AwayFromZero))
                    {
                        //找对应的行走线段
                        AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == InflectLand.LandmarkCode && p.EndLandMarkCode == NextLand.LandmarkCode);
                        if (Seg != null && Seg.ExcuteAngle != -1)
                        {
                            InflectLand.Angle = Seg.ExcuteAngle;
                        }
                        else
                        {
                            if (NextLand.LandY > InflectLand.LandY)//地图上北
                            {
                                if (dtCoor.Rows.Count > 0)
                                {
                                    DataRow dr = dtCoor.Select("Direction=" + 0).FirstOrDefault();
                                    InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                }
                                else
                                {
                                    InflectLand.Angle = 90;
                                }
                            }
                            else//地图下南
                            {
                                if (dtCoor.Rows.Count > 0)
                                {
                                    DataRow dr = dtCoor.Select("Direction=" + 2).FirstOrDefault();
                                    InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                }
                                else
                                {
                                    InflectLand.Angle = 270;
                                }
                            }
                        }
                    }
                    else if (Math.Round(InflectLand.LandY, 1, MidpointRounding.AwayFromZero) == Math.Round(NextLand.LandY, 1, MidpointRounding.AwayFromZero))
                    {
                        AllSegment Seg = AllSegs.FirstOrDefault(p => p.BeginLandMakCode == InflectLand.LandmarkCode && p.EndLandMarkCode == NextLand.LandmarkCode);
                        if (Seg != null && Seg.ExcuteAngle != -1)
                        {
                            InflectLand.Angle = Seg.ExcuteAngle;
                        }
                        else
                        {
                            if (NextLand.LandX > InflectLand.LandX)//地图右东
                            {
                                if (dtCoor.Rows.Count > 0)
                                {
                                    DataRow dr = dtCoor.Select("Direction=" + 1).FirstOrDefault();
                                    InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                }
                                else
                                {
                                    InflectLand.Angle = 0;
                                }
                            }
                            else//地图左西
                            {
                                if (dtCoor.Rows.Count > 0)
                                {
                                    DataRow dr = dtCoor.Select("Direction=" + 3).FirstOrDefault();
                                    InflectLand.Angle = Convert.ToInt16(dr["Angle"]);
                                }
                                else
                                {
                                    InflectLand.Angle = 180;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            { throw ex; }
        }
Esempio n. 17
0
        public List <LandmarkInfo> GetRoute(LandmarkInfo StartLand, LandmarkInfo EndLand)
        {
            try
            {
                List <List <LandmarkInfo> > hs_route = new List <List <LandmarkInfo> >();
                AcountRoute(StartLand, EndLand);
                hs_route.Add(CreateDeepCopy <List <LandmarkInfo> >(RouteList));
                List <LandmarkInfo> OrialRoute = CreateDeepCopy <List <LandmarkInfo> >(RouteList);
                List <LandmarkInfo> OrialClose = CreateDeepCopy <List <LandmarkInfo> >(CloseList);
                Stack NewPivotAnotherLand      = CreateDeepCopy <Stack>(PivotAnotherLand);
                while (NewPivotAnotherLand.Count > 0)
                {
                    PivotAnotherLand.Clear();
                    RouteList = CreateDeepCopy <List <LandmarkInfo> >(OrialRoute);
                    CloseList = CreateDeepCopy <List <LandmarkInfo> >(OrialClose);
                    Hashtable    hs        = NewPivotAnotherLand.Pop() as Hashtable;
                    ArrayList    keyList   = new ArrayList(hs.Keys);
                    LandmarkInfo PivotLand = hs[keyList[0].ToString()] as LandmarkInfo;



                    int index      = RouteList.FindIndex(p => p.LandmarkCode == keyList[0].ToString()) + 1;
                    int indexClose = CloseList.FindIndex(p => p.LandmarkCode == keyList[0].ToString()) + 1;
                    RouteList.RemoveRange(index, RouteList.Count - index);
                    CloseList.RemoveRange(indexClose, CloseList.Count - indexClose);
                    AcountRoute(PivotLand, EndLand);
                    hs_route.Add(CreateDeepCopy <List <LandmarkInfo> >(RouteList));
                }
                List <LandmarkInfo> Routes = null;
                SysParameter        sys    = AGVClientDAccess.GetParameterByCode("RouteCountMode");
                if (sys != null)
                {
                    if (sys.ParameterValue == "最少地标数")
                    {
                        Routes = (from a in hs_route
                                  where a.Where(p => p.LandmarkCode == EndLand.LandmarkCode).Count() > 0
                                  orderby a.Count ascending
                                  select a).FirstOrDefault();
                    }
                    else if (sys.ParameterValue == "最少拐弯")
                    {
                        Routes = (from a in hs_route
                                  where a.Where(p => p.LandmarkCode == EndLand.LandmarkCode).Count() > 0
                                  orderby a.Count ascending
                                  select a).FirstOrDefault();

                        Routes = (from a in hs_route
                                  where a.Where(p => p.LandmarkCode == EndLand.LandmarkCode).Count() > 0
                                  orderby AcountInflect(a) ascending
                                  select a).FirstOrDefault();
                    }
                }
                else
                {
                    Routes = (from a in hs_route
                              where a.Where(p => p.LandmarkCode == EndLand.LandmarkCode).Count() > 0
                              orderby a.Count ascending
                              select a).FirstOrDefault();
                }
                if (Routes == null)
                {
                    Routes = new List <LandmarkInfo>();
                }
                //this.RouteList = Routes;
                AcountDirect(ref Routes);
                return(Routes);
            }
            catch (Exception ex)
            { throw ex; }
        }
Esempio n. 18
0
        public bool Inital()
        {
            try
            {
                MoniCars.Clear();
                AllCar               = AGVClientDAccess.LoadAGVAchive();
                AllLands             = AGVClientDAccess.LoadLandByCondition("1=1");
                AllSegs              = AGVClientDAccess.LoadAllSegment();
                SimulatorVar.AllSegs = AllSegs;
                Stores               = AGVClientDAccess.LoadStorages();
                System               = AGVSimulationDAccess.LoadSystem();
                foreach (CarBaseStateInfo item in AllCar)
                {
                    CarMonitor moniCar = new CarMonitor();
                    moniCar.AgvID           = item.AgvID;
                    moniCar.CurrSite        = Convert.ToInt32(item.StandbyLandMark);
                    moniCar.StandbyLandMark = item.StandbyLandMark;
                    double ScalingRate    = 0;
                    string ScalingRateStr = System["ScalingRate"].ToString();
                    try
                    {
                        ScalingRate = Convert.ToDouble(ScalingRateStr);
                    }
                    catch
                    { }
                    if (ScalingRate > 0)
                    {
                        LandmarkInfo CurrLand = AllLands.FirstOrDefault(p => p.LandmarkCode == item.StandbyLandMark);
                        if (CurrLand != null)
                        {
                            moniCar.X = (float)(CurrLand.LandX * ScalingRate);
                            moniCar.Y = (float)(CurrLand.LandY * ScalingRate);
                        }
                    }
                    moniCar.ScalingRate = ScalingRate;
                    MoniCars.Add(moniCar);
                }
                if (Car_Ini != null)
                {
                    Car_Ini(MoniCars);
                }
                //Juncts.Clear();
                //IList<TrafficController> Traffics = AGVClientDAccess.GetTraffics();
                //foreach (TrafficController item in Traffics)
                //{
                //    JunctionInfo junct = new JunctionInfo();
                //    foreach (string s in item.EnterLandCode.Split(','))
                //    { junct.JunctionLandMarkCodes.Add(s); }
                //    junct.JunctionID = item.JunctionID;
                //    foreach (string s in item.JunctionLandMarkCodes.Split(','))
                //    { junct.JunctionLandMarkCodes.Add(s); }
                //    junct.RealseLandMarkCode = item.RealseLandMarkCode;
                //    Juncts.Add(junct);
                //}

                CountRoute = new RoutePlanData(AllSegs);
                Traffic    = new TrafficController(MoniCars, AllSegs, System, AllLands);
                timerStarBeStopedCar.Enabled   = true;
                timerStarBeStopedCar.AutoReset = true;
                timerStarBeStopedCar.Elapsed  += TimerStarBeStopedCar_Elapsed;
                timerFreshTask.Enabled         = true;
                timerFreshTask.AutoReset       = true;
                timerFreshTask.Elapsed        += TimerFreshTask_Elapsed;
                return(true);
            }
            catch (Exception ex)
            { return(false); throw ex; }
        }
        /// <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);
            }
        }
Esempio n. 20
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);
            }
        }
        /// <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);
            }
        }