/// <summary> /// 判断小车是否可以前往轨道 /// 1.该轨道是否已经有小车 /// 2.该轨道的兄弟轨道是否有车 /// 3.两轨道间是否存在库存大于3 /// </summary> /// <param name="trackid"></param> /// <returns></returns> public bool CanCarrierEnterTrack(uint trackid) { CarrierTask carrier = DevList.Find(c => c.TrackId == trackid); if (carrier != null) { return(false); } uint brotherid = PubMaster.Track.GetBrotherTrackId(trackid); if (brotherid == 0) { //没有兄弟轨道,不会碰撞??(可能也是配置漏了) return(true); } carrier = DevList.Find(c => c.TrackId == brotherid); if (carrier != null) { if ((PubMaster.Goods.GetTrackStock(trackid) + PubMaster.Goods.GetTrackStock(brotherid)) > 3) { return(true); } } return(true); }
private void CarrierMsgUpdate(SocketMsgMod mod) { if (mod != null) { if (Monitor.TryEnter(_obj, TimeSpan.FromSeconds(2))) { try { CarrierTask task = DevList.Find(c => c.ID == mod.ID); if (task != null) { task.ConnStatus = mod.ConnStatus; if (mod.Device is DevCarrier carrier) { task.DevStatus = carrier; task.UpdateInfo(); CheckDev(task); if (carrier.IsUpdate || mTimer.IsTimeOutAndReset(TimerTag.DevRefreshTimeOut, carrier.ID, 5)) { MsgSend(task, carrier); } } CheckConn(task); } } catch (Exception e) { mlog.Error(true, e.Message, e); } finally { Monitor.Exit(_obj); } } } }
public void StartStopCarrier(uint carrierid, bool isstart) { if (Monitor.TryEnter(_obj, TimeSpan.FromSeconds(2))) { try { CarrierTask task = DevList.Find(c => c.ID == carrierid); if (task != null) { if (isstart) { if (!task.IsEnable) { task.SetEnable(isstart); } task.Start(); } else { if (task.IsEnable) { task.SetEnable(isstart); } task.Stop(); PubMaster.Warn.RemoveDevWarn((ushort)task.ID); } } } finally { Monitor.Exit(_obj); } } }
public void DoTask(uint devid, DevCarrierTaskE carriertask, bool isoversize = false) { if (Monitor.TryEnter(_obj, TimeSpan.FromSeconds(2))) { try { CarrierTask task = DevList.Find(c => c.ID == devid); if (task != null) { if (task.OperateMode == DevOperateModeE.自动) { if (task.Status == DevCarrierStatusE.停止 && task.Task == carriertask && task.FinishTask == carriertask) { carriertask = DevCarrierTaskE.终止; } } else { carriertask = DevCarrierTaskE.终止; } task.DoTask(carriertask, isoversize ? DevCarrierSizeE.超限 : DevCarrierSizeE.非超限); } } finally { Monitor.Exit(_obj); } } }
/// <summary> /// 查找是否存在运输车在指定的轨道 /// 1.ID对应的轨道 /// 2.轨道的兄弟轨道 /// </summary> /// <param name="trackid"></param> /// <returns></returns> internal bool HaveInTrack(uint trackid, out uint carrierid) { Track track = PubMaster.Track.GetTrack(trackid); CarrierTask carrier = DevList.Find(c => c.TrackId == trackid); carrierid = carrier?.ID ?? 0; return(carrier != null); }
private bool GetCarrierInTrack(uint trackid) { Track track = PubMaster.Track.GetTrack(trackid); CarrierTask carrier = DevList.Find(c => track.IsInTrack(c.Site)); if (carrier != null) { } return(false); }
/// <summary> /// 判断小车是否处于任务 /// </summary> /// <param name="carrier_id"></param> /// <param name="carriertask"></param> /// <returns></returns> internal bool IsTaskAndDoTask(uint carrier_id, DevCarrierTaskE carriertask) { CarrierTask task = DevList.Find(c => c.ID == carrier_id); if (task != null) { if (task.Task == carriertask && task.FinishTask == DevCarrierTaskE.终止) { return(true); } task.DoTask(carriertask, DevCarrierSizeE.非超限); } return(false); }
public void SetCarrierAlert(uint carrierid, uint trackid, CarrierAlertE type, bool isalert) { if (Monitor.TryEnter(_obj, TimeSpan.FromSeconds(10))) { try { CarrierTask task = DevList.Find(c => c.ID == carrierid); if (task != null) { task.SetAlert(type, trackid, isalert); } } finally { Monitor.Exit(_obj); } } }
internal bool CheckStatus(uint carrier_id) { if (Monitor.TryEnter(_obj, TimeSpan.FromSeconds(2))) { try { CarrierTask task = DevList.Find(c => c.ID == carrier_id); if (task != null) { return(task.OperateMode != DevOperateModeE.自动); } } finally { Monitor.Exit(_obj); } } return(false); }
internal void UpdateWorking(uint devId, bool working) { if (!Monitor.TryEnter(_obj, TimeSpan.FromSeconds(2))) { return; } try { CarrierTask task = DevList.Find(c => c.ID == devId); if (task != null) { task.IsWorking = working; MsgSend(task, task.DevStatus); } } finally { Monitor.Exit(_obj); } }
private void MsgSend(CarrierTask task, DevCarrier carrier) { if (Monitor.TryEnter(_objmsg, TimeSpan.FromSeconds(5))) { try { mMsg.ID = task.ID; mMsg.Name = task.Device.name; mMsg.o1 = carrier; mMsg.o2 = task.ConnStatus; Messenger.Default.Send(mMsg, MsgToken.CarrierStatusUpdate); } finally { Monitor.Exit(_objmsg); } } }
/// <summary> /// 小车当前是否状态符合/不管有没有货 /// </summary> /// <param name="carrier"></param> /// <returns></returns> private bool CheckCarrierFreeNoTask(CarrierTask carrier) { if (!carrier.IsWorking) { return(false); } if (carrier.ConnStatus == SocketConnectStatusE.通信正常 && carrier.Status == DevCarrierStatusE.停止 && carrier.OperateMode == DevOperateModeE.自动 //&& carrier.WorkMode == DevCarrierWorkModeE.生产模式 && (carrier.Task == carrier.FinishTask || carrier.Task == DevCarrierTaskE.无) //&& carrier.Load == DevCarrierLoadE.无货 ) { return(true); } return(false); }
public void Start() { List <Device> carriers = PubMaster.Device.GetDeviceList(DeviceTypeE.运输车); foreach (Device dev in carriers) { CarrierTask task = new CarrierTask(); task.Device = dev; task.Start(); DevList.Add(task); } if (_mRefresh == null || !_mRefresh.IsAlive || _mRefresh.ThreadState == ThreadState.Aborted) { _mRefresh = new Thread(Refresh) { IsBackground = true }; } _mRefresh.Start(); }
private void CheckConn(CarrierTask task) { switch (task.ConnStatus) { case SocketConnectStatusE.连接成功: case SocketConnectStatusE.通信正常: PubMaster.Warn.RemoveDevWarn(WarningTypeE.DeviceOffline, (ushort)task.ID); break; case SocketConnectStatusE.连接中: case SocketConnectStatusE.连接断开: case SocketConnectStatusE.主动断开: if (task.IsEnable) { PubMaster.Warn.AddDevWarn(WarningTypeE.DeviceOffline, (ushort)task.ID); } break; } if (task.MConChange) { MsgSend(task, task.DevStatus); } }
private static void UpdateFerryLoadStatus(CarrierTask task) { Track tt = PubMaster.Track.GetTrack(task.TrackId); if (tt != null) { switch (tt.Type) { case TrackTypeE.摆渡车_入: case TrackTypeE.摆渡车_出: PubTask.Ferry.UpdateFerryWithTrackId(task.TrackId, DevFerryLoadE.载车); task.LastTrackId = task.TrackId; break; default: if (task.LastTrackId != 0) { PubTask.Ferry.UpdateFerryWithTrackId(task.LastTrackId, DevFerryLoadE.空); task.LastTrackId = 0; } break; } } }
/// <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); }
public bool IsCarrierFree(uint carrierid) { CarrierTask carrier = DevList.Find(c => c.ID == carrierid); return(CheckCarrierFreeNotLoad(carrier)); }
/// <summary> /// 分配倒库小车 /// </summary> /// <param name="trans"></param> /// <param name="carrierid"></param> /// <param name="result"></param> /// <returns></returns> private bool GetTransSortCarrier(StockTrans trans, 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.give_track_id && c.CarrierType == needtype); #region [2.摆渡车上是否有车[空闲,无货] if (carrier == null) { //3.1获取能到达[空轨道]轨道的上砖摆渡车的轨道ID List <uint> ferrytrackids = PubMaster.Area.GetFerryWithTrackInOut(DeviceTypeE.摆渡, trans.area_id, 0, trans.give_track_id, 0, true); //3.2获取在摆渡轨道上的车[空闲,无货] List <CarrierTask> carriers = DevList.FindAll(c => ferrytrackids.Contains(c.TrackId) && c.CarrierType == needtype); if (carriers.Count > 0) { //如何判断哪个摆渡车最右 foreach (CarrierTask car in carriers) { //小车:没有任务绑定 if (!PubTask.Trans.HaveInCarrier(car.ID)) { //空闲,没货,没任务 if (CheckCarrierFreeNotLoad(car)) { carrierid = car.ID; return(true); } } } } } #region [2.满砖轨道是否有车[空闲,无货]] //if (carrier == null) //{ // carrier = DevList.Find(c => c.TrackId == trans.take_track_id); //} #endregion #endregion //前面找到车了,如果空闲则分配,否则等待 if (carrier != null) { if (CheckCarrierFreeNotLoad(carrier)) { carrierid = carrier.ID; return(true); } } #region [直接找车] else { if (trans.area_id != 0) { List <AreaDevice> areatras = PubMaster.Area.GetAreaDevList(trans.area_id, DeviceTypeE.运输车); foreach (AreaDevice areatra in areatras) { CarrierTask task = DevList.Find(c => c.ID == areatra.device_id && c.CarrierType == needtype); if (task != null && CheckCarrierFreeNotLoad(task) && PubMaster.Track.IsTrackType(task.TrackId, TrackTypeE.储砖_出)) { carrierid = task.ID; return(true); } } } } #endregion return(false); }
/// <summary> /// 1.运输车任务状态 /// 2.满砖/空砖/正常取货卸货 /// </summary> /// <param name="task"></param> private void CheckDev(CarrierTask task) { task.CheckAlert(); if (task.OperateMode == DevOperateModeE.手动) { if (task.Task != DevCarrierTaskE.终止 && task.Task != DevCarrierTaskE.无) { DoTask(task.ID, DevCarrierTaskE.终止); } Track track = PubMaster.Track.GetTrack(task.TrackId); if (track.Type == TrackTypeE.摆渡车_入 || track.Type == TrackTypeE.摆渡车_出) { PubTask.Ferry.StopFerryByFerryTrackId(track.id); } } if (task.Status != DevCarrierStatusE.停止) { return; } if (task.OperateMode == DevOperateModeE.无) { task.DoModeUpdate(DevCarrierWorkModeE.生产); } if (task.DevReset == DevCarrierResetE.位 && task.DevStatus.ActionType == DevCarrierSignalE.位) { task.DevReset = DevCarrierResetE.无动作; } //if (task.OperateMode == DevOperateModeE.手动模式) return; //if (task.WorkMode != DevCarrierWorkModeE.生产模式) return; #region [检查任务] #region [倒库完成] //倒库完成后小车回到空轨道今天等待,倒库任务完成,同时有空轨道信息 //if (task.Task == DevCarrierTaskE.后退至轨道倒库 // && task.FinishTask == DevCarrierTaskE.后退至轨道倒库) //{ // if(task.Signal == DevCarrierSignalE.空轨道) // { // PubTask.Trans.ShiftTrans(task.ID, task.TrackId); // } //} //if() #endregion #region [空砖] if (task.Task == DevCarrierTaskE.后退取砖 && task.FinishTask == DevCarrierTaskE.后退取砖) { Track track = PubMaster.Track.GetTrack(task.TrackId); if (track.Type == TrackTypeE.储砖_出 || track.Type == TrackTypeE.储砖_出入) { switch (task.Signal) { case DevCarrierSignalE.空轨道: if (task.Load == DevCarrierLoadE.无货) { PubMaster.Track.UpdateStockStatus(track.id, TrackStockStatusE.空砖, "上砖取空"); PubMaster.Goods.ClearTrackEmtpy(track.id); PubMaster.Track.AddTrackLog((ushort)task.AreaId, task.ID, track.id, TrackLogE.空轨道, "无货"); } else { PubMaster.Track.AddTrackLog((ushort)task.AreaId, task.ID, track.id, TrackLogE.空轨道, "有货"); } break; } task.DevReset = DevCarrierResetE.位; } } if (task.Signal == DevCarrierSignalE.空轨道 && task.Task != DevCarrierTaskE.后退取砖) { task.DevReset = DevCarrierResetE.位; } #endregion #region [非空非满] if (task.Task == DevCarrierTaskE.前进放砖 && task.FinishTask == DevCarrierTaskE.前进放砖 && task.Signal == DevCarrierSignalE.非空非满) { task.DevReset = DevCarrierResetE.位; } #endregion #region [满砖] if (task.Signal == DevCarrierSignalE.满轨道 && task.Task == task.FinishTask) { Track givetrack = PubMaster.Track.GetTrackByCode(task.GiveTrackCode); if (givetrack != null && (givetrack.Type == TrackTypeE.储砖_入 || givetrack.Type == TrackTypeE.储砖_出入)) { ushort storecount = PubMaster.Track.AddTrackLog((ushort)task.AreaId, task.ID, givetrack.id, TrackLogE.满轨道, ""); //ushort areafullqty = PubMaster.Area.GetAreaFullQty(task.AreaId); ushort areafullqty = 8; // 金凯瑞直接8车算了 - -。 if (storecount >= areafullqty) { //PubMaster.Track.SetTrackEaryFull(givetrack.id, true, DateTime.Now); PubMaster.Track.UpdateStockStatus(givetrack.id, TrackStockStatusE.满砖, "下砖放满"); PubMaster.Track.UpdateRecentGood(givetrack.id, 0); PubMaster.Track.UpdateRecentTile(givetrack.id, 0); } } else if (givetrack != null) { PubMaster.Warn.AddDevWarn(WarningTypeE.CarrierFullSignalFullNotOnStoreTrack, (ushort)task.ID); PubMaster.Track.AddTrackLog((ushort)task.AreaId, task.ID, givetrack.id, TrackLogE.满轨道, "非储砖轨道"); } task.DevReset = DevCarrierResetE.位; } //if((task.Site > 300 && task.Site < 400) // || (task.Site > 700 && task.Site <800)) //{ // if(task.Signal == DevCarrierSignalE.满轨道) // { // task.DevReset = DevCarrierResetE.复位; // } //} #endregion #region [倒库] if (task.Task == DevCarrierTaskE.后退至轨道倒库 && task.Signal == DevCarrierSignalE.非空非满 && task.Status == DevCarrierStatusE.停止 && mTimer.IsOver(TimerTag.CarrierSortTakeGive, (ushort)task.ID, 5, 10)) { task.DevReset = DevCarrierResetE.位; } #endregion #region [逻辑警告] task.CheckLogicAlert(); #endregion }