diff --git a/OrpaonEMS.App/App.xaml.cs b/OrpaonEMS.App/App.xaml.cs index 5e812fa..4855e6f 100644 --- a/OrpaonEMS.App/App.xaml.cs +++ b/OrpaonEMS.App/App.xaml.cs @@ -184,6 +184,10 @@ namespace OrpaonEMS.App protected override void OnExit(ExitEventArgs e) { + ContainerLocator.Container.Resolve().ThreadEnable = false; + ContainerLocator.Container.Resolve().WebSocketThreadEnable = false; + ContainerLocator.Container.Resolve().ThreadEnable = false; + energyStorageService.EnergyStorageStateMachine.Fire(Core.Enums.EnergyStorageStateTrig.HandTrig); base.OnExit(e); } diff --git a/OrpaonEMS.App/Services/EMSService.cs b/OrpaonEMS.App/Services/EMSService.cs index 90dbaa7..7ad3056 100644 --- a/OrpaonEMS.App/Services/EMSService.cs +++ b/OrpaonEMS.App/Services/EMSService.cs @@ -185,7 +185,7 @@ namespace OrpaonEMS.App.Services ListDistClient.Find(a => a.ServerCmd.Station == 0)!.EMSSocketServerConState.ServerSendState = true; ListDistClient.Find(a => a.ServerCmd.Station == 1)!.EMSSocketServerConState.ServerSendState = true; - + //发布消息 wsServer.PublishAllClientPayload(JsonSerializer.Serialize>(ListDistClient.Select(a => a.ServerCmd).ToList())); } @@ -1235,19 +1235,19 @@ namespace OrpaonEMS.App.Services var Data = Encoding.UTF8.GetString(message.Payload); //反序列化数据 ClientInfo data = JsonSerializer.Deserialize(Data); - if (data.Station == 1) - { - var dd = 1; - } + //if (data.Station == 1) + //{ + // var dd = 1; + //} foreach (var item in ListDistClient) { if (item.ClientInfo!.Station == data.Station) { - if (data.Station == 1) - { - var dd = 1; - } + //if (data.Station == 1) + //{ + // var dd = 1; + //} item.ClientInfo = data; item.EMSSocketServerConState.ServerRecvState = true; break; @@ -1294,7 +1294,7 @@ namespace OrpaonEMS.App.Services /// private bool WebSocketServerState { get; set; } = false; - private bool ThreadEnable = true; + public bool ThreadEnable = true; #endregion diff --git a/OrpaonEMS.App/Services/EnergyStorageService.cs b/OrpaonEMS.App/Services/EnergyStorageService.cs index 3252e0d..4905d96 100644 --- a/OrpaonEMS.App/Services/EnergyStorageService.cs +++ b/OrpaonEMS.App/Services/EnergyStorageService.cs @@ -1363,7 +1363,7 @@ namespace OrpaonEMS.App.Services /// /// 线程使能 /// - private bool WebSocketThreadEnable { get; set; } = true; + public bool WebSocketThreadEnable { get; set; } = true; /// /// 当前的客户端状态指令内容 diff --git a/OrpaonEMS.App/Services/MqttDataClientService.cs b/OrpaonEMS.App/Services/MqttDataClientService.cs index 63f7f76..dff6dbe 100644 --- a/OrpaonEMS.App/Services/MqttDataClientService.cs +++ b/OrpaonEMS.App/Services/MqttDataClientService.cs @@ -32,9 +32,9 @@ namespace OrpaonEMS.App.Services InPowerPCSDataService = inPowerPCSDataService; if (ConfigDataService.IsMaster) { - MqttClientInit(); + //MqttClientInit(); - CycleSendStart(); + //CycleSendStart(); } } diff --git a/OrpaonEMS.App/Services/YuePuRunModelService.cs b/OrpaonEMS.App/Services/YuePuRunModelService.cs index 6679646..a3bdedb 100644 --- a/OrpaonEMS.App/Services/YuePuRunModelService.cs +++ b/OrpaonEMS.App/Services/YuePuRunModelService.cs @@ -26,7 +26,7 @@ namespace OrpaonEMS.App.Services { /////// /////怎么认定为晚上,光伏发电功率低于一个阈值时可认为是晚上 - public YuePuRunModelService(ILogService logService, ConfigDataService configDataService, + public YuePuRunModelService(ILogService logService, ConfigDataService configDataService, IEventAggregator eventAggregator) { ConfigDataService = configDataService; @@ -140,7 +140,7 @@ namespace OrpaonEMS.App.Services } - + } /// @@ -514,7 +514,6 @@ namespace OrpaonEMS.App.Services { try { - Thread.Sleep(1000); if (WaitTokenSource.IsCancellationRequested) { break; @@ -532,6 +531,7 @@ namespace OrpaonEMS.App.Services SlaveClient.ServerCmd.CoolOnOffCmd = false; MasterClient.ServerCmd.CoolOnOffCmd = false; + Thread.Sleep(30000); //WaitEnvActionResult @@ -695,48 +695,47 @@ namespace OrpaonEMS.App.Services // OpenSolar(); //} - //if (!IsSpecialWeekDay()) - //{ - - //展示用 - ManageRealPw = EsEleMeter4.AvePw - EsEleMeter1.AvePw; - TaxRealPw = SolarEleMeter5.AvePw - SolarEleMeter3.AvePw;//光伏和市电供应给税务大楼的负载 - - //循环执行方法 - //从储能箱充满为止 - if (SlaveClient.ClientInfo!.SOC < 90) + if (!IsInWeekendTime()) { - //主储能箱充电 - SlaveClient.ServerCmd.CmdType = "Charg"; - SlaveClient.ServerCmd.CmdPw = SlaveClient.ClientInfo!.MaxDisChargPw * ConfigDataService.energyStorageRunConfig.MaxBatDisChargRatio; + //展示用 + ManageRealPw = EsEleMeter4.AvePw - EsEleMeter1.AvePw; + TaxRealPw = SolarEleMeter5.AvePw - SolarEleMeter3.AvePw;//光伏和市电供应给税务大楼的负载 + + //循环执行方法 + //从储能箱充满为止 + if (SlaveClient.ClientInfo!.SOC < 90) + { + //主储能箱充电 + SlaveClient.ServerCmd.CmdType = "Charg"; + SlaveClient.ServerCmd.CmdPw = SlaveClient.ClientInfo!.MaxDisChargPw * ConfigDataService.energyStorageRunConfig.MaxBatDisChargRatio; + + } + else + { + //从储能箱充电 + SlaveClient.ServerCmd.CmdType = "Charg"; + SlaveClient.ServerCmd.CmdPw = 0; + } + + //主储能箱不运行 + MasterClient.ServerCmd.CmdType = "Charg"; + MasterClient.ServerCmd.CmdPw = 0; + } else { - //从储能箱充电 + //周五或者周六 + //主从都不充电 + MasterClient.ServerCmd.CmdType = "Charg"; + MasterClient.ServerCmd.CmdPw = 0; + //MasterControlMsg = "【主储能】周五周六晚上不充电,【主储能】不动作"; + SlaveClient.ServerCmd.CmdType = "Charg"; SlaveClient.ServerCmd.CmdPw = 0; + //SlaveControlMsg = "【从储能】周五周六晚上不充电,【从储能】不动作"; } - //主储能箱不运行 - MasterClient.ServerCmd.CmdType = "Charg"; - MasterClient.ServerCmd.CmdPw = 0; - - - //} - //else - //{ - // //周五或者周六 - // //主从都不充电 - // MasterClient.ServerCmd.CmdType = "Charg"; - // MasterClient.ServerCmd.CmdPw = 0; - // MasterControlMsg = "【主储能】周五周六晚上不充电,【主储能】不动作"; - - // SlaveClient.ServerCmd.CmdType = "Charg"; - // SlaveClient.ServerCmd.CmdPw = 0; - // SlaveControlMsg = "【从储能】周五周六晚上不充电,【从储能】不动作"; - //} - } catch (Exception ex) @@ -805,48 +804,46 @@ namespace OrpaonEMS.App.Services // OpenSolar(); //} - //if (!IsSpecialWeekDay()) - //{ - - //展示用 - ManageRealPw = EsEleMeter4.AvePw - EsEleMeter1.AvePw; - TaxRealPw = SolarEleMeter5.AvePw - SolarEleMeter3.AvePw;//光伏和市电供应给税务大楼的负载 - - //循环执行方法 - //主储能箱充满为止 - if (MasterClient.ClientInfo!.SOC < ConfigDataService.energyStorageRunConfig.BMSSocUpSignLimitValue) + if (!IsInWeekendTime()) { - //主储能箱充电 - MasterClient.ServerCmd.CmdType = "Charg"; - MasterClient.ServerCmd.CmdPw = MasterClient.ClientInfo!.MaxDisChargPw * ConfigDataService.energyStorageRunConfig.MaxBatDisChargRatio; + //展示用 + ManageRealPw = EsEleMeter4.AvePw - EsEleMeter1.AvePw; + TaxRealPw = SolarEleMeter5.AvePw - SolarEleMeter3.AvePw;//光伏和市电供应给税务大楼的负载 + + //循环执行方法 + //主储能箱充满为止 + if (MasterClient.ClientInfo!.SOC < ConfigDataService.energyStorageRunConfig.BMSSocUpSignLimitValue) + { + //主储能箱充电 + MasterClient.ServerCmd.CmdType = "Charg"; + MasterClient.ServerCmd.CmdPw = MasterClient.ClientInfo!.MaxDisChargPw * ConfigDataService.energyStorageRunConfig.MaxBatDisChargRatio; + + } + else + { + //主储能箱充电 + MasterClient.ServerCmd.CmdType = "Charg"; + MasterClient.ServerCmd.CmdPw = 0; + } + + //从储能箱不运行 + SlaveClient.ServerCmd.CmdType = "Charg"; + SlaveClient.ServerCmd.CmdPw = 0; } else { - //主储能箱充电 + //周五或者周六 + //主从都不充电 MasterClient.ServerCmd.CmdType = "Charg"; MasterClient.ServerCmd.CmdPw = 0; + //MasterControlMsg = "【主储能】周五周六晚上不充电,【主储能】不动作"; + + SlaveClient.ServerCmd.CmdType = "Charg"; + SlaveClient.ServerCmd.CmdPw = 0; + //SlaveControlMsg = "【从储能】周五周六晚上不充电,【从储能】不动作"; } - //从储能箱不运行 - SlaveClient.ServerCmd.CmdType = "Charg"; - SlaveClient.ServerCmd.CmdPw = 0; - - - //} - //else - //{ - // //周五或者周六 - // //主从都不充电 - // MasterClient.ServerCmd.CmdType = "Charg"; - // MasterClient.ServerCmd.CmdPw = 0; - // MasterControlMsg = "【主储能】周五周六晚上不充电,【主储能】不动作"; - - // SlaveClient.ServerCmd.CmdType = "Charg"; - // SlaveClient.ServerCmd.CmdPw = 0; - // SlaveControlMsg = "【从储能】周五周六晚上不充电,【从储能】不动作"; - //} - } catch (Exception ex) @@ -3275,13 +3272,43 @@ namespace OrpaonEMS.App.Services return (DateTime.Now.DayOfWeek == DayOfWeek.Friday && IsPm()) || (DateTime.Now.DayOfWeek == DayOfWeek.Saturday && IsPm()); } + /// + /// 是周五还是周六 + /// 在晚上判断是周五晚上还是周六晚上,腾出储能给光伏充电用 + /// + /// + public bool IsInWeekendTime() + { + DateTime now = DateTime.Now; + DayOfWeek currentDay = now.DayOfWeek; + TimeSpan currentTime = now.TimeOfDay; + + // 周五情况:时间 >= 23:00 + if (currentDay == DayOfWeek.Friday && currentTime.Hours >= 23) + { + return true; + } + // 周六情况:全天有效 + else if (currentDay == DayOfWeek.Saturday) + { + return true; + } + // 周日情况:时间 < 07:00 + else if (currentDay == DayOfWeek.Sunday && currentTime.Hours < 7) + { + return true; + } + + return false; + } + /// /// 是否时下午 /// /// private bool IsPm() { - return DateTime.Now.Hour > 18; + return DateTime.Now.Hour >= 23; } ///