Exemple #1
0
        public bool SetDevWorking(uint devid, bool working, out DeviceTypeE type)
        {
            Device dev = DeviceList.Find(c => c.id == devid);

            if (dev != null)
            {
                dev.do_work = working;
                PubMaster.Mod.DevSql.EditDevice(dev);
                type = dev.Type;
                return(true);
            }
            type = DeviceTypeE.其他;
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// 获取最大储砖轨道order
        /// </summary>
        /// <returns></returns>
        public int GetMaxOrder(ushort area, DeviceTypeE dt)
        {
            switch (dt)
            {
            case DeviceTypeE.摆渡:
                return(TrackList.FindAll(c => c.area == area &&
                                         c.InType(TrackTypeE.储砖_出入, TrackTypeE.砖轨道, TrackTypeE.储砖_出)).Max(c => c.order));

            case DeviceTypeE.摆渡:
                return(TrackList.FindAll(c => c.area == area &&
                                         c.InType(TrackTypeE.储砖_出入, TrackTypeE.砖轨道, TrackTypeE.储砖_入)).Max(c => c.order));

            default:
                return(0);
            }
        }
Exemple #3
0
        public bool GetTrackFerryCode(uint take_track_id, DeviceTypeE ferrytype, out ushort trackferrycode, out string result)
        {
            result         = "";
            trackferrycode = 0;
            Track track = TrackList.Find(c => c.id == take_track_id);

            if (track != null)
            {
                switch (track.Type)
                {
                case TrackTypeE.砖轨道:
                case TrackTypeE.储砖_入:
                    trackferrycode = track.ferry_up_code;
                    break;

                case TrackTypeE.砖轨道:
                case TrackTypeE.储砖_出:
                    trackferrycode = track.ferry_down_code;
                    break;

                case TrackTypeE.储砖_出入:
                    if (ferrytype == DeviceTypeE.摆渡)
                    {
                        trackferrycode = track.ferry_up_code;
                    }
                    else
                    {
                        trackferrycode = track.ferry_down_code;
                    }
                    break;

                default:

                    break;
                }

                if (trackferrycode != 0)
                {
                    result = "";
                    return(true);
                }
            }

            result = "找不到轨道信息";
            return(false);
        }
Exemple #4
0
        /// <summary>
        /// 获取摆渡车ID或摆渡车轨道的ID
        /// </summary>
        /// <param name="trans"></param>
        /// <param name="istrackid"></param>
        /// <returns></returns>
        public List <uint> GetFerryWithTrackInOut(DeviceTypeE ferrytype, uint areaid, uint taketrackid, uint givetrackid, uint cartrackid, bool istrackid)
        {
            List <uint>       list   = new List <uint>();
            List <AreaDevice> ferrys = AreaDevList.FindAll(c => c.area_id == areaid && c.DevType == ferrytype);

            if (ferrys != null && ferrys.Count > 0)
            {
                bool takematch, givematch, carmatch;
                foreach (AreaDevice device in ferrys)
                {
                    takematch = taketrackid == 0 || AreaDevTraList.Exists(c => c.device_id == device.device_id &&
                                                                          c.area_id == device.area_id &&
                                                                          c.track_id == taketrackid);
                    givematch = givetrackid == 0 || AreaDevTraList.Exists(c => c.device_id == device.device_id &&
                                                                          c.area_id == device.area_id &&
                                                                          c.track_id == givetrackid);
                    carmatch = cartrackid == 0 || AreaDevTraList.Exists(c => c.device_id == device.device_id &&
                                                                        c.area_id == device.area_id &&
                                                                        c.track_id == cartrackid);

                    if (takematch && givematch && carmatch)
                    {
                        if (istrackid)
                        {
                            uint trackid = PubMaster.Device.GetFerryTrackId(device.device_id);
                            if (trackid > 0)
                            {
                                list.Add(trackid);
                            }
                        }
                        else
                        {
                            list.Add(device.device_id);
                        }
                    }
                }
            }

            return(list);
        }
Exemple #5
0
        /// <summary>
        /// 根据交易信息分配摆渡车
        /// 1.取货轨道是否有车
        /// 2.卸货轨道是否有车
        /// 3.摆渡车上是否有车
        /// 4.根据上下砖机轨道优先级逐轨道是否有车
        /// 5.对面储砖区域(上下砖机轨道对应的兄弟轨道是否有车)
        /// 6.对面区域摆渡车是否有车
        /// 7.对面砖机轨道是否有车
        /// </summary>
        /// <param name="trans"></param>
        /// <param name="ferrytype"></param>
        /// <param name="priortrackid"></param>
        /// <param name="ferryid"></param>
        /// <param name="result"></param>
        /// <param name="carTraid"> 倒库车当前位置 </param>
        /// <returns></returns>
        public bool AllocateFerry(StockTrans trans, DeviceTypeE ferrytype, uint priortrackid, out uint ferryid, out string result)
        {
            result  = "";
            ferryid = 0;
            if (Monitor.TryEnter(_obj, TimeSpan.FromSeconds(2)))
            {
                try
                {
                    //3.1获取能到达[取货/卸货]轨道的摆渡车的ID
                    List <uint> ferryids;
                    Track       carrierTrack = PubTask.Carrier.GetCarrierTrack(trans.carrier_id);
                    bool        isCarInFerry = false;
                    if (carrierTrack.Type == enums.track.TrackTypeE.摆渡车_入 || carrierTrack.Type == enums.track.TrackTypeE.摆渡车_出)
                    {
                        isCarInFerry = true;
                    }

                    if (trans.TransType == TransTypeE.倒库)
                    {
                        ferryids = PubMaster.Area.GetFerryWithTrackInOut(ferrytype, trans.area_id, 0, trans.give_track_id, isCarInFerry ? 0 : carrierTrack.id, false);
                    }
                    else
                    {
                        ferryids = PubMaster.Area.GetFerryWithTrackInOut(ferrytype, trans.area_id, trans.take_track_id, trans.give_track_id, isCarInFerry ? 0 : carrierTrack.id, false);
                    }

                    //3.2摆渡车上是否有车[空闲,无货]
                    List <FerryTask> ferrys = DevList.FindAll(c => ferryids.Contains(c.ID));

                    if (isCarInFerry)
                    {
                        ferryid = DevList.Find(c => c.LeftTrackId == carrierTrack.id)?.ID ?? 0;
                        return(true);
                    }

                    short carrierTrackOrder = carrierTrack.order;

                    if (ferrys.Count > 0)
                    {
                        int safedis = PubMaster.Dic.GetDtlIntCode("FerryAvoidNumber");
                        //判断是否存在有摆渡车已被锁
                        if (ferrys.Exists(c => c.IsFerryLock()) && ferrys.Exists(c => !c.IsFerryLock()))
                        {
                            List <FerryTask> ferryLockeds   = ferrys.FindAll(c => c.IsFerryLock());
                            List <FerryTask> ferryUnLockeds = ferrys.FindAll(c => !c.IsFerryLock());

                            foreach (FerryTask fUnLocked in ferryUnLockeds)
                            {
                                if (CheckFerryStatus(fUnLocked) && (fUnLocked.IsStillLockInTrans(trans.id) || fUnLocked.IsFerryFree()))
                                {
                                    //摆渡车所对着的轨道id
                                    //uint taskUnLockedTrackId = ferrytype == DeviceTypeE.上摆渡 ? fUnLocked.DownTrackId : fUnLocked.UpTrackId;
                                    uint taskUnLockedTrackId = fUnLocked.GetFerryCurrentTrackId();

                                    //摆渡车的当前轨道的顺序
                                    short taskUnLockedCurrentOrder = PubMaster.Track.GetTrack(taskUnLockedTrackId)?.order ?? 0;

                                    int leftCompare, rightCompare;
                                    if (taskUnLockedCurrentOrder >= carrierTrackOrder)
                                    {
                                        leftCompare  = carrierTrackOrder - safedis;
                                        rightCompare = taskUnLockedCurrentOrder + safedis;
                                    }
                                    else
                                    {
                                        leftCompare  = taskUnLockedCurrentOrder - safedis;
                                        rightCompare = carrierTrackOrder + safedis;
                                    }
                                    leftCompare = leftCompare < 0 ? 0 : leftCompare;
                                    bool isChosen = true;
                                    foreach (FerryTask fLocked in ferryLockeds)
                                    {
                                        if (!CheckFerryStatus(fLocked, out string r))
                                        {
                                            continue;
                                        }

                                        if (CheckFerryStatus(fLocked) && fLocked.IsStillLockInTrans(trans.id))
                                        {
                                            ferryid = fLocked.ID;
                                            return(true);
                                        }
                                        //上锁摆渡车所对着的轨道id
                                        //uint taskLockedTrackId = ferrytype == DeviceTypeE.上摆渡 ? fLocked.DownTrackId : fLocked.UpTrackId;
                                        uint taskLockedTrackId = fLocked.GetFerryCurrentTrackId();

                                        //上锁摆渡车的当前轨道的顺序
                                        short taskLockedCurrentOrder = PubMaster.Track.GetTrack(taskLockedTrackId)?.order ?? 0;

                                        //上锁摆渡车的目的轨道的位置顺序
                                        short taskLockedTargetOrder = PubMaster.Track.GetTrackByCode(fLocked.DevStatus.TargetSite)?.order ?? 0;

                                        if ((leftCompare < taskLockedCurrentOrder && taskLockedCurrentOrder < rightCompare) ||
                                            (leftCompare < taskLockedTargetOrder && taskLockedTargetOrder < rightCompare))
                                        {
                                            isChosen = false;
                                            break;
                                        }
                                    }
                                    if (isChosen)
                                    {
                                        ferryid = fUnLocked.ID;
                                        return(true);
                                    }
                                }
                                return(false);
                            }
                        }

                        long distance = 999;
                        //如何判断哪个摆渡车最好储砖
                        foreach (FerryTask ferry in ferrys)
                        {
                            if (CheckFerryStatus(ferry) && (ferry.IsStillLockInTrans(trans.id) || ferry.IsFerryFree()))
                            {
                                // 摆渡车对应轨道号
                                Track ferryTrack = PubMaster.Track.GetTrack(ferry.GetFerryCurrentTrackId());

                                if (ferryTrack == null || ferryTrack.order == 0)
                                {
                                    continue;
                                }
                                //摆渡车跟运输车轨道的差绝对值,   数据库 在录入的轨道order时,砖机轨道的顺序是对着的那条储砖轨道的顺序
                                long d = Math.Abs(ferryTrack.order - carrierTrack.order);
                                if (distance > d)
                                {
                                    distance = d;
                                    ferryid  = ferry.ID;
                                }
                            }
                        }
                        return(ferryid != 0);
                    }
                }
                finally { Monitor.Exit(_obj); }
            }
            return(false);
        }
Exemple #6
0
        /// <summary>
        /// 获取能够同时到达指定轨道的摆渡车ID
        /// </summary>
        /// <param name="ferrytype">摆渡车类型</param>
        /// <param name="traids">轨道可变列表(多个轨道号)</param>
        /// <returns></returns>
        public List <uint> GetWithTracksFerryIds(DeviceTypeE ferrytype, params uint[] traids)
        {
            List <uint> ferryids = PubMaster.Device.GetFerryIds(ferrytype);

            return(GetWithTracksFerryIds(ferryids, traids));
        }
Exemple #7
0
 public List <AreaDevice> GetAreaDevList(uint area_id, DeviceTypeE devtype)
 {
     return(AreaDevList.FindAll(c => c.area_id == area_id && c.DevType == devtype));
 }
        /// <summary>
        /// 根据交易信息分配运输车
        /// 1.取货轨道是否有车
        /// 2.卸货轨道是否有车
        /// 3.摆渡车上是否有车
        /// 4.根据上下砖机轨道优先级逐轨道是否有车
        /// 5.对面储砖区域(上下砖机轨道对应的兄弟轨道是否有车)
        /// 6.对面区域摆渡车是否有车
        /// 7.对面砖机轨道是否有车
        /// </summary>
        /// <param name="trans"></param>
        /// <param name="carrierid"></param>
        /// <returns></returns>
        private bool GetTransInOutCarrier(StockTrans trans, DeviceTypeE ferrytype, out uint carrierid, out string result)
        {
            result    = "";
            carrierid = 0;
            if (trans.goods_id == 0)
            {
                return(false);
            }
            CarrierTypeE needtype = PubMaster.Goods.GetGoodsCarrierType(trans.goods_id);
            // 1.取货轨道是否有车[空闲,无货]
            CarrierTask carrier = DevList.Find(c => c.TrackId == trans.take_track_id && c.CarrierType == needtype);

            if (carrier == null && (trans.TransType == TransTypeE.出库 || trans.TransType == TransTypeE.手动出库))
            {
                uint brothertra = PubMaster.Track.GetBrotherTrackId(trans.take_track_id);
                carrier = DevList.Find(c => c.TrackId == brothertra &&
                                       c.CarrierType == needtype &&
                                       c.Task == DevCarrierTaskE.后退取砖);
            }

            if (carrier == null)
            {
                #region [2.卸货轨道是否有车[空闲,无货]]
                carrier = DevList.Find(c => c.TrackId == trans.give_track_id && c.CarrierType == needtype);
                #endregion

                #region [3.摆渡车上是否有车[空闲,无货]
                if (carrier == null)
                {
                    //3.1 获取能到达[取货/卸货]轨道的摆渡车的ID
                    List <uint> ferrytrackids = PubMaster.Area.GetFerryWithTrackInOut(ferrytype, trans.area_id, trans.take_track_id, trans.give_track_id, 0, true);

                    List <uint> loadcarferryids = new List <uint>();
                    foreach (uint fetraid in ferrytrackids)
                    {
                        uint ferryid = PubMaster.Device.GetFerryIdByFerryTrackId(fetraid);
                        if (PubTask.Ferry.IsLoad(ferryid))
                        {
                            loadcarferryids.Add(fetraid);
                        }
                    }

                    //3.2 获取在摆渡车上的车[空闲,无货]
                    List <CarrierTask> carriers = DevList.FindAll(c => !c.IsLogicAlert() && loadcarferryids.Contains(c.TrackId) && c.CarrierType == needtype);
                    if (carriers.Count > 0)
                    {
                        //如何判断哪个摆渡车最右
                        foreach (CarrierTask car in carriers)
                        {
                            //小车:没有任务绑定
                            if (!PubTask.Trans.HaveInCarrier(car.ID))
                            {
                                switch (trans.TransType)
                                {
                                case TransTypeE.入库:
                                    //空闲,没货,没任务
                                    if (CheckCarrierFreeNotLoad(car))
                                    {
                                        carrierid = car.ID;
                                        return(true);
                                    }
                                    break;

                                case TransTypeE.出库:
                                    //空闲,没任务
                                    if (CheckCarrierFreeNoTask(car))
                                    {
                                        carrierid = car.ID;
                                        return(true);
                                    }
                                    break;

                                case TransTypeE.倒库:
                                    break;

                                case TransTypeE.其他:
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                    }
                }
                #endregion
            }
            //前面找到车了,如果空闲则分配,否则等待



            if (carrier != null)
            {
                switch (trans.TransType)
                {
                case TransTypeE.入库:
                case TransTypeE.手动入库:
                    if (CheckCarrierFreeNotLoad(carrier))
                    {
                        carrierid = carrier.ID;
                        return(true);
                    }
                    break;

                case TransTypeE.出库:
                case TransTypeE.手动出库:
                    if (!carrier.IsWorking)
                    {
                        return(false);
                    }
                    if (carrier.ConnStatus == SocketConnectStatusE.通信正常 &&
                        carrier.OperateMode == DevOperateModeE.自动)
                    {
                        if (carrier.Status == DevCarrierStatusE.停止
                            //&& carrier.WorkMode == DevCarrierWorkModeE.生产模式
                            && (carrier.Task == carrier.FinishTask || carrier.Task == DevCarrierTaskE.无))
                        {
                            carrierid = carrier.ID;
                            return(true);
                        }

                        if (carrier.Task == DevCarrierTaskE.后退取砖 && carrier.FinishTask == DevCarrierTaskE.无)
                        {
                            carrierid = carrier.ID;
                            return(true);
                        }
                    }

                    if (CheckCarrierFreeNoTask(carrier))
                    {
                        carrierid = carrier.ID;
                        return(true);
                    }
                    break;

                case TransTypeE.倒库:
                    break;

                case TransTypeE.其他:
                    break;

                default:
                    break;
                }
            }
            #region [找其他轨道]
            else
            {
                List <uint> trackids = PubMaster.Area.GetTileTrackIds(trans);
                foreach (uint traid in trackids)
                {
                    if (!PubMaster.Track.IsStoreType(traid))
                    {
                        continue;
                    }
                    List <CarrierTask> tasks = DevList.FindAll(c => c.TrackId == traid);
                    if (tasks.Count > 0)
                    {
                        if (tasks.Count > 1)
                        {
                            continue;
                        }
                        if (CheckCarrierFreeNotLoad(tasks[0]) &&
                            tasks[0].CarrierType == needtype &&
                            !PubTask.Trans.HaveInCarrier(tasks[0].ID)
                            )
                        {
                            carrierid = tasks[0].ID;
                            return(true);
                        }
                    }
                }
            }
            #endregion

            return(false);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="trans"></param>
        private void CheckTransAndAddMoveTask(StockTrans trans)
        {
            //如果已经有移车任务则不生成
            if (_M.ExistAreaLineType(trans.area_id, TransTypeE.移车))
            {
                return;
            }

            #region [根据任务区分]

            bool        checktakegivetrack = false;
            DeviceTypeE ferrytype          = DeviceTypeE.其他;
            switch (trans.TransType)
            {
            case TransTypeE.出库:
            case TransTypeE.手动出库:
                checktakegivetrack = true;
                ferrytype          = DeviceTypeE.摆渡;
                break;

            case TransTypeE.入库:
            case TransTypeE.手动入库:
                checktakegivetrack = true;
                ferrytype          = DeviceTypeE.摆渡;
                break;

            case TransTypeE.倒库:
                checktakegivetrack = false;
                ferrytype          = DeviceTypeE.摆渡;
                break;
            }

            #endregion

            //3 _ 有空闲车不能直接到达作业轨道
            List <CarrierTask> carriers = PubTask.Carrier.GetFreeCarrierWithNoDirectFerry(trans, ferrytype, checktakegivetrack,
                                                                                          out List <uint> trackid, out List <uint> ferryid);
            foreach (CarrierTask car in carriers)
            {
                uint cartrackid = car.TrackId;
                //判断运输车所在轨道和任务
                List <uint> ctrackid = PubMaster.Track.SortTrackIdsWithOrder(trackid, cartrackid, PubMaster.Track.GetTrack(car.TrackId)?.order ?? 0);
                foreach (var traid in ctrackid)
                {
                    //轨道被任务或者有车在
                    if (_M.IsTraInTrans(traid) || PubTask.Carrier.HaveInTrack(traid, car.ID))
                    {
                        continue;
                    }

                    if (PubMaster.Area.ExistFerryWithTrack(ferryid, traid) &&
                        PubMaster.Area.GetWithTracksFerryIds(ferrytype, cartrackid, traid).Count > 0)
                    {
                        uint sortaskid = _M.AddTransWithoutLock(trans.area_id, 0, TransTypeE.移车, 0, 0, cartrackid, traid, TransStatusE.移车中, car.ID);
                        if (sortaskid != 0)
                        {
                            _mLog.Status(true, string.Format("标识[ {0} ], [ {1} ]超时, 取[ {2} ] -> 卸[ {3} ], 找不到空闲的运输车", trans.id, trans.TransType,
                                                             PubMaster.Track.GetTrackName(trans.take_track_id),
                                                             PubMaster.Track.GetTrackName(trans.give_track_id)));
                            _mLog.Status(true, string.Format("标识[ {0} ], 移车任务[ {1}], 运输车[ {2} ], 从[ {3} ] -> 到[ {4} ]", trans.id, sortaskid,
                                                             PubMaster.Device.GetDeviceName(car.ID),
                                                             PubMaster.Track.GetTrackName(cartrackid),
                                                             PubMaster.Track.GetTrackName(traid)));
                        }
                        return;
                    }
                }
            }
        }
Exemple #10
0
 public List <Device> GetDeviceList(DeviceTypeE type)
 {
     return(DeviceList.FindAll(c => c.Type == type));;
 }
Exemple #11
0
 public bool IsDevType(uint devid, DeviceTypeE type)
 {
     return(DeviceList.Exists(c => c.id == devid && c.Type == type));
 }
Exemple #12
0
 public List <AreaDevice> GetAreaDevListWithType(DeviceTypeE devtype)
 {
     return(AreaDevList.FindAll(c => c.DevType == devtype));
 }