Skip to content

Commit

Permalink
add error handling to clsRelays
Browse files Browse the repository at this point in the history
  • Loading branch information
SK21 committed Jan 10, 2024
1 parent 695fcf7 commit 4b50edc
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 108 deletions.
230 changes: 122 additions & 108 deletions RateAppSource/RateController/Classes/clsRelays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,45 @@ public int PowerRelays(int ModuleID)

public void Renumber(int StartRelay, int StartModule, int StartSection)
{
int CurrentSection = StartSection;
int FirstRelay;
for (int j = StartModule; j < 8; j++)
try
{
if (j == StartModule)
int CurrentSection = StartSection;
int FirstRelay;
for (int j = StartModule; j < 8; j++)
{
FirstRelay = StartRelay;
}
else
{
FirstRelay = 0;
}
for (int i = FirstRelay; i < 16; i++)
{
clsRelay Rly = Item(i, j);
int tmp = Rly.SectionID;
//if (Rly.Type == RelayTypes.None && CurrentSection < mf.MaxSections) Rly.Type = RelayTypes.Section;
if (Rly.Type == RelayTypes.Section || Rly.Type == RelayTypes.Invert_Section
|| ((Rly.Type == RelayTypes.TramRight || Rly.Type == RelayTypes.TramLeft) && tmp > 0))
if (j == StartModule)
{
if (CurrentSection < mf.MaxSections)
{
Rly.SectionID = CurrentSection;
CurrentSection++;
}
else
FirstRelay = StartRelay;
}
else
{
FirstRelay = 0;
}
for (int i = FirstRelay; i < 16; i++)
{
clsRelay Rly = Item(i, j);
int tmp = Rly.SectionID;
//if (Rly.Type == RelayTypes.None && CurrentSection < mf.MaxSections) Rly.Type = RelayTypes.Section;
if (Rly.Type == RelayTypes.Section || Rly.Type == RelayTypes.Invert_Section
|| ((Rly.Type == RelayTypes.TramRight || Rly.Type == RelayTypes.TramLeft) && tmp > 0))
{
Rly.Type = RelayTypes.None;
if (CurrentSection < mf.MaxSections)
{
Rly.SectionID = CurrentSection;
CurrentSection++;
}
else
{
Rly.Type = RelayTypes.None;
}
}
}
}
}
catch (Exception ex)
{
mf.Tls.WriteErrorLog("clsRelays/Renumber: " + ex.Message);
}
}

public void Reset()
Expand Down Expand Up @@ -128,108 +135,115 @@ public void Save(int RelayID = 0, int ModuleID = 0)

