From a130c0a832820d4d0921df1698b9b2323b9d94f7 Mon Sep 17 00:00:00 2001 From: Marco Burri <26461040+Kersoph@users.noreply.github.com> Date: Tue, 4 Jan 2022 17:40:33 +0100 Subject: [PATCH] The PLC holds the program data --- .../ProgrammableLogicController.cs | 2 +- .../sfc/processing_unit/SfcProgram.cs | 30 +++++++++---------- .../sfc/processing_unit/SfcTransition.cs | 2 +- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/data/diagram_models/sfc/processing_unit/ProgrammableLogicController.cs b/data/diagram_models/sfc/processing_unit/ProgrammableLogicController.cs index 03d92f2..6924176 100644 --- a/data/diagram_models/sfc/processing_unit/ProgrammableLogicController.cs +++ b/data/diagram_models/sfc/processing_unit/ProgrammableLogicController.cs @@ -43,7 +43,7 @@ public ProgrammableLogicController(SimulationPage simulationPage, SfcEntity sfcE _inputRegisters = new ResettingStateTable(_simulationPage.SimulationOutput); _outputRegisters = new ResettingStateTable(_simulationPage.SimulationInput); SfcProgramData = new SfcProgramData(sfcEntity); - SfcProgram = new SfcProgram(this, SfcProgramData); + SfcProgram = new SfcProgram(this); } #endregion diff --git a/data/diagram_models/sfc/processing_unit/SfcProgram.cs b/data/diagram_models/sfc/processing_unit/SfcProgram.cs index f9ff1fb..fe78076 100644 --- a/data/diagram_models/sfc/processing_unit/SfcProgram.cs +++ b/data/diagram_models/sfc/processing_unit/SfcProgram.cs @@ -8,15 +8,13 @@ public class SfcProgram { #region ==================== Fields / Properties ==================== public ProgrammableLogicController Plc { get; private set; } - public SfcProgramData Data { get; private set; } #endregion #region ==================== Constructor ==================== - public SfcProgram(ProgrammableLogicController plc, SfcProgramData data) + public SfcProgram(ProgrammableLogicController plc) { Plc = plc; - Data = data; } #endregion @@ -27,28 +25,28 @@ public SfcProgram(ProgrammableLogicController plc, SfcProgramData data) /// public void UpdateProcess(int deltaTimeMs) { - Data.InactiveSteps.UnionWith(Data.SoonInactiveSteps); - Data.ActiveSteps.ExceptWith(Data.SoonInactiveSteps); - Data.SoonInactiveSteps.Clear(); - foreach (var sfcStep in Data.SoonActiveSteps) + Plc.SfcProgramData.InactiveSteps.UnionWith(Plc.SfcProgramData.SoonInactiveSteps); + Plc.SfcProgramData.ActiveSteps.ExceptWith(Plc.SfcProgramData.SoonInactiveSteps); + Plc.SfcProgramData.SoonInactiveSteps.Clear(); + foreach (var sfcStep in Plc.SfcProgramData.SoonActiveSteps) { sfcStep.ExecuteActions(this, ActionQualifier.PPlus, deltaTimeMs); } - Data.ActiveSteps.UnionWith(Data.SoonActiveSteps); - Data.InactiveSteps.ExceptWith(Data.SoonActiveSteps); - Data.SoonActiveSteps.Clear(); + Plc.SfcProgramData.ActiveSteps.UnionWith(Plc.SfcProgramData.SoonActiveSteps); + Plc.SfcProgramData.InactiveSteps.ExceptWith(Plc.SfcProgramData.SoonActiveSteps); + Plc.SfcProgramData.SoonActiveSteps.Clear(); - foreach (var sfcStep in Data.ActiveSteps) + foreach (var sfcStep in Plc.SfcProgramData.ActiveSteps) { sfcStep.ExecuteActions(this, ActionQualifier.N, deltaTimeMs); } - foreach (var sfcStep in Data.ActiveSteps) + foreach (var sfcStep in Plc.SfcProgramData.ActiveSteps) { sfcStep.CalculateTransition(this); } - foreach (var sfcStep in Data.SoonInactiveSteps) + foreach (var sfcStep in Plc.SfcProgramData.SoonInactiveSteps) { sfcStep.ExecuteActions(this, ActionQualifier.PMinus, deltaTimeMs); } @@ -59,8 +57,8 @@ public void UpdateProcess(int deltaTimeMs) /// public void UpdateStepStatus(List toActive, List toInactive) { - Data.SoonActiveSteps.UnionWith(toActive); - Data.SoonInactiveSteps.UnionWith(toInactive); + Plc.SfcProgramData.SoonActiveSteps.UnionWith(toActive); + Plc.SfcProgramData.SoonInactiveSteps.UnionWith(toInactive); } /// @@ -68,7 +66,7 @@ public void UpdateStepStatus(List toActive, List toInactive) /// public bool IsProgramLogicValid() { - return Data.AreStepsValid(); + return Plc.SfcProgramData.AreStepsValid(); } #endregion } diff --git a/data/diagram_models/sfc/processing_unit/SfcTransition.cs b/data/diagram_models/sfc/processing_unit/SfcTransition.cs index 2093f43..e729537 100644 --- a/data/diagram_models/sfc/processing_unit/SfcTransition.cs +++ b/data/diagram_models/sfc/processing_unit/SfcTransition.cs @@ -51,7 +51,7 @@ public bool CalculateTransition(SfcProgram program) // All dependent steps must be active foreach (SfcStep step in DependingSteps) { - if (!program.Data.IsStepActive(step)) return false; + if (!program.Plc.SfcProgramData.IsStepActive(step)) return false; } return Transition.Result(program.Plc); }