From 4fb7cbfbf4befeff295dd7884c1606b45157f2e6 Mon Sep 17 00:00:00 2001 From: rszn <645583145@qq.com> Date: Sun, 30 Jun 2024 21:13:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E4=BA=8E=E5=B9=B6=E8=A1=8C=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/DbModel/Station/MoveBinRecord.cs | 70 +++++++++++++++ Repository/Station/BinInfoRepository.cs | 40 +++++---- Repository/Station/MoveBinRecordRepository.cs | 14 +++ Service/Execute/Api/PlcApi.cs | 15 ++++ Service/Execute/Mgr/CommonMgr.cs | 48 ++++++++++- Service/Execute/Step/DoSwappingState.cs | 86 +++++++++++-------- Service/Execute/SwappingStateMachine.cs | 15 ++-- Service/MyTask/BatteryMoveTask.cs | 10 ++- Service/Plc/Client/PlcClient.cs | 53 ++++++++---- Service/Plc/Client/PlcMgr.cs | 6 +- Service/Plc/Msg/PlcToHost.cs | 10 +-- Service/Station/MonitorService.cs | 44 ++++++++-- .../Controllers/ChargeMonitorController.cs | 12 +-- 13 files changed, 323 insertions(+), 100 deletions(-) create mode 100644 Entity/DbModel/Station/MoveBinRecord.cs create mode 100644 Repository/Station/MoveBinRecordRepository.cs diff --git a/Entity/DbModel/Station/MoveBinRecord.cs b/Entity/DbModel/Station/MoveBinRecord.cs new file mode 100644 index 0000000..301d650 --- /dev/null +++ b/Entity/DbModel/Station/MoveBinRecord.cs @@ -0,0 +1,70 @@ +using SqlSugar; + +namespace Entity.DbModel.Station; + +/// +///充电订单;充电订单表 +/// +[SugarTable("move_bin_record")] +public class MoveBinRecord : BaseModel +{ + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, ColumnName = "id")] + public int Id { get; set; } + + /// + /// in_bin_no + /// + [SugarColumn(IsPrimaryKey = true, ColumnName = "in_bin_no")] + public string? InBinNo { get; set; } + + /// + /// in_battery_no + /// + [SugarColumn(IsPrimaryKey = true, ColumnName = "in_battery_no")] + public string? InBatteryNo { get; set; } + + /// + /// in_battery_soc + /// + + [SugarColumn(IsPrimaryKey = true, ColumnName = "in_battery_soc")] + public string? InBatterySoc { get; set; } + + + /// + /// in_bin_no + /// + [SugarColumn(IsPrimaryKey = true, ColumnName = "up_bin_no")] + public string? UpBinNo { get; set; } + + /// + /// in_battery_no + /// + [SugarColumn(IsPrimaryKey = true, ColumnName = "up_battery_no")] + public string? UpBatteryNo { get; set; } + + /// + /// in_battery_soc + /// + + [SugarColumn(IsPrimaryKey = true, ColumnName = "up_battery_soc")] + public string? UpBatterySoc { get; set; } + + /// + /// 狀態 0:初始化 1:進行中 2:成功 3:失敗 + /// + [SugarColumn(IsPrimaryKey = true, ColumnName = "status")] + public int Status { get; set; } + + + /// + /// 类型 0:自动 1:手动 + /// + [SugarColumn(IsPrimaryKey = true, ColumnName = "type")] + public int Type { get; set; } +} diff --git a/Repository/Station/BinInfoRepository.cs b/Repository/Station/BinInfoRepository.cs index 5c432cd..6c6b2fa 100644 --- a/Repository/Station/BinInfoRepository.cs +++ b/Repository/Station/BinInfoRepository.cs @@ -19,25 +19,36 @@ public class BinInfoRepository : BaseRepository /// StaticStationInfo.SwapSoc /// StaticStationInfo.SwapFinishChargeTime /// - public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime) + public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime, string upMoveNo) { SelectPackDto selectPackDto = new() { SuccessFlag = false, }; List list = - QueryListByClause(i => i.CacheBinFlag == 0 && i.CanSwapFlag==1 && + QueryListByClause(i => i.CanSwapFlag == 1 && i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock, "in_time asc"); - BinInfo? cacheBinBattery = ChooseCacheBinBattery(swapSoc); - if (list.Count <= 0 && cacheBinBattery == null) + + + // BinInfo? cacheBinBattery = ChooseCacheBinBattery(swapSoc); + + if (list.Count <= 0) { selectPackDto.Info = InfoEnum.SelectBinStatusInfo.NoBattery; return selectPackDto; } - list = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus==4).ToList(); - if (list.Count <= 0 && cacheBinBattery == null) + list = list.OrderBy(i => i.CacheBinFlag).ToList(); + + + if (!string.IsNullOrWhiteSpace(upMoveNo)) + { + list = list.Where(i => !upMoveNo.Equals(i.No) && (i.No != "" || i.No != "-1")).ToList(); + } + + list = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus == 4).ToList(); + if (list.Count <= 0) { selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging; return selectPackDto; @@ -45,7 +56,7 @@ public class BinInfoRepository : BaseRepository list = list.Where(i => i.Soc != null && i.Soc >= swapSoc).ToList(); - if (list.Count <= 0 && cacheBinBattery == null) + if (list.Count <= 0) { selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc; return selectPackDto; @@ -54,20 +65,15 @@ public class BinInfoRepository : BaseRepository list = list.Where(i => i.LastChargeFinishTime != null && new TimeSpan(DateTime.Now.Ticks - i.LastChargeFinishTime.ToDateTime().Ticks) .TotalMinutes > swapFinishChargeTime).ToList(); - if (list.Count <= 0 && cacheBinBattery == null) + if (list.Count <= 0) { selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOf3Minute; return selectPackDto; } - if (list.Count > 0) - { - selectPackDto.BinInfo = list[0]; - } - else - { - selectPackDto.BinInfo = cacheBinBattery; - } + + selectPackDto.BinInfo = list[0]; + selectPackDto.Info = InfoEnum.SelectBinStatusInfo.Success; selectPackDto.SuccessFlag = true; @@ -84,7 +90,7 @@ public class BinInfoRepository : BaseRepository public BinInfo? ChooseCacheBinBattery(int swapSoc) { return - QueryByClause(i => i.CacheBinFlag == 1 && i.CanSwapFlag==1 && i.Soc >= swapSoc && + QueryByClause(i => i.CacheBinFlag == 1 && i.CanSwapFlag == 1 && i.Soc >= swapSoc && i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock); } } diff --git a/Repository/Station/MoveBinRecordRepository.cs b/Repository/Station/MoveBinRecordRepository.cs new file mode 100644 index 0000000..88aa446 --- /dev/null +++ b/Repository/Station/MoveBinRecordRepository.cs @@ -0,0 +1,14 @@ +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using SqlSugar; + +namespace Repository.Station; + +[Scope("SingleInstance")] +public class MoveBinRecordRepository:BaseRepository +{ + + public MoveBinRecordRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) + { + } +} diff --git a/Service/Execute/Api/PlcApi.cs b/Service/Execute/Api/PlcApi.cs index 9312621..c43e527 100644 --- a/Service/Execute/Api/PlcApi.cs +++ b/Service/Execute/Api/PlcApi.cs @@ -123,12 +123,26 @@ public class PlcApi /// public static bool ReadTaskStatus(ushort taskNo) { + PlcMgr.ResetPlc(); Log.Info($"PlcApi ReadTaskStatus param= taskNo={taskNo}"); var readTaskStatus = PlcMgr.ReadTaskStatus(taskNo); Log.Info($"PlcApi ReadTaskStatus resp={readTaskStatus}"); return readTaskStatus; } + /// + /// 读取任务状态 + /// + /// + public static bool ReadTaskStatusReset() + { + PlcMgr.ResetPlc(); + Log.Info($"PlcApi ReadTaskStatus param= taskNo={0}"); + var readTaskStatus = PlcMgr.ReadTaskStatus(0); + Log.Info($"PlcApi ReadTaskStatus resp={readTaskStatus}"); + return readTaskStatus; + } + /// /// plc上使能 /// @@ -162,6 +176,7 @@ public class PlcApi /// 6未连接 public static int ReadPlcTaskStatus() { + PlcMgr.ResetPlc(); Log.Info($"PlcApi start ReadPlcTaskStatus "); var readPlcTaskStatus = PlcMgr.ReadPlcTaskStatus(); Log.Info($"PlcApi ReadPlcTaskStatus resp= {readPlcTaskStatus}"); diff --git a/Service/Execute/Mgr/CommonMgr.cs b/Service/Execute/Mgr/CommonMgr.cs index d5cbf12..938b535 100644 --- a/Service/Execute/Mgr/CommonMgr.cs +++ b/Service/Execute/Mgr/CommonMgr.cs @@ -6,9 +6,12 @@ using Entity.Dto; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; using Repository.Station; +using Service.Execute.Api; using Service.Execute.Model; using Service.Init; +using Service.Plc.Client; using Service.Station; +using SqlSugar; namespace Service.Execute.Utils; @@ -24,6 +27,8 @@ public class CommonMgr public SwapOrderReportCloudRepository _swapOrderReportCloudRepository { get; set; } + public MoveBinRecordRepository MoveBinRecordRepository { get; set; } + /// /// 新增小步状态 /// @@ -156,17 +161,43 @@ public class CommonMgr /// /// 取电池判断 + /// 不能选正在执行移仓的电池 /// /// public void UpBin(SwapOrderBatteryInfo orderBatteryInfo) { SelectPackDto selectPack = - _binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime); + _binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime, + queryMoveBinNo()[0]); orderBatteryInfo.UpBinInfo = selectPack.BinInfo; orderBatteryInfo.CanSwap = selectPack.Info; } + private List queryMoveBinNo() + { + string moveUp = ""; + string moveIn = ""; + + //当前有移仓任务 + if (PlcMgr.PlcClient.ReadTaskNo() == 2) + { + MoveBinRecord queryByClause = MoveBinRecordRepository.QueryByClause(i => i.Status == 0 || i.Status == 1, + i => i.CreatedTime, + OrderByType.Desc); + if (queryByClause != null) + { + moveUp = queryByClause.UpBinNo; + moveIn = queryByClause.InBinNo; + } + } + + return new List() + { + moveUp, moveIn + }; + } + /// /// 放电池判断:取出来的电池仓位能不能放 /// @@ -185,6 +216,17 @@ public class CommonMgr return; } + var value = queryMoveBinNo()[1]; + if (!string.IsNullOrWhiteSpace(value)) + { + list = list.Where(i => i.No != value).ToList(); + } + if (list.Count <= 0) + { + orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.LessOfEmptyBin; + return; + } + orderBatteryInfo.InBinInfo = list[0]; orderBatteryInfo.InBinInfo.BatteryNo = "-1"; orderBatteryInfo.InBinInfo.Soc = -1; @@ -194,7 +236,7 @@ public class CommonMgr if (carInfoBatteryInfos != null && carInfoBatteryInfos.Count > 0) { orderBatteryInfo.InBinInfo.BatteryNo = carInfoBatteryInfos[0].BatteryNo; - // orderBatteryInfo.InBinInfo.Soc = carInfoBatteryInfos[0].Soc; + // orderBatteryInfo.InBinInfo.Soc = carInfoBatteryInfos[0].Soc; orderBatteryInfo.InBinInfo.Soe = carInfoBatteryInfos[0].Soe; orderBatteryInfo.InBinInfo.Soh = carInfoBatteryInfos[0].Soh; } @@ -277,4 +319,4 @@ public class CommonMgr Vtm = Convert.ToSingle(machine.BoxCarInfoModel?.ElecMsg?.TotalMile), }); } -} \ No newline at end of file +} diff --git a/Service/Execute/Step/DoSwappingState.cs b/Service/Execute/Step/DoSwappingState.cs index a41c948..2a72253 100644 --- a/Service/Execute/Step/DoSwappingState.cs +++ b/Service/Execute/Step/DoSwappingState.cs @@ -11,6 +11,7 @@ using Service.Execute.StaticTools; using Service.Execute.SwapException; using Service.Execute.Utils; using Service.Init; +using Service.Plc.Client; using Service.Station; namespace Service.Execute.Step; @@ -100,6 +101,7 @@ public class DoSwappingState : IState { return SwappingStateMachine.ReturnWithInvokeErr(toInvokeStatus, ExceptionReason.None); } + //查询换电任务是否结束 return new StateResult() @@ -121,26 +123,36 @@ public class DoSwappingState : IState bool unLock = result.Result; if (unLock) { - //查询车辆锁止状态 - var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No, - machine.SwapOrderBatteryInfo.UpBinInfo.No); + //查询当前是否有任务执行 - //查詢當前任務狀態是否被更改 - var readPlcTaskStatus = PlcApi.ReadTaskStatus(1); - if (startSwapping && readPlcTaskStatus) + var readTaskNo = PlcMgr.PlcClient?.ReadTaskNo(); + if (readTaskNo == 0 || readTaskNo==1) { - machine.SwapOrder.SwapBeginTime = DateTime.Now; - _CommonMgr.UpdateSwapOrder(machine); - machine.SwapStatus = 0; - machine.StartSwappingFlag = true; - _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag, - machine); + PlcMgr.PlcClient?.ExChangeTaskNo(1); + //查询车辆锁止状态 + var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No, + machine.SwapOrderBatteryInfo.UpBinInfo.No); + + //查詢當前任務狀態是否被更改 + var readPlcTaskStatus = PlcApi.ReadTaskStatus(1); + if (startSwapping && readPlcTaskStatus) + { + + machine.SwapOrder.SwapBeginTime = DateTime.Now; + _CommonMgr.UpdateSwapOrder(machine); + machine.SwapStatus = 0; + machine.StartSwappingFlag = true; + _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag, + machine); + } + } + else + { + _log.Info("当前有任务在执行"); } } - }, () => - { - SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwap); - },false, () => { },10,InvokeStatus.None); + }, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwap); }, false, () => { }, 10, + InvokeStatus.None); } @@ -240,7 +252,6 @@ public class DoSwappingState : IState if (PlcApi.ReadPlcTaskStatus() == 1004) { - } else { @@ -252,7 +263,7 @@ public class DoSwappingState : IState _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.OutNewBatteryFlag, machine); } - }, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoNewBatteryCarryOut);}, false, () => { }, 10, + }, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoNewBatteryCarryOut); }, false, () => { }, 10, InvokeStatus.None); } @@ -265,7 +276,6 @@ public class DoSwappingState : IState // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed()); if (PlcApi.ReadPlcTaskStatus() == 1005) { - } else { @@ -277,11 +287,8 @@ public class DoSwappingState : IState _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag, machine); } - }, () => - { - SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack); - },false, () => { }, - 10,InvokeStatus.None); + }, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack); }, false, () => { }, + 10, InvokeStatus.None); } public InvokeStatus PackFinish(SwappingStateMachine machine) @@ -303,8 +310,8 @@ public class DoSwappingState : IState _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag, machine); } - }, () => { },false, () => { }, - 10,InvokeStatus.None); + }, () => { }, false, () => { }, + 10, InvokeStatus.None); } /// @@ -318,14 +325,18 @@ public class DoSwappingState : IState () => machine.ToSafePositionFlag, () => { // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPackFinish.GetLed()); - + if (PlcApi.ReadPlcTaskStatus() == 1007) { - SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoToSafePosition); - machine.ToSafePositionFlag = true; - machine.BusinessSwappingStateUpdateTime = DateTime.Now; + if (PlcApi.ReadTaskStatusReset()) + { + PlcMgr.PlcClient?.ResetTaskNo(); + SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoToSafePosition); + machine.ToSafePositionFlag = true; + machine.BusinessSwappingStateUpdateTime = DateTime.Now; - machine.SwapStatus = 1; + machine.SwapStatus = 1; + } } }, () => { }); } @@ -344,13 +355,12 @@ public class DoSwappingState : IState int count = 0; while (!machine.ChannelStatusOkFlag) { - if (machine.CancelFlag) { _log.Info($" CheckChannelStatus canceled"); - return StateResult.Cancel; + return StateResult.Cancel; } - + _log.Info("begin plc CheckChannelStatus"); Thread.Sleep(2000); var channelStatus = PlcApi.ChannelStatus(); @@ -375,7 +385,7 @@ public class DoSwappingState : IState // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrChannelStatus.GetLed()); SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrChannelStatus); //等待2分钟 - Thread.Sleep(3*60 *1000); + Thread.Sleep(3 * 60 * 1000); machine.VehiclesInPlace2Flag = false; machine.StartSwappingFlag = false; machine.PlcHoldFlag = false; @@ -448,8 +458,8 @@ public class DoSwappingState : IState succCount++; } } - - if (succCount==successCount) + + if (succCount == successCount) { machine.VehiclesInPlace2Flag = true; } @@ -461,4 +471,4 @@ public class DoSwappingState : IState }, false, () => { } , 20, InvokeStatus.None); } -} \ No newline at end of file +} diff --git a/Service/Execute/SwappingStateMachine.cs b/Service/Execute/SwappingStateMachine.cs index 317496b..4262583 100644 --- a/Service/Execute/SwappingStateMachine.cs +++ b/Service/Execute/SwappingStateMachine.cs @@ -12,6 +12,7 @@ using Service.Execute.Model.Tbox; using Service.Execute.StaticTools; using Service.Execute.Step; using Service.Execute.SwapException; +using Service.Plc.Client; namespace Service.Execute; @@ -249,6 +250,11 @@ public class SwappingStateMachine : IDisposable public void Reset() { Log.Info("reset data"); + if (PlcMgr.PlcClient?.ReadTaskNo() == 1) + { + PlcMgr.PlcClient?.ExChangeTaskNo(0); + } + ResetOrderAmtStatus(); if (RfidReadModel != null) { @@ -280,7 +286,7 @@ public class SwappingStateMachine : IDisposable Log.Info($"ManualSwapSuccFlag machine ok"); return true; } - + public bool ManualConfirmLockCar() { ManualConfirmCarLockFlag = true; @@ -288,7 +294,7 @@ public class SwappingStateMachine : IDisposable Log.Info($"ManualConfirmLockCar ok"); return true; } - + public bool ManualConfirmUnLockCar() { ManualConfirmCarUnlockFlag = true; @@ -298,7 +304,6 @@ public class SwappingStateMachine : IDisposable } - private void ResetData() { BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.Idle; @@ -417,7 +422,7 @@ public class SwappingStateMachine : IDisposable } } - //预约单 + //预约单 List amtOrderInfos = AmtOrderRepository.QueryListByClause(it => it.ExpireTime < DateTime.Now && it.Status == (byte)InfoEnum.AmtOrderStatus.Success).ToList(); @@ -454,4 +459,4 @@ public enum SwappingState Exception, Canceled, ManualSucc, -} \ No newline at end of file +} diff --git a/Service/MyTask/BatteryMoveTask.cs b/Service/MyTask/BatteryMoveTask.cs index 0171f24..ac38e09 100644 --- a/Service/MyTask/BatteryMoveTask.cs +++ b/Service/MyTask/BatteryMoveTask.cs @@ -48,7 +48,7 @@ public class BatteryMoveTask : ITask } List queryListByClause = - _binInfoRepository.QueryListByClause(i => i.ChargeStatus == 4 && i.CacheBinFlag == 0 && i.Soc>=StaticStationInfo.SwapSoc + _binInfoRepository.QueryListByClause(i => i.ChargeStatus == 4 && i.CacheBinFlag == 0 && i.Soc>=StaticStationInfo.SwapSoc && i.AmtLock == 0 && i.Status == 1, "battery_enter_seq asc"); @@ -57,6 +57,11 @@ public class BatteryMoveTask : ITask return; } + //不能进行移仓 + if (PlcMgr.PlcClient?.ReadTaskNo() != 0) + { + return; + } var binInfo = queryListByClause[0]; Result success = @@ -70,6 +75,7 @@ public class BatteryMoveTask : ITask } catch (Exception e) { + PlcMgr.PlcClient?.ExChangeTaskNo(0); Log.Error($" SwapOrderReportCloudTask err e={e}"); } } @@ -88,4 +94,4 @@ public class BatteryMoveTask : ITask { _stop = false; } -} \ No newline at end of file +} diff --git a/Service/Plc/Client/PlcClient.cs b/Service/Plc/Client/PlcClient.cs index 6b7f5d7..9be9f5c 100644 --- a/Service/Plc/Client/PlcClient.cs +++ b/Service/Plc/Client/PlcClient.cs @@ -17,11 +17,33 @@ public class PlcClient : ModbusTcpMaster { private static readonly ILog Log = LogManager.GetLogger(typeof(PlcClient)); + + private long TaskNo=0; public BinInfoRepository BinInfoRepository { get; set; } public EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; } public EquipAlarmRecordRepository EquipAlarmRecordRepository { get; set; } public EquipAlarmProcessRecordRepository EquipAlarmProcessRecordRepository { get; set; } + + //修改当前任务 + public void ExChangeTaskNo(long taskNo) + { + Interlocked.Exchange(ref TaskNo, taskNo); + } + + //重置当前任务 + public void ResetTaskNo() + { + Interlocked.Exchange(ref TaskNo, 0); + } + + //读取当前任务 + public long ReadTaskNo() + { + + return Interlocked.Read( ref TaskNo); + } + public PlcClient() { ReadAction = BatchRead; @@ -35,6 +57,7 @@ public class PlcClient : ModbusTcpMaster private void BatchRead(ModbusTcpMaster master) { + PlcMgr.SendHear(); var bytes01 = master.BatchReadHolderRegister(1, 115); if (bytes01 != null) @@ -139,14 +162,14 @@ public class PlcClient : ModbusTcpMaster if (lstAlarm.Count > 0) { #region 有报警比较两边差异,新出现的报警就添加,消失的报警就处理并记录 - + var lstEquipAlarmRecord=EquipAlarmRecordRepository.Query(); var sqllstAlarm=lstEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList(); - // 找出实时报警中存在但数据库中不存在的元素 - List uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList(); - - // 找出数据库中存在但实时报警中不存在的元素 + // 找出实时报警中存在但数据库中不存在的元素 + List uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList(); + + // 找出数据库中存在但实时报警中不存在的元素 List uniqueToList2 = sqllstAlarm.Except(lstAlarm).ToList(); if (uniqueToList1.Count > 0) @@ -165,7 +188,7 @@ public class PlcClient : ModbusTcpMaster ErrorMsg = alarmDefine.ErrorMsg, ProcessMethod = alarmDefine.ProcessMethod, StartTime= DateTime.Now - }; + }; EquipAlarmRecordRepository.Insert(record); } } @@ -173,9 +196,9 @@ public class PlcClient : ModbusTcpMaster if (uniqueToList2.Count > 0) {//这些是要清除实时报警,并且处理记录的。 - // 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象 - List filteredObjectList = lstEquipAlarmRecord - .Where(obj => uniqueToList2.Contains(obj.ErrorCode)) + // 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象 + List filteredObjectList = lstEquipAlarmRecord + .Where(obj => uniqueToList2.Contains(obj.ErrorCode)) .ToList(); foreach (var VARIABLE in filteredObjectList) { @@ -193,7 +216,7 @@ public class PlcClient : ModbusTcpMaster } EquipAlarmRecordRepository.Delete(filteredObjectList); } - + #endregion } else @@ -219,10 +242,10 @@ public class PlcClient : ModbusTcpMaster } } EquipAlarmRecordRepository.Delete(i=>i.Id>0); - + #endregion - - + + } } @@ -245,7 +268,7 @@ public class PlcClient : ModbusTcpMaster it => it.No == binNo); } - + private void UpdateBinInfoCache(int exists, string binNo) { if (exists == 0) @@ -253,7 +276,7 @@ public class PlcClient : ModbusTcpMaster it => new BinInfo(){ Exists = 0, - + }, it => it.No == binNo); else diff --git a/Service/Plc/Client/PlcMgr.cs b/Service/Plc/Client/PlcMgr.cs index abd8919..e9ce053 100644 --- a/Service/Plc/Client/PlcMgr.cs +++ b/Service/Plc/Client/PlcMgr.cs @@ -18,6 +18,8 @@ public class PlcMgr public static readonly PlcFault PlcFaultData = new PlcFault(); + public + /// /// 数据有效时间。单位秒 /// @@ -305,7 +307,7 @@ public class PlcMgr bool writeCharge6 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus06); bool writeCharge7 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus07); bool writeCharge8 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus08); - + return write1 && write2 && write3 && write4 && write5 && write6; } @@ -396,4 +398,4 @@ public class PlcMgr return bResult; } -} \ No newline at end of file +} diff --git a/Service/Plc/Msg/PlcToHost.cs b/Service/Plc/Msg/PlcToHost.cs index e183a93..01e616d 100644 --- a/Service/Plc/Msg/PlcToHost.cs +++ b/Service/Plc/Msg/PlcToHost.cs @@ -3,7 +3,7 @@ namespace Service.Plc.Msg { /// - /// + /// /// public class PlcToHost { @@ -43,14 +43,14 @@ namespace Service.Plc.Msg /// public ModbusProperty RemoteLocalControlState { get; set; } = new(40207); /// - /// 灯光状态 + /// 灯光状态 /// 0:无状态 /// 1000:已全部打开 /// 1010:已全部关闭 /// public ModbusProperty LightStatus { get; set; } = new(40208); /// - /// 排风扇状态 + /// 排风扇状态 /// 0:无状态 /// 1000:已全部打开 /// 1010:已全部关闭 @@ -58,7 +58,7 @@ namespace Service.Plc.Msg public ModbusProperty ExhaustFanStatus { get; set; } = new(40209); /// /// 站内积水状态 - /// BIT0:积水预警 + /// BIT0:积水预警 /// BIT1:积水报警 /// public ModbusProperty WaterStatusStation { get; set; } = new(40210); @@ -172,7 +172,7 @@ namespace Service.Plc.Msg /// 1020:红灯 /// 1030:红灯闪烁 /// 1040:黄灯 - /// 1050:黄灯闪烁 + /// 1050:黄灯闪烁移舱任务 /// 1100:所有灯亮 /// public ModbusProperty LightOut { get; set; } = new(40406); diff --git a/Service/Station/MonitorService.cs b/Service/Station/MonitorService.cs index c541bca..3799e72 100644 --- a/Service/Station/MonitorService.cs +++ b/Service/Station/MonitorService.cs @@ -27,6 +27,8 @@ public class MonitorService public ChargeOrderRepository ChargeOrderRepository { get; set; } public PlcTaskMgr PlcTaskMgr { get; set; } + public MoveBinRecordRepository MoveBinRecordRepository { get; set; } + public Result GetSwapMonitorData() { var configBinInfo = @@ -145,7 +147,7 @@ public class MonitorService /// /// /// - public Result BatteryRelocation(ushort removeBinNo, ushort putBinNo) + public Result BatteryRelocation(ushort removeBinNo, ushort putBinNo,int type=0) { //校验:出仓位 BinInfo? removeBin = BinInfoRepository.QueryByClause(i => @@ -165,13 +167,22 @@ public class MonitorService return Result.Fail("入仓位状态有误"); } + if (PlcMgr.PlcClient?.ReadTaskNo() != 0) + { + Log.Info("当前存在其他任务"); + return Result.Fail("当前存在其他任务"); + } + PlcMgr.PlcClient?.ExChangeTaskNo(2); var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2); if (!result) { + PlcMgr.PlcClient?.ExChangeTaskNo(0); return Result.Fail(); } + + int count = 3; while (count > 0) { @@ -187,22 +198,40 @@ public class MonitorService if (!result) { + PlcMgr.PlcClient?.ExChangeTaskNo(0); Log.Error("BatteryRelocation PlcMgr.ReadTaskStatus(2) =false"); return Result.Fail(); } + MoveBinRecord moveBinRecord = new MoveBinRecord() + { + UpBinNo = removeBinNo.ToString(), + UpBatteryNo = removeBin.BatteryNo, + UpBatterySoc = removeBin.Soc.ToString(), + InBatteryNo = putBin.BatteryNo, + InBatterySoc = putBin.Soc.ToString(), + InBinNo = putBinNo.ToString(), + Status = 0, + Type = type + }; + MoveBinRecordRepository.Insert(moveBinRecord); + result = PlcMgr.HoldOn(); if (!result) - { + { PlcMgr.PlcClient?.ExChangeTaskNo(0); Log.Error("BatteryRelocation PlcMgr.HoldOn() =false"); return Result.Fail(); } - Log.Info($"battery move task Manual removeBinNo={removeBinNo}, putBinNo={putBinNo} "); - + Log.Info($"battery move task Manual removeBinNo={removeBinNo}, putBinNo={putBinNo} type={type} "); + moveBinRecord.Status = 1; + MoveBinRecordRepository.Update(moveBinRecord); var queryPlcTask = PlcTaskMgr.QueryPlcTask(2, 1200, 1201); if (!queryPlcTask) { + PlcMgr.PlcClient?.ExChangeTaskNo(0); + moveBinRecord.Status = 3; + MoveBinRecordRepository.Update(moveBinRecord); return Result.Fail(); } @@ -231,8 +260,9 @@ public class MonitorService removeBin.BatteryEnterSeq = 0; BinInfoRepository.Update(removeBin); - - + moveBinRecord.Status = 2; + MoveBinRecordRepository.Update(moveBinRecord); + PlcMgr.PlcClient?.ExChangeTaskNo(0); return Result.Success(); } @@ -246,4 +276,4 @@ public class MonitorService return Result>.Success(mapperBinInfo.Map>(queryListByClause)); } -} \ No newline at end of file +} diff --git a/WebStarter/Controllers/ChargeMonitorController.cs b/WebStarter/Controllers/ChargeMonitorController.cs index 8e66d29..18fbe83 100644 --- a/WebStarter/Controllers/ChargeMonitorController.cs +++ b/WebStarter/Controllers/ChargeMonitorController.cs @@ -28,7 +28,7 @@ public class ChargeMonitorController _binInfoService = binInfoService; _monitorService = monitorService; } - + /// /// 仓位预约 /// @@ -49,7 +49,7 @@ public class ChargeMonitorController else return Result.Fail(result); } - + /// /// 修改仓位电池编码 /// @@ -76,8 +76,8 @@ public class ChargeMonitorController else return Result.Fail(result); } - - + + /// /// 充电仓查询:条件:仓位编号 仓位名称 /// @@ -119,7 +119,7 @@ public class ChargeMonitorController [HttpGet("BatteryRelocation")] public async Task> BatteryRelocation(ushort removeBinNo, ushort putBinNo) { - return _monitorService.BatteryRelocation(removeBinNo, putBinNo); + return _monitorService.BatteryRelocation(removeBinNo, putBinNo,1); } /// @@ -130,4 +130,4 @@ public class ChargeMonitorController { return _monitorService.GetChargeBinOption(); } -} \ No newline at end of file +}