public int SetRelays(int ModuleID)
{
// based on sections status and relay type set relays
// return int value for relayLo, relayHi
int Result = 0;
try
{
// based on sections status and relay type set relays
// return int value for relayLo, relayHi

bool SectionsOn = false; // whether at least on section is on
bool MasterOn = false; // whether at least one master relay is on
bool MasterFound = false;
bool SectionsOn = false; // whether at least on section is on
bool MasterOn = false; // whether at least one master relay is on
bool MasterFound = false;

// check if at least one section on
for (int i = 0; i < mf.MaxSections; i++)
{
if (mf.Sections.Item(i).IsON)
// check if at least one section on
for (int i = 0; i < mf.MaxSections; i++)
{
SectionsOn = true;
break;
if (mf.Sections.Item(i).IsON)
{
SectionsOn = true;
break;
}
}
}

// set master relay
for (int i = 0; i < cRelays.Count; i++)
{
clsRelay Rly = cRelays[i];

if (Rly.Type == RelayTypes.Master)
// set master relay
for (int i = 0; i < cRelays.Count; i++)
{
Rly.IsON = SectionsOn;
MasterOn = SectionsOn;
MasterFound = true;
clsRelay Rly = cRelays[i];

if (Rly.Type == RelayTypes.Master)
{
Rly.IsON = SectionsOn;
MasterOn = SectionsOn;
MasterFound = true;
}
}
}

// set hydraulic relays
HydUPDown(ModuleID);
// set hydraulic relays
HydUPDown(ModuleID);

// set tram lines, geo stop
for (int i = 0; i < cRelays.Count; i++)
{
clsRelay Rly = cRelays[i];
if (Rly.ModuleID == ModuleID)
// set tram lines, geo stop
for (int i = 0; i < cRelays.Count; i++)
{
if (Rly.Type == RelayTypes.TramLeft) Rly.IsON = mf.MachineData.TramLeft;
if (Rly.Type == RelayTypes.TramRight) Rly.IsON = mf.MachineData.TramRight;
if (Rly.Type == RelayTypes.GeoStop) Rly.IsON = mf.MachineData.GeoStop;
clsRelay Rly = cRelays[i];
if (Rly.ModuleID == ModuleID)
{
if (Rly.Type == RelayTypes.TramLeft) Rly.IsON = mf.MachineData.TramLeft;
if (Rly.Type == RelayTypes.TramRight) Rly.IsON = mf.MachineData.TramRight;
if (Rly.Type == RelayTypes.GeoStop) Rly.IsON = mf.MachineData.GeoStop;
}
}
}

// set section, slave, power relays
int Result = 0;
for (int i = 0; i < cRelays.Count; i++)
{
clsRelay Rly = cRelays[i];
if (Rly.ModuleID == ModuleID)
// set section, slave, power relays
for (int i = 0; i < cRelays.Count; i++)
{
switch (Rly.Type)
clsRelay Rly = cRelays[i];
if (Rly.ModuleID == ModuleID)
{
case RelayTypes.Section:
if (MasterFound && !MasterOn)
{
// leave relay to previous value, master relay is off
// do nothing
}
else
{
// set relay by section
Rly.IsON = mf.Sections.Items[Rly.SectionID].IsON;
}
break;

case RelayTypes.Slave:
if (MasterFound && !MasterOn)
{
// leave relay to previous value, master relay is off
// do nothing
}
else
{
// set relay if at lease one section on
Rly.IsON = SectionsOn;
}
break;

case RelayTypes.Power:
cRelays[i].IsON = true;
break;
switch (Rly.Type)
{
case RelayTypes.Section:
if (MasterFound && !MasterOn)
{
// leave relay to previous value, master relay is off
// do nothing
}
else
{
// set relay by section
Rly.IsON = mf.Sections.Items[Rly.SectionID].IsON;
}
break;

case RelayTypes.Slave:
if (MasterFound && !MasterOn)
{
// leave relay to previous value, master relay is off
// do nothing
}
else
{
// set relay if at lease one section on
Rly.IsON = SectionsOn;
}
break;

case RelayTypes.Power:
cRelays[i].IsON = true;
break;

case RelayTypes.Invert_Section:
if (MasterFound && !MasterOn)
{
// leave relay to previous value, master relay is off
// do nothing
}
else
{
// set relay by section
Rly.IsON = !mf.Sections.Items[Rly.SectionID].IsON;
}
break;
}

case RelayTypes.Invert_Section:
if (MasterFound && !MasterOn)
{
// leave relay to previous value, master relay is off
// do nothing
}
else
{
// set relay by section
Rly.IsON = !mf.Sections.Items[Rly.SectionID].IsON;
}
break;
// build return int
if (Rly.IsON) Result |= (int)Math.Pow(2, i);
}

// build return int
if (Rly.IsON) Result |= (int)Math.Pow(2, i);
}
}
catch (Exception ex)
{
mf.Tls.WriteErrorLog("clsRelays/SetRelays: " + ex.Message);
}

return Result;
}
Expand Down
Binary file not shown.
Binary file modified RateAppSource/RateController/obj/Debug/RateController.exe
Binary file not shown.
Binary file modified RateAppSource/RateController/obj/Debug/RateController.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified RateControllerApp/RateController.exe
Binary file not shown.
Binary file modified RateControllerApp/de/RateController.resources.dll
Binary file not shown.
Binary file modified RateControllerApp/fr/RateController.resources.dll
Binary file not shown.
Binary file modified RateControllerApp/hu/RateController.resources.dll
Binary file not shown.
Binary file modified RateControllerApp/nl/RateController.resources.dll
Binary file not shown.
Binary file modified RateControllerApp/pl/RateController.resources.dll
Binary file not shown.
Binary file modified RateControllerApp/ru/RateController.resources.dll
Binary file not shown.

0 comments on commit 4b50edc

Please sign in to comment.