diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index 8a857c7db..fd63b0882 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -170,6 +170,16 @@ internal static class Program Watchdog.NotifyAlive(); var record = ReadStatus(); + + // If control Special Error return true, we must stop the system.(break;) + var specialErrorOccured = record.ControlSpecialError(); + + if (specialErrorOccured.Item1) + { + //stop the system + //return + specialErrorOccured.Item2.WriteLine(); + } record.ControlConstants(); record.ControlSystemState(); @@ -202,6 +212,36 @@ internal static class Program // ReSharper disable once FunctionNeverReturns } + private static (Boolean, String) ControlSpecialError (this StatusRecord r) // to find a better name + { + // Those errors must not occurs. Stop the system in case this is happen. + var isSpecialErrorOccured = false; + var errorMessage = "No Error"; + + // 1. relay0 is open and K2 Close. + if (r.Relays is { K2ConnectIslandBusToGridBus: false, K2IslandBusIsConnectedToGridBus: true } ) + { + isSpecialErrorOccured = true; + errorMessage = " Contradiction: R0 is opening the K2 but the K2 is still close "; + } + + // 2. If K1 is open, K2 must be open . + if (r.Relays is { K1GridBusIsConnectedToGrid: false, K2IslandBusIsConnectedToGridBus: true } ) + { + isSpecialErrorOccured = true; + errorMessage = " Contradiction: K1 is open but the K2 is still close "; + } + + // 3. If FI error is occured, K2 must be open. + if (r.Relays is { FiError: true, K2IslandBusIsConnectedToGridBus: true } ) + { + isSpecialErrorOccured = true; + errorMessage = " Contradiction: Fi error occured but the K2 is still close "; + } + + + return (isSpecialErrorOccured, errorMessage); + } private static void ControlConstants(this StatusRecord r) { @@ -228,7 +268,7 @@ internal static class Program dcDevices.ForEach(d => d.Control.VoltageLimits.MaxBatteryVoltage = configFile.MaxChargeBatteryVoltage); dcDevices.ForEach(d => d.Control.VoltageLimits.MinBatteryVoltage = configFile.MinDischargeBatteryVoltage); dcDevices.ForEach(d => d.Control.ControlMode = DcControlMode.VoltageDroop); - + r.DcDc.ResetAlarms(); r.AcDc.ResetAlarms(); }