Skip to content

Commit

Permalink
The PLC holds the program data
Browse files Browse the repository at this point in the history
  • Loading branch information
Kersoph committed Jan 4, 2022
1 parent cd71cd7 commit a130c0a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 14 additions & 16 deletions data/diagram_models/sfc/processing_unit/SfcProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -27,28 +25,28 @@ public SfcProgram(ProgrammableLogicController plc, SfcProgramData data)
/// </summary>
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);
}
Expand All @@ -59,16 +57,16 @@ public void UpdateProcess(int deltaTimeMs)
/// </summary>
public void UpdateStepStatus(List<SfcStep> toActive, List<SfcStep> toInactive)
{
Data.SoonActiveSteps.UnionWith(toActive);
Data.SoonInactiveSteps.UnionWith(toInactive);
Plc.SfcProgramData.SoonActiveSteps.UnionWith(toActive);
Plc.SfcProgramData.SoonInactiveSteps.UnionWith(toInactive);
}

/// <summary>
/// Returns true if the simulation can be executed
/// </summary>
public bool IsProgramLogicValid()
{
return Data.AreStepsValid();
return Plc.SfcProgramData.AreStepsValid();
}
#endregion
}
Expand Down
2 changes: 1 addition & 1 deletion data/diagram_models/sfc/processing_unit/SfcTransition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a130c0a

Please sign in to comment.