Compare commits
6
Commits
6f076919c7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0c328d97e | ||
|
|
d8c2292b24 | ||
|
|
c005378368 | ||
|
|
4b9bcc6ad3 | ||
|
|
c3f4acaf07 | ||
|
|
49bdd5d4c0 |
No files matched your search
@@ -1,7 +1,35 @@
|
||||
|
||||
[plc]
|
||||
port = COM1
|
||||
sensor_delay_open = 0 ; seconds
|
||||
sensor_delay_close = 2 ; seconds
|
||||
|
||||
[update]
|
||||
url = https://elwig.at/files/pamhagen-sysctrl/latest
|
||||
auto = true
|
||||
|
||||
[xbe24]
|
||||
a1 = PATH_MW2_PRESS1
|
||||
a2 = PATH_MW2_PRESS2
|
||||
a3 = PATH_MW2_T1
|
||||
a4 = PATH_MW2_T2
|
||||
a5 = PATH_MW2_T3
|
||||
a6 = PATH_MW2_T4
|
||||
b1 = START_REBLER
|
||||
b2 = STOP_REBLER
|
||||
b3 = SELECT_MW2
|
||||
b4 = TOGGLE_STIRRER_MW2
|
||||
b5 = START_MP2
|
||||
b6 = STOP_MP2
|
||||
c1 = START_TROUGH_AUGER
|
||||
c2 = STOP_TROUGH_AUGER
|
||||
c3 = SELECT_MW1
|
||||
c4 = TOGGLE_STIRRER_MW1
|
||||
c5 = START_MP1
|
||||
c6 = STOP_MP1
|
||||
d1 = PATH_MW1_PRESS1
|
||||
d2 = PATH_MW1_PRESS2
|
||||
d3 = PATH_MW1_T1
|
||||
d4 = PATH_MW1_T2
|
||||
d5 = PATH_MW1_T3
|
||||
d6 = PATH_MW1_T4
|
||||
@@ -34,15 +34,12 @@ namespace PamhagenSysCtrl {
|
||||
}
|
||||
|
||||
protected override async void OnStartup(StartupEventArgs evt) {
|
||||
if (Config == null)
|
||||
return;
|
||||
|
||||
Version = new Version(typeof(App).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion.Split('+')[0] ?? "0.0.0");
|
||||
|
||||
Plant = new(Config.PlcPort);
|
||||
try {
|
||||
await Plant.StartThread();
|
||||
} catch (Exception exc) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
base.OnStartup(evt);
|
||||
|
||||
if (Config.UpdateUrl != null && Config.UpdateAuto) {
|
||||
|
||||
@@ -9,11 +9,16 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
private readonly string FileName;
|
||||
|
||||
public string PlcPort = "COM1";
|
||||
public int PlcSensorDelayOpen = 0;
|
||||
public int PlcSensorDelayClose = 0;
|
||||
public string? UpdateUrl;
|
||||
public bool UpdateAuto;
|
||||
|
||||
public PamhagenPlant.ShortcutKey?[] Xbe24KeyMap;
|
||||
|
||||
public Config(string filename) {
|
||||
FileName = filename;
|
||||
Xbe24KeyMap = new PamhagenPlant.ShortcutKey?[24];
|
||||
Read();
|
||||
}
|
||||
|
||||
@@ -21,12 +26,30 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
try {
|
||||
var config = new ConfigurationBuilder().AddIniFile(FileName).Build();
|
||||
PlcPort = config["plc:port"] ?? "COM1";
|
||||
PlcSensorDelayOpen = int.Parse(config["plc:sensor_delay_open"] ?? "0");
|
||||
PlcSensorDelayClose = int.Parse(config["plc:sensor_delay_close"] ?? "0");
|
||||
UpdateUrl = config["update:url"];
|
||||
UpdateAuto = TrueValues.Contains(config["update:auto"]?.ToLower());
|
||||
var xbe24 = config.GetSection("xbe24");
|
||||
for (char c = 'a'; c <= 'd'; c++) {
|
||||
for (int r = 1; r <= 6; r++) {
|
||||
int n = (c - 'a') * 6 + r - 1;
|
||||
var s = xbe24[$"{c}{r}"]?.ToUpper();
|
||||
Xbe24KeyMap[n] = s == null ? null : Enum.Parse<PamhagenPlant.ShortcutKey>(s);
|
||||
}
|
||||
}
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show($"Die Konfigurationsdatei konnte nicht gelesen werden:\n\n{exc.Message}", "Konfigurationsdatei lesen", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public PamhagenPlant.ShortcutKey? MapKey(int n) {
|
||||
return n < 0 || Xbe24KeyMap.Length < n ? null : Xbe24KeyMap[n];
|
||||
}
|
||||
|
||||
public int? MapKey(PamhagenPlant.ShortcutKey key) {
|
||||
return Xbe24KeyMap.IndexOf(key) is int n ? n == -1 ? null : n : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace PamhagenSysCtrl.Helpers {
|
||||
public static class Extensions {
|
||||
|
||||
public static void SetBacklight(this Xbe24Keyboard k, PamhagenPlant.ShortcutKey key, Color color, bool flashing = false) {
|
||||
if (App.Config.MapKey(key) is int n)
|
||||
k.SetBacklight(n, color, flashing);
|
||||
}
|
||||
|
||||
public static bool IsKeyPressed(this Xbe24Keyboard k, PamhagenPlant.ShortcutKey key) {
|
||||
return App.Config.MapKey(key) is int n && k.IsKeyPressed(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,12 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
public readonly Tank Tank7;
|
||||
public readonly Tank Tank8;
|
||||
public readonly Tank Tank9;
|
||||
public readonly Valve V5;
|
||||
public readonly Valve V6;
|
||||
public readonly Valve V7;
|
||||
public readonly Valve V8;
|
||||
|
||||
public readonly Dictionary<PamhagenPlant.ShortcutKey, (ISource Source, Pump Pump, INode? Intermediate, ISink Sink)> PathShortcuts;
|
||||
|
||||
public PamhagenGraph() {
|
||||
double mw2X = -118;
|
||||
@@ -66,26 +72,26 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
var pr1X = -15;
|
||||
var pr2X = 23;
|
||||
|
||||
var trough = new EntryTrough("Auffangwanne", mw1X + 14, rebY - 20, () => App.Plant?.IsTroughAugerActive ?? false);
|
||||
var trough = new EntryTrough("Auffangwanne", mw1X + 14, rebY - 20, () => App.Plant?.State.TroughAuger_IsActive ?? false);
|
||||
Nodes.Add(trough);
|
||||
|
||||
Auger1 = new EncasedAuger("", rebX - 19, rebY, () => App.Plant?.IsAuger1Active ?? false);
|
||||
var auger0 = new EncasedAuger("Pressen-\nQuerschnecke", rebX - 39, rebY, () => App.Plant?.IsPresseQuerSchneckeActive ?? false, 180, clickable: false);
|
||||
Auger3 = new EncasedAuger("", rebX - 23, rebY - 24, () => App.Plant?.IsAuger3Active ?? false, 135);
|
||||
var belt = new ConveyorBelt("", rebX - 29, rebY - 8, () => App.Plant?.IsAuger2Active ?? false);
|
||||
Auger1 = new EncasedAuger("", rebX - 19, rebY, () => App.Plant?.State.Auger1_IsActive ?? false);
|
||||
var auger0 = new EncasedAuger("Pressen-\nQuerschnecke", rebX - 39, rebY, () => App.Plant?.State.PressCrossAuger_IsActive ?? false, 180, clickable: false);
|
||||
Auger3 = new EncasedAuger("", rebX - 23, rebY - 24, () => App.Plant?.State.Auger3_IsActive ?? false, 135);
|
||||
var belt = new ConveyorBelt("", rebX - 29, rebY - 8, () => App.Plant?.State.Auger2_IsActive ?? false);
|
||||
Nodes.Add(belt);
|
||||
Nodes.Add(Auger1);
|
||||
Nodes.Add(auger0);
|
||||
Nodes.Add(Auger3);
|
||||
var rebler = new Rebler("Rebler", rebX, rebY, () => App.Plant?.IsReblerActive ?? false);
|
||||
var rebler = new Rebler("Rebler", rebX, rebY, () => App.Plant?.State.Rebler_IsActive ?? false);
|
||||
Nodes.Add(rebler);
|
||||
var switcher = new Switcher("", rebX, rebY + 12, () => App.Plant?.TroughSelector ?? 0, () => App.Plant == null ? 0 : App.Plant.WantMW1Selected ? 1 : 2);
|
||||
var switcher = new Switcher("", rebX, rebY + 12, () => App.Plant?.State.MW1_IsSelected == true ? 1 : App.Plant?.State.MW2_IsSelected == true ? 2 : 0, () => App.Plant?.State.MW1_WantSelected == true ? 1 : App.Plant?.State.MW2_WantSelected == true ? 2 : 0);
|
||||
Nodes.Add(switcher);
|
||||
|
||||
MW1 = new Trough("MW1", mw1X, mpY - 14, () => App.Plant?.FillLevelMW1 ?? FillState.Unknown);
|
||||
MW2 = new Trough("MW2", mw2X, mpY - 14, () => App.Plant?.FillLevelMW2 ?? FillState.Unknown);
|
||||
MP1 = new Pump("MP1", mw1X, mpY, () => App.Plant?.MP1 ?? default, () => App.Plant?.MP1HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
MP2 = new Pump("MP2", mw2X, mpY, () => App.Plant?.MP2 ?? default, () => App.Plant?.MP2HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
MW1 = new Trough("MW1", mw1X, mpY - 14, () => App.Plant?.State.MW1_FillLevel ?? FillState.Unknown);
|
||||
MW2 = new Trough("MW2", mw2X, mpY - 14, () => App.Plant?.State.MW2_FillLevel ?? FillState.Unknown);
|
||||
MP1 = new Pump("MP1", mw1X, mpY, () => App.Plant?.State.MP1_State ?? default, () => App.Plant?.State.MP1_HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Contains(x)));
|
||||
MP2 = new Pump("MP2", mw2X, mpY, () => App.Plant?.State.MP2_State ?? default, () => App.Plant?.State.MP2_HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Contains(x)));
|
||||
var x1 = new PipeJoin(mw1X, mpY + 8);
|
||||
var x2 = new PipeJoin(mw2X, mpY + 8);
|
||||
|
||||
@@ -116,23 +122,23 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
CreatePipe(v4, x5, true);
|
||||
CreatePipe(x5, x6, true);
|
||||
|
||||
var v5 = CreateValve(5, x1X + 6, ltg1Y, 1);
|
||||
var v6 = CreateValve(6, x1X + 6, ltg2Y + 8, 3);
|
||||
var v7 = CreateValve(7, x1X + 6, ltg2Y, 3);
|
||||
var v8 = CreateValve(8, x1X - 6, ltg2Y + 8, 0);
|
||||
V5 = CreateValve(5, x1X + 6, ltg1Y, 1);
|
||||
V6 = CreateValve(6, x1X + 6, ltg2Y + 8, 3);
|
||||
V7 = CreateValve(7, x1X + 6, ltg2Y, 3);
|
||||
V8 = CreateValve(8, x1X - 6, ltg2Y + 8, 0);
|
||||
var v9 = CreateValve(9, ltg2X, ltg5Y + 8, 2);
|
||||
|
||||
CreatePipe(x4, v5);
|
||||
CreatePipe(x4, v6, true);
|
||||
CreatePipe(x6, v7);
|
||||
CreatePipe(x6, v8);
|
||||
CreatePipe(v7, v9, label: "Ltg. 2", labelOffsetX: 6);
|
||||
CreatePipe(x4, V5);
|
||||
CreatePipe(x4, V6, true);
|
||||
CreatePipe(x6, V7);
|
||||
CreatePipe(x6, V8);
|
||||
CreatePipe(V7, v9, label: "Ltg. 2", labelOffsetX: 6);
|
||||
|
||||
var xv15 = new PipeJoin(ltg1X, wt1Y + 8);
|
||||
var xv11 = new PipeJoin(ltg2X, wt1Y + 14);
|
||||
var x7 = new PipeJoin(ltg2X, ltg5Y);
|
||||
|
||||
CreatePipe(v5, xv15, label: "Ltg. 1", labelOffsetX: 6);
|
||||
CreatePipe(V5, xv15, label: "Ltg. 1", labelOffsetX: 6);
|
||||
CreatePipe(v9, x7);
|
||||
CreatePipe(x7, xv11);
|
||||
|
||||
@@ -309,14 +315,14 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
CreateInlet(v43, Tank9);
|
||||
|
||||
var xp12 = new PipeJoin((t1X + t2X) / 2, tanksY + 16);
|
||||
P12 = new Pump("P1/2", (t1X + t2X) / 2, tanksY + 22, () => App.Plant?.P12 ?? default, () => App.Plant?.P12HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
P12 = new Pump("P1/2", (t1X + t2X) / 2, tanksY + 22, () => App.Plant?.State.P12_State ?? default, () => App.Plant?.State.P12_HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Contains(x)));
|
||||
CreateOutlet(Tank1, xp12);
|
||||
CreateOutlet(Tank2, xp12);
|
||||
CreatePipe(xp12, P12);
|
||||
|
||||
P3 = new Pump("P3", t3X, tanksY + 22, () => App.Plant?.P3 ?? default, () => App.Plant?.P3HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
P4 = new Pump("P4", t4X, tanksY + 22, () => App.Plant?.P4 ?? default, () => App.Plant?.P4HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
P5 = new Pump("P5", t5X, tanksY + 22, () => App.Plant?.P5 ?? default, () => App.Plant?.P5HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
P3 = new Pump("P3", t3X, tanksY + 22, () => App.Plant?.State.P3_State ?? default, () => App.Plant?.State.P3_HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Contains(x)));
|
||||
P4 = new Pump("P4", t4X, tanksY + 22, () => App.Plant?.State.P4_State ?? default, () => App.Plant?.State.P4_HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Contains(x)));
|
||||
P5 = new Pump("P5", t5X, tanksY + 22, () => App.Plant?.State.P5_State ?? default, () => App.Plant?.State.P5_HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Contains(x)));
|
||||
CreateOutlet(Tank3, P3);
|
||||
CreateOutlet(Tank4, P4);
|
||||
CreateOutlet(Tank5, P5);
|
||||
@@ -346,7 +352,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
var xt6 = new PipeJoin(t6X, tanksY + 22);
|
||||
var xt7 = new PipeJoin(t7X, tanksY + 22);
|
||||
var xt8 = new PipeJoin(t8X, tanksY + 22);
|
||||
P6 = new Pump("P6", t6X, tanksY + 30, () => App.Plant?.P6 ?? default, () => App.Plant?.P6HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
P6 = new Pump("P6", t6X, tanksY + 30, () => App.Plant?.State.P6_State ?? default, () => App.Plant?.State.P6_HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Contains(x)));
|
||||
CreateOutlet(Tank6, xt6);
|
||||
CreateOutlet(Tank7, xt7);
|
||||
CreateOutlet(Tank8, xt8);
|
||||
@@ -380,8 +386,8 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
var xp7 = new PipeJoin(pr2cX, ltg8Y);
|
||||
var xp8 = new PipeJoin(pr2cX, ltg9Y);
|
||||
|
||||
CreatePipe(v6, xp1, true, label: "Ltg. 3", labelOffsetX: 6);
|
||||
CreatePipe(v8, xp2, true, label: "Ltg. 4", labelOffsetX: 18);
|
||||
CreatePipe(V6, xp1, true, label: "Ltg. 3", labelOffsetX: 6);
|
||||
CreatePipe(V8, xp2, true, label: "Ltg. 4", labelOffsetX: 18);
|
||||
CreatePipe(v49, xp3, true, label: "Ltg. 8");
|
||||
CreatePipe(P6, xp4, true, label: "Ltg. 9");
|
||||
CreatePipe(xp1, v51, true);
|
||||
@@ -404,28 +410,97 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
CreatePipe(xp5, xp6);
|
||||
CreatePipe(xp7, xp8);
|
||||
|
||||
var zv1 = new ExternalValve("ZV1", pr1cX, prY - 8, 0, () => App.Plant?.Press1HasClearance ?? false);
|
||||
var zv2 = new ExternalValve("ZV2", pr2cX, prY - 8, 2, () => App.Plant?.Press2HasClearance ?? false);
|
||||
var zv1 = new ExternalValve("ZV1", pr1cX, prY - 8, 0, () => App.Plant?.State.Press1_HasClearance ?? false);
|
||||
var zv2 = new ExternalValve("ZV2", pr2cX, prY - 8, 2, () => App.Plant?.State.Press2_HasClearance ?? false);
|
||||
CreatePipe(xp6, zv1, true);
|
||||
CreatePipe(xp8, zv2, true);
|
||||
CreateInlet(zv1, Press1, true);
|
||||
CreateInlet(zv2, Press2, true);
|
||||
|
||||
PathShortcuts = [];
|
||||
foreach (var key in Enum.GetValues<PamhagenPlant.ShortcutKey>()) {
|
||||
var n = Enum.GetName(key);
|
||||
if (n?.StartsWith("PATH_") != true) continue;
|
||||
ISource src;
|
||||
Pump p;
|
||||
INode? inter = null;
|
||||
ISink sink;
|
||||
if (n.StartsWith("PATH_MW1_")) {
|
||||
src = MW1;
|
||||
p = MP1;
|
||||
} else if (n.StartsWith("PATH_MW2_")) {
|
||||
src = MW2;
|
||||
p = MP2;
|
||||
} else if (n.StartsWith("PATH_T12_")) {
|
||||
src = Tank1;
|
||||
p = P12;
|
||||
} else if (n.StartsWith("PATH_T3_")) {
|
||||
src = Tank3;
|
||||
p = P3;
|
||||
} else if (n.StartsWith("PATH_T4_")) {
|
||||
src = Tank4;
|
||||
p = P4;
|
||||
} else if (n.StartsWith("PATH_T5_")) {
|
||||
src = Tank5;
|
||||
p = P5;
|
||||
} else if (n.StartsWith("PATH_P6_")) {
|
||||
src = Tank6;
|
||||
p = P6;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if (n.Contains("_LTG1_")) {
|
||||
inter = V5;
|
||||
} else if (n.Contains("_LTG2_")) {
|
||||
inter = V7;
|
||||
} else if (n.Contains("_LTG3_")) {
|
||||
inter = V6;
|
||||
} else if (n.Contains("_LTG4_")) {
|
||||
inter = V8;
|
||||
}
|
||||
if (n.EndsWith("_PRESS1")) {
|
||||
sink = Press1;
|
||||
} else if (n.EndsWith("_PRESS2")) {
|
||||
sink = Press2;
|
||||
} else if (n.EndsWith("_T1")) {
|
||||
sink = Tank1;
|
||||
} else if (n.EndsWith("_T2")) {
|
||||
sink = Tank2;
|
||||
} else if (n.EndsWith("_T3")) {
|
||||
sink = Tank3;
|
||||
} else if (n.EndsWith("_T4")) {
|
||||
sink = Tank4;
|
||||
} else if (n.EndsWith("_T5")) {
|
||||
sink = Tank5;
|
||||
} else if (n.EndsWith("_T6")) {
|
||||
sink = Tank6;
|
||||
} else if (n.EndsWith("_T7")) {
|
||||
sink = Tank7;
|
||||
} else if (n.EndsWith("_T8")) {
|
||||
sink = Tank8;
|
||||
} else if (n.EndsWith("_T9")) {
|
||||
sink = Tank9;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
PathShortcuts[key] = (src, p, inter, sink);
|
||||
}
|
||||
}
|
||||
|
||||
protected ControlledValve CreateValve(int n, double x, double y, int o) {
|
||||
return new(n, x, y, o, () => App.Plant?.IsValveOpen(n) ?? false, (v) => App.Plant?.ManualControlMode ?? false ? App.Plant.WantValveOpen(n) : SelectedPaths.Any(p => p.Hops.Any(h => h.Node == v)));
|
||||
return new(n, x, y, o, () => App.Plant?.State.Valve_OpenState(n), (v) => App.Plant?.ManualControlMode ?? false ? App.Plant.State.Valve_WantOpen(n) : SelectedPaths.Any(p => p.Contains(v)));
|
||||
}
|
||||
|
||||
protected static Tank CreateTank(int n, double x, double y, int capacity) {
|
||||
return new($"Tank {n}", x, y, capacity, () => App.Plant?.TankFillLevels[n - 1] ?? FillState.Unknown);
|
||||
return new($"Tank {n}", x, y, capacity, () => App.Plant?.State.Tanks_FillLevel[n - 1] ?? FillState.Unknown);
|
||||
}
|
||||
|
||||
private int PathCost(Path p) {
|
||||
return
|
||||
1000 * p.Hops.Count(h => h.Node is Valve) +
|
||||
(p.Hops.Any(h => h.Node is ControlledValve v && v.Nr == 15) && !p.Hops.Any(h => h.Node is ControlledValve v && (v.Nr == 16 || v.Nr == 20)) ? 10 : 0) +
|
||||
(p.Hops.Any(h => h.Node is ControlledValve v && v.Nr == 11) && !p.Hops.Any(h => h.Node is ControlledValve v && (v.Nr == 14 || v.Nr == 21)) ? 10 : 0) +
|
||||
(p.Hops.Any(h => h.Node is ControlledValve v && v.Nr == 6) ? 10 : 0) +
|
||||
1000 * p.Valves.Count() +
|
||||
(p.InnerValves.Any(v => v.Nr == 15) && !p.InnerValves.Any(v => v.Nr == 16 || v.Nr == 20) ? 10 : 0) +
|
||||
(p.InnerValves.Any(v => v.Nr == 11) && !p.InnerValves.Any(v => v.Nr == 14 || v.Nr == 21) ? 10 : 0) +
|
||||
(p.InnerValves.Any(v => v.Nr == 6) ? 10 : 0) +
|
||||
p.Bends;
|
||||
}
|
||||
|
||||
@@ -437,76 +512,47 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
}
|
||||
}
|
||||
|
||||
public void TraverseSubgraph(INode start, Func<INode, bool> invalid, HashSet<IEdge>? _visited = null, Action<INode, bool, IEdge>? edgeAction = null, Action<ControlledValve>? valveAction = null, bool reverse = false) {
|
||||
var visited = _visited ?? [];
|
||||
if (start is ControlledValve v) {
|
||||
valveAction?.Invoke(v);
|
||||
}
|
||||
if (invalid(start)) {
|
||||
return;
|
||||
}
|
||||
public static IEnumerable<(INode Start, IEdge Edge, bool EdgeReverse, INode End)> TraverseSubgraph(INode start, Func<INode, bool> isBorder, HashSet<IEdge>? _visited = null, bool reverse = false) {
|
||||
if (isBorder(start))
|
||||
yield break;
|
||||
|
||||
var visited = _visited ?? [];
|
||||
foreach (var edge in start.Inputs) {
|
||||
if (visited.Contains(edge)) continue;
|
||||
var o = edge.IsTwoWay && edge.Start == start ? edge.End : edge.Start;
|
||||
edgeAction?.Invoke(start, reverse || _visited == null, edge);
|
||||
yield return (start, edge, reverse || _visited == null, o);
|
||||
visited.Add(edge);
|
||||
TraverseSubgraph(o, invalid, visited, edgeAction, valveAction, reverse || _visited == null);
|
||||
foreach (var e in TraverseSubgraph(o, isBorder, visited, reverse || _visited == null))
|
||||
yield return e;
|
||||
}
|
||||
foreach (var edge in start.Outputs) {
|
||||
if (visited.Contains(edge)) continue;
|
||||
var o = edge.IsTwoWay && edge.End == start ? edge.Start : edge.End;
|
||||
edgeAction?.Invoke(start, reverse, edge);
|
||||
yield return (start, edge, reverse, o);
|
||||
visited.Add(edge);
|
||||
TraverseSubgraph(o, invalid, visited, edgeAction, valveAction, reverse);
|
||||
foreach (var e in TraverseSubgraph(o, isBorder, visited, reverse))
|
||||
yield return e;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddPath(Path path) {
|
||||
_selectedPaths.Add(path);
|
||||
UpdateValvesAdjacientToPath(path, true, false);
|
||||
path.LockValves();
|
||||
if (App.Plant is PamhagenPlant plant) {
|
||||
foreach (var (_, node) in path.Hops) {
|
||||
if (node is ControlledValve v) {
|
||||
plant.OpenV(v.Nr);
|
||||
}
|
||||
}
|
||||
foreach (var v in path.InnerValves) plant.OpenV(v.Nr);
|
||||
foreach (var v in path.BorderValves) plant.CloseV(v.Nr);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovePath(Path path) {
|
||||
_selectedPaths.Remove(path);
|
||||
UpdateValvesAdjacientToPath(path, false);
|
||||
foreach (var p in _selectedPaths) UpdateValvesAdjacientToPath(p, true);
|
||||
path.UnlockValves();
|
||||
if (App.Plant is PamhagenPlant plant) {
|
||||
foreach (var (_, node) in path.Hops) {
|
||||
if (node is ControlledValve v) {
|
||||
plant.CloseV(v.Nr);
|
||||
}
|
||||
}
|
||||
foreach (var v in path.InnerValves) plant.CloseV(v.Nr);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateValvesAdjacientToPath(Path path, bool locked, bool? wantOpen = null) {
|
||||
foreach (var (edge, node) in path.Hops) {
|
||||
TraverseSubgraph(node, (n) => n is ControlledValve || n is ISink || n is Pump, valveAction: (v) => {
|
||||
if (locked) {
|
||||
v.LockedForPaths.Add(path);
|
||||
} else {
|
||||
v.LockedForPaths.Remove(path);
|
||||
}
|
||||
if (wantOpen.HasValue) {
|
||||
if (wantOpen.Value) {
|
||||
App.Plant?.OpenV(v.Nr);
|
||||
} else {
|
||||
App.Plant?.CloseV(v.Nr);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void ColorPipesAdjacientToPath(Path path, Brush? color1, MotorState flowArrows, Brush? color2) {
|
||||
public static void ColorPipesAdjacientToPath(Path path, Brush? color1, MotorState flowArrows, Brush? color2) {
|
||||
var color = color1;
|
||||
var flowPathOffset = 0.0;
|
||||
HashSet<IEdge> visited = [];
|
||||
@@ -520,27 +566,28 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
}
|
||||
visited.Add(edge);
|
||||
if (node is Pump) color = color2;
|
||||
TraverseSubgraph(node, (n) => n is Valve || n is ISink || n is Pump, visited, edgeAction: (s, r, e) => e.Highlight = color);
|
||||
foreach (var (_, e, _, _) in TraverseSubgraph(node, (n) => n is Valve || n is ISink || n is Pump, visited)) {
|
||||
e.Highlight = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ColorPipesByValves(INode start, Brush? color1, MotorState flowArrows, Brush? color2) {
|
||||
public static void ColorPipesByValves(INode start, Brush? color1, MotorState flowArrows, Brush? color2) {
|
||||
var flowPathOffset = 0.0;
|
||||
TraverseSubgraph(start, (n) => n is ISink || n is Outlet || !((n as Valve)?.IsOpen ?? (n as ExternalValve)?.IsOpen ?? true), null,
|
||||
edgeAction: (s, r, e) => {
|
||||
if (((e.Start as Valve)?.IsOpen ?? true) && ((e.End as Valve)?.IsOpen ?? true)) {
|
||||
e.Highlight = color1;
|
||||
if (flowArrows == MotorState.Forward || flowArrows == MotorState.Backward) {
|
||||
var dir = e.Start == s;
|
||||
if (r) dir = !dir;
|
||||
if (flowArrows == MotorState.Backward) dir = !dir;
|
||||
e.Flow = (dir, flowPathOffset);
|
||||
flowPathOffset += e.FlowLength;
|
||||
}
|
||||
} else {
|
||||
e.Highlight = color2;
|
||||
foreach (var (s, e, r, _) in TraverseSubgraph(start, (n) => n is ISink || n is Outlet || !((n as Valve)?.IsOpen ?? (n as ExternalValve)?.IsOpen ?? true))) {
|
||||
if (((e.Start as Valve)?.IsOpen ?? true) && ((e.End as Valve)?.IsOpen ?? true)) {
|
||||
e.Highlight = color1;
|
||||
if (flowArrows == MotorState.Forward || flowArrows == MotorState.Backward) {
|
||||
var dir = e.Start == s;
|
||||
if (r) dir = !dir;
|
||||
if (flowArrows == MotorState.Backward) dir = !dir;
|
||||
e.Flow = (dir, flowPathOffset);
|
||||
flowPathOffset += e.FlowLength;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
e.Highlight = color2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -13,7 +13,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
|
||||
protected Func<Valve, bool> CallbackWantOpen;
|
||||
|
||||
public ControlledValve(int nr, double x, double y, int orientation, Func<bool> cbOpen, Func<Valve, bool> cbWant) :
|
||||
public ControlledValve(int nr, double x, double y, int orientation, Func<bool?> cbOpen, Func<Valve, bool> cbWant) :
|
||||
base(x, y, orientation, cbOpen) {
|
||||
Nr = nr;
|
||||
CallbackWantOpen = cbWant;
|
||||
@@ -23,9 +23,9 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
if (App.Plant?.ManualControlMode ?? false) {
|
||||
_text?.Visibility = Visibility.Visible;
|
||||
_triangles?.Fill =
|
||||
!WantOpen && !IsOpen && !isHovering ? PamhagenBrushes.Red :
|
||||
!WantOpen && !IsOpen ? PamhagenBrushes.Green :
|
||||
!WantOpen && IsOpen ? PamhagenBrushes.DimRed :
|
||||
!WantOpen && IsClosed && !isHovering ? PamhagenBrushes.Red :
|
||||
!WantOpen && IsClosed ? PamhagenBrushes.Green :
|
||||
!WantOpen && !IsClosed ? PamhagenBrushes.DimRed :
|
||||
WantOpen && !IsOpen ? PamhagenBrushes.DimGreen :
|
||||
WantOpen && IsOpen && !isHovering ? PamhagenBrushes.Green :
|
||||
WantOpen && IsOpen ? PamhagenBrushes.Red :
|
||||
@@ -33,12 +33,19 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
} else {
|
||||
_text?.Visibility = isHovering ? Visibility.Visible : Visibility.Hidden;
|
||||
_triangles?.Fill =
|
||||
IsLocked && !WantOpen && !IsOpen ? PamhagenBrushes.DimOrange :
|
||||
IsLocked && !WantOpen && IsOpen ? PamhagenBrushes.Red :
|
||||
IsLocked && !WantOpen && IsClosed ? PamhagenBrushes.DimOrange :
|
||||
IsLocked && !WantOpen && !IsClosed ? PamhagenBrushes.Red :
|
||||
IsLocked && WantOpen && !IsOpen ? PamhagenBrushes.Yellow :
|
||||
IsLocked && WantOpen && IsOpen ? PamhagenBrushes.Green :
|
||||
Highlight ?? (isHovering ? Brushes.LightGray : Brushes.DarkGray);
|
||||
}
|
||||
if (!IsClosed) {
|
||||
_topLine?.Points[1] = _middlePoints.Open.Top;
|
||||
_bottomLine?.Points[1] = _middlePoints.Open.Bottom;
|
||||
} else {
|
||||
_topLine?.Points[1] = _middlePoints.Closed.Top;
|
||||
_bottomLine?.Points[1] = _middlePoints.Closed.Bottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
|
||||
public override string Label { get; }
|
||||
|
||||
public ExternalValve(string label, double x, double y, int orientation, Func<bool> cbOpen) :
|
||||
public ExternalValve(string label, double x, double y, int orientation, Func<bool?> cbOpen) :
|
||||
base(x, y, orientation, cbOpen) {
|
||||
Label = label;
|
||||
}
|
||||
@@ -17,6 +17,13 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
!IsOpen ? PamhagenBrushes.Red :
|
||||
IsOpen ? PamhagenBrushes.Green :
|
||||
Highlight ?? Brushes.DarkGray;
|
||||
if (!IsClosed) {
|
||||
_topLine?.Points[1] = _middlePoints.Open.Top;
|
||||
_bottomLine?.Points[1] = _middlePoints.Open.Bottom;
|
||||
} else {
|
||||
_topLine?.Points[1] = _middlePoints.Closed.Top;
|
||||
_bottomLine?.Points[1] = _middlePoints.Closed.Bottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,43 @@
|
||||
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
public record struct Path(
|
||||
INode Start,
|
||||
IEnumerable<(IEdge Edge, INode Node)> Hops)
|
||||
{
|
||||
INode Start,
|
||||
(IEdge Edge, INode Node)[] Hops
|
||||
) {
|
||||
public readonly int Bends => Hops.Sum(h => (h.Node is not Valve && h.Node is not PipeJoin ? 1 : 0) + (h.Edge.Start.CenterX != h.Edge.End.CenterX && h.Edge.Start.CenterY != h.Edge.End.CenterY ? 1 : 0));
|
||||
public readonly double Length => Hops.Sum(h => Math.Abs(h.Edge.Start.CenterX - h.Edge.End.CenterX) + Math.Abs(h.Edge.Start.CenterY - h.Edge.End.CenterY));
|
||||
|
||||
public readonly INode End => Hops.Last().Node;
|
||||
public readonly IEnumerable<INode> Nodes => [Start, .. Hops.Select(h => h.Node)];
|
||||
|
||||
public readonly bool Contains(INode node) => Nodes.Any(h => h == node);
|
||||
public readonly bool Matches(INode start, INode end) => Matches(start, null, end);
|
||||
public readonly bool Matches(INode start, INode? intermediate, INode end) => Start == start && End == end && (intermediate == null || Nodes.Any(n => n == intermediate));
|
||||
|
||||
public readonly IEnumerable<Pump> Pumps => Nodes.Select(n => n as Pump).Where(p => p != null).Cast<Pump>();
|
||||
public readonly IEnumerable<Valve> Valves => Nodes.Select(n => n as Valve).Where(v => v != null).Cast<Valve>();
|
||||
|
||||
private readonly IEnumerable<ControlledValve> InnerAndBorderValves => Nodes
|
||||
.SelectMany(node => PamhagenGraph.TraverseSubgraph(node, (n) => n is ControlledValve || n is ISink || n is Pump))
|
||||
.Select(e => e.End as ControlledValve)
|
||||
.Where(v => v != null)
|
||||
.Cast<ControlledValve>()
|
||||
.Distinct();
|
||||
public readonly IEnumerable<ControlledValve> InnerValves => Nodes.Select(n => n as ControlledValve).Where(v => v != null).Cast<ControlledValve>();
|
||||
public readonly IEnumerable<ControlledValve> BorderValves => InnerAndBorderValves.Except(InnerValves);
|
||||
|
||||
public readonly bool HasActivePump => Nodes.Any(n => n is Pump p && p.IsActive);
|
||||
public readonly bool IsReady => InnerValves.All(v => v.IsOpen && v.WantOpen && v.IsLocked) && BorderValves.All(v => v.IsClosed && !v.WantOpen && v.IsLocked);
|
||||
|
||||
public readonly void LockValves() {
|
||||
foreach (var v in InnerAndBorderValves) {
|
||||
v.LockedForPaths.Add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void UnlockValves() {
|
||||
foreach (var v in InnerAndBorderValves) {
|
||||
v.LockedForPaths.Remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,19 +16,22 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
|
||||
public int Orientation { get; set; }
|
||||
|
||||
public bool IsOpen => CallbackIsOpen();
|
||||
public bool IsOpen => CallbackIsOpen() == true;
|
||||
public bool IsClosed => CallbackIsOpen() == false;
|
||||
public bool IsTransitioning => CallbackIsOpen() == null;
|
||||
public ISet<IEdge> Inputs { get; init; }
|
||||
public ISet<IEdge> Outputs { get; init; }
|
||||
|
||||
protected Func<bool> CallbackIsOpen;
|
||||
protected Func<bool?> CallbackIsOpen;
|
||||
|
||||
protected Rectangle? _background;
|
||||
protected Polygon? _triangles;
|
||||
protected Polyline? _topLine;
|
||||
protected Polyline? _bottomLine;
|
||||
protected ((Point Top, Point Bottom) Closed, (Point Top, Point Bottom) Open) _middlePoints;
|
||||
protected TextBlock? _text;
|
||||
|
||||
public Valve(double x, double y, int orientation, Func<bool> cbOpen) {
|
||||
public Valve(double x, double y, int orientation, Func<bool?> cbOpen) {
|
||||
CenterX = x;
|
||||
CenterY = y;
|
||||
CallbackIsOpen = cbOpen;
|
||||
@@ -83,6 +86,9 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
Graph.ToPx(CenterX + WIDTH / 4, CenterY, scale),
|
||||
Graph.ToPx(CenterX + WIDTH / 2, CenterY + LENGTH / 4, scale),
|
||||
];
|
||||
if (_topLine != null && _bottomLine != null)
|
||||
_middlePoints = ((_topLine.Points[1], _bottomLine.Points[1]),
|
||||
(Graph.ToPx(CenterX - WIDTH / 3, CenterY, scale), Graph.ToPx(CenterX + WIDTH / 3, CenterY, scale)));
|
||||
} else {
|
||||
Graph.SetCenter(_background, CenterX, CenterY, LENGTH, LENGTH / 2, scale);
|
||||
_triangles?.Points = [
|
||||
@@ -101,6 +107,9 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
Graph.ToPx(CenterX, CenterY + WIDTH / 4, scale),
|
||||
Graph.ToPx(CenterX + LENGTH / 4, CenterY + WIDTH / 2, scale),
|
||||
];
|
||||
if (_topLine != null && _bottomLine != null)
|
||||
_middlePoints = ((_topLine.Points[1], _bottomLine.Points[1]),
|
||||
(Graph.ToPx(CenterX, CenterY - WIDTH / 3, scale), Graph.ToPx(CenterX, CenterY + WIDTH / 3, scale)));
|
||||
}
|
||||
_triangles?.StrokeThickness = border;
|
||||
_topLine?.StrokeThickness = border;
|
||||
|
||||
+12
-12
@@ -1,18 +1,18 @@
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace PamhagenSysCtrl.Helpers {
|
||||
public class PamhagenPlc : IDisposable {
|
||||
namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
public class LegacyPamhagenPlc : IDisposable {
|
||||
|
||||
public record struct SensorStates(
|
||||
long PressureSensors,
|
||||
FillState FillingLevelMW1,
|
||||
FillState FillingLevelMW2,
|
||||
FillState FillLevelMW1,
|
||||
FillState FillLevelMW2,
|
||||
bool ClearancePress1,
|
||||
bool ClearancePress2,
|
||||
int TroughSelector,
|
||||
double GradationOe,
|
||||
FillState[] FillingLevelTanks,
|
||||
MotorState PresseQuerSchnecke
|
||||
FillState[] FillLevelTanks,
|
||||
MotorState PressCrossAuger
|
||||
) {
|
||||
public readonly bool GetDS(int n) => (PressureSensors & (1L << (n - 1))) != 0;
|
||||
}
|
||||
@@ -34,12 +34,12 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
|
||||
protected readonly T1 Plc;
|
||||
|
||||
public string PortName => Plc.PortName;
|
||||
public T1.Status LastPlcStatus => Plc.LastStatus;
|
||||
public T1Error LastPlcError => Plc.LastError;
|
||||
public string ComPort => Plc.PortName;
|
||||
public T1.Status LastStatus => Plc.LastStatus;
|
||||
public T1Error LastError => Plc.LastError;
|
||||
|
||||
public PamhagenPlc(string portName, Parity parity = Parity.Odd) {
|
||||
Plc = new T1(portName, parity);
|
||||
public LegacyPamhagenPlc(string comPort, Parity parity = Parity.Odd) {
|
||||
Plc = new T1(comPort, parity);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
@@ -95,7 +95,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
throw new T1Exception($"Interner Fehler: {error} ({(int)error:0000})");
|
||||
}
|
||||
|
||||
protected async Task<(ushort RW010, ushort RW011, ushort RW012, ushort RW013, ushort RW014, ushort RW015, ushort RW016)> ReadInputRegisters() {
|
||||
public async Task<(ushort RW010, ushort RW011, ushort RW012, ushort RW013, ushort RW014, ushort RW015, ushort RW016)> ReadInputRegisters() {
|
||||
var d = await Plc.DataRead("RW010", 7);
|
||||
// RW010, RW011, RW012, RW013 Drucksensoren
|
||||
// RW014 Füllstände A1, A2, Presse1, Presse2, Wannenselekt
|
||||
@@ -0,0 +1,347 @@
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
public class PamhagenPlc : IDisposable {
|
||||
|
||||
private bool _manualControlMode = false;
|
||||
private bool _overridePathClearnaces = false;
|
||||
private bool _overrideDryRunClearances = false;
|
||||
public bool ManualControlMode { get => _manualControlMode; set { _manualControlMode = value; UpdateInterlocks(); } }
|
||||
public bool OverridePathClearances { get => _overridePathClearnaces; set { _overridePathClearnaces = value; UpdateInterlocks(); } }
|
||||
public bool OverrideDryRunClearances { get => _overrideDryRunClearances; set { _overrideDryRunClearances = value; UpdateInterlocks(); } }
|
||||
|
||||
internal bool MP1_WantActive { get; private set; }
|
||||
internal bool MP2_WantActive { get; private set; }
|
||||
internal bool P12_WantActive { get; private set; }
|
||||
internal bool P3_WantActive { get; private set; }
|
||||
internal bool P4_WantActive { get; private set; }
|
||||
internal bool P5_WantActive { get; private set; }
|
||||
internal bool P6_WantActive { get; private set; }
|
||||
|
||||
protected LegacyPamhagenPlc Plc;
|
||||
public PamhagenState State { get; private set; }
|
||||
|
||||
public string? ComPort => Plc?.ComPort;
|
||||
public T1.Status? LastStatus => Plc?.LastStatus;
|
||||
public T1Error? LastError => Plc?.LastError;
|
||||
|
||||
internal LegacyPamhagenPlc.ActuatorStates Actuators;
|
||||
internal LegacyPamhagenPlc.ActuatorStates LastActuators;
|
||||
internal LegacyPamhagenPlc.SensorStates[] LastSensors = [];
|
||||
|
||||
internal readonly int ConsiderLastSensorsOpen;
|
||||
internal readonly int ConsiderLastSensorsClose;
|
||||
|
||||
public PamhagenPlc(string comPort, int sensorDelayOpenMs, int sensorDelayCloseMs, Parity parity = Parity.Odd) {
|
||||
Plc = new(comPort, parity);
|
||||
ConsiderLastSensorsOpen = sensorDelayOpenMs / 125 + 1;
|
||||
ConsiderLastSensorsClose = sensorDelayCloseMs / 125 + 1;
|
||||
LastSensors = new LegacyPamhagenPlc.SensorStates[Math.Max(ConsiderLastSensorsOpen, ConsiderLastSensorsClose)];
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
GC.SuppressFinalize(this);
|
||||
Plc.Dispose();
|
||||
}
|
||||
|
||||
public async Task Initialize() {
|
||||
await Plc.TestConnection();
|
||||
Actuators = await Plc.ReadOutputs();
|
||||
LastActuators = Actuators;
|
||||
var sensors = await Plc.ReadInputs();
|
||||
LastSensors[0] = sensors;
|
||||
State = new(LastSensors, this);
|
||||
}
|
||||
|
||||
public async Task Shutdown() {
|
||||
await Plc.WriteOutputs(new() { Valves = Actuators.Valves });
|
||||
}
|
||||
|
||||
public async Task Update() {
|
||||
UpdateInterlocks();
|
||||
|
||||
if (Actuators != LastActuators) {
|
||||
LastActuators = Actuators;
|
||||
await Plc.WriteOutputs(LastActuators);
|
||||
}
|
||||
var sensors = await Plc.ReadInputs();
|
||||
Array.Copy(LastSensors, 0, LastSensors, 1, LastSensors.Length - 1);
|
||||
LastSensors[0] = sensors;
|
||||
State = new(LastSensors, this);
|
||||
|
||||
UpdateInterlocks();
|
||||
}
|
||||
|
||||
protected void UpdateInterlocks() {
|
||||
if (!ManualControlMode) {
|
||||
if (State.PressCrossAuger_IsActive && !State.Auger2_IsActive) StartAuger2();
|
||||
if (State.Rebler_IsActive && !State.Auger1_IsActive) StartAuger1();
|
||||
if (State.Auger1_IsActive && !State.Auger2_IsActive) StartAuger2();
|
||||
if (State.Auger2_IsActive && !State.Auger3_IsActive) StartAuger3();
|
||||
if (State.TroughAuger_IsActive && !State.TroughAuger_HasClearance)
|
||||
StopTroughAuger();
|
||||
if (!State.PressCrossAuger_IsActive && !State.Auger1_IsActive) {
|
||||
StopAuger2();
|
||||
StopAuger3();
|
||||
}
|
||||
}
|
||||
|
||||
if (State.MP1_IsActive && !State.MP1_HasClearance) StopMP1();
|
||||
if (State.MP2_IsActive && !State.MP2_HasClearance) StopMP2();
|
||||
if (State.P12_IsActive && !State.P12_HasClearance) DisableP12();
|
||||
if (State.P3_IsActive && !State.P3_HasClearance) DisableP3();
|
||||
if (State.P4_IsActive && !State.P4_HasClearance) DisableP4();
|
||||
if (State.P5_IsActive && !State.P5_HasClearance) DisableP5();
|
||||
if (State.P6_IsActive && !State.P6_HasClearance) DisableP6();
|
||||
|
||||
if (MP1_WantActive && State.MP1_HasClearance) StartMP1Forward();
|
||||
if (MP2_WantActive && State.MP2_HasClearance) StartMP2Forward();
|
||||
if (P12_WantActive && State.P12_HasClearance) EnableP12();
|
||||
if (P3_WantActive && State.P3_HasClearance) EnableP3();
|
||||
if (P4_WantActive && State.P4_HasClearance) EnableP4();
|
||||
if (P5_WantActive && State.P5_HasClearance) EnableP5();
|
||||
if (P6_WantActive && State.P6_HasClearance) EnableP6();
|
||||
|
||||
if (!ManualControlMode) {
|
||||
if (State.MP1_State == MotorState.Forward && State.MW1_FillLevel >= FillState.Half && !State.MW1_Stirrer_IsActive) {
|
||||
StartStirrerMW1();
|
||||
} else if (State.MW2_Stirrer_IsActive && (!State.MP1_IsActive || State.MW1_FillLevel < FillState.Half)) {
|
||||
StopStirrerMW1();
|
||||
}
|
||||
if (State.MP2_State == MotorState.Forward && State.MW2_FillLevel >= FillState.Half && !State.MW2_Stirrer_IsActive) {
|
||||
StartStirrerMW2();
|
||||
} else if (State.MW2_Stirrer_IsActive && (!State.MP2_IsActive || State.MW2_FillLevel < FillState.Half)) {
|
||||
StopStirrerMW2();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenV(int n) => SetV(n, true);
|
||||
public void CloseV(int n) => SetV(n, false);
|
||||
|
||||
protected void SetV(int n, bool val) {
|
||||
if (n < 1 || n > 57) throw new ArgumentException("Invalid value for n: 1 <= #V <= 57");
|
||||
Actuators.SetV(n, val);
|
||||
}
|
||||
|
||||
public void SelectMW1() {
|
||||
Actuators.SetV(58, true);
|
||||
}
|
||||
|
||||
public void SelectMW2() {
|
||||
Actuators.SetV(58, false);
|
||||
}
|
||||
|
||||
public void StartTroughAuger() {
|
||||
if (!ManualControlMode && !State.TroughAuger_HasClearance)
|
||||
throw new NoClearanceException("Schnecke Auffangwanne hat keine Freigabe");
|
||||
Actuators.TroughAuger = true;
|
||||
}
|
||||
|
||||
public void StopTroughAuger() {
|
||||
Actuators.TroughAuger = false;
|
||||
}
|
||||
|
||||
public void StartRebler() {
|
||||
Actuators.Rebler = true;
|
||||
if (!ManualControlMode) StartAuger1();
|
||||
}
|
||||
|
||||
public void StopRebler() {
|
||||
if (!ManualControlMode) StopTroughAuger();
|
||||
Actuators.Rebler = false;
|
||||
if (!ManualControlMode) StopAuger1();
|
||||
}
|
||||
|
||||
public void StartStirrerMW1() {
|
||||
Actuators.StirrerMW1 = true;
|
||||
}
|
||||
|
||||
public void StopStirrerMW1() {
|
||||
Actuators.StirrerMW1 = false;
|
||||
}
|
||||
|
||||
public void StartStirrerMW2() {
|
||||
Actuators.StirrerMW2 = true;
|
||||
}
|
||||
|
||||
public void StopStirrerMW2() {
|
||||
Actuators.StirrerMW2 = false;
|
||||
}
|
||||
|
||||
public void StartAuger1() {
|
||||
Actuators.Auger1 = true;
|
||||
if (!ManualControlMode) StartAuger2();
|
||||
}
|
||||
|
||||
public void StopAuger1() {
|
||||
if (!ManualControlMode && State.Rebler_IsActive) throw new NoClearanceException("Rebler aktiv");
|
||||
Actuators.Auger1 = false;
|
||||
if (!ManualControlMode && !State.PressCrossAuger_IsActive)
|
||||
StopAuger2();
|
||||
}
|
||||
|
||||
public void StartAuger2() {
|
||||
Actuators.Auger2 = true;
|
||||
if (!ManualControlMode) StartAuger3();
|
||||
}
|
||||
|
||||
public void StopAuger2() {
|
||||
if (!ManualControlMode && State.PressCrossAuger_IsActive) throw new NoClearanceException("Presse-Querschnecke aktiv");
|
||||
if (!ManualControlMode && State.Auger1_IsActive) throw new NoClearanceException("Förderschnecke 1 aktiv");
|
||||
Actuators.Auger2 = false;
|
||||
if (!ManualControlMode)
|
||||
StopAuger3();
|
||||
}
|
||||
|
||||
public void StartAuger3() {
|
||||
Actuators.Auger3 = true;
|
||||
}
|
||||
|
||||
public void StopAuger3() {
|
||||
if (!ManualControlMode && State.Auger2_IsActive) throw new NoClearanceException("Förderschnecke 2 aktiv");
|
||||
Actuators.Auger3 = false;
|
||||
}
|
||||
|
||||
public void StartGradationPump() {
|
||||
Actuators.GradationPump = true;
|
||||
}
|
||||
|
||||
public void StopGradationPump() {
|
||||
Actuators.GradationPump = false;
|
||||
}
|
||||
|
||||
public void StartMP1Forward() {
|
||||
if (!State.MP1_HasClearance) {
|
||||
if (!State.MP1_HasDryRunClearance || !State.MP1_WantsPathClearance)
|
||||
throw new NoClearanceException("MP1 hat keine Freigabe");
|
||||
MP1_WantActive = true;
|
||||
return;
|
||||
}
|
||||
MP1_WantActive = false;
|
||||
if (Actuators.MP1 == MotorState.Backward) throw new NoClearanceException("MP1 läuft bereits (zurück)");
|
||||
Actuators.MP1 = MotorState.Forward;
|
||||
if (State.MW1_FillLevel >= FillState.Half) StartStirrerMW1();
|
||||
}
|
||||
|
||||
public void StartMP1Backward() {
|
||||
MP1_WantActive = false;
|
||||
if (!State.MP1_HasClearance) throw new NoClearanceException("MP1 hat keine Freigabe");
|
||||
if (Actuators.MP1 == MotorState.Forward) throw new NoClearanceException("MP1 läuft bereits (vor)");
|
||||
Actuators.MP1 = MotorState.Backward;
|
||||
}
|
||||
|
||||
public void StopMP1() {
|
||||
MP1_WantActive = false;
|
||||
Actuators.MP1 = MotorState.Halt;
|
||||
if (!ManualControlMode) StopStirrerMW1();
|
||||
}
|
||||
|
||||
public void StartMP2Forward() {
|
||||
if (!State.MP2_HasClearance) {
|
||||
if (!State.MP2_HasDryRunClearance || !State.MP2_WantsPathClearance)
|
||||
throw new NoClearanceException("MP2 hat keine Freigabe");
|
||||
MP2_WantActive = true;
|
||||
return;
|
||||
}
|
||||
MP2_WantActive = false;
|
||||
if (Actuators.MP2 == MotorState.Backward) throw new NoClearanceException("MP2 läuft bereits (zurück)");
|
||||
Actuators.MP2 = MotorState.Forward;
|
||||
if (State.MW2_FillLevel >= FillState.Half) StartStirrerMW2();
|
||||
}
|
||||
|
||||
public void StartMP2Backward() {
|
||||
MP2_WantActive = false;
|
||||
if (!State.MP2_HasClearance) throw new NoClearanceException("MP2 hat keine Freigabe");
|
||||
if (Actuators.MP2 == MotorState.Forward) throw new NoClearanceException("MP2 läuft bereits (vor)");
|
||||
Actuators.MP2 = MotorState.Backward;
|
||||
}
|
||||
|
||||
public void StopMP2() {
|
||||
MP2_WantActive = false;
|
||||
Actuators.MP2 = MotorState.Halt;
|
||||
if (!ManualControlMode) StopStirrerMW1();
|
||||
}
|
||||
|
||||
public void EnableP12() {
|
||||
if (!State.P12_HasClearance) {
|
||||
if (!State.P12_HasDryRunClearance || !State.P12_WantsPathClearance)
|
||||
throw new NoClearanceException("P1/2 hat keine Freigabe");
|
||||
P12_WantActive = true;
|
||||
return;
|
||||
}
|
||||
P12_WantActive = false;
|
||||
if (!State.P12_HasClearance) throw new NoClearanceException("P1/2 hat keine Freigabe");
|
||||
Actuators.P12 = MotorState.Forward;
|
||||
}
|
||||
|
||||
public void DisableP12() {
|
||||
P12_WantActive = false;
|
||||
Actuators.P12 = MotorState.Halt;
|
||||
}
|
||||
|
||||
public void EnableP3() {
|
||||
if (!State.P3_HasClearance) {
|
||||
if (!State.P3_HasDryRunClearance || !State.P3_WantsPathClearance)
|
||||
throw new NoClearanceException("P3 hat keine Freigabe");
|
||||
P3_WantActive = true;
|
||||
return;
|
||||
}
|
||||
P3_WantActive = false;
|
||||
Actuators.P3 = MotorState.Forward;
|
||||
}
|
||||
|
||||
public void DisableP3() {
|
||||
P3_WantActive = false;
|
||||
Actuators.P3 = MotorState.Halt;
|
||||
}
|
||||
|
||||
public void EnableP4() {
|
||||
if (!State.P4_HasClearance) {
|
||||
if (!State.P4_HasDryRunClearance || !State.P4_WantsPathClearance)
|
||||
throw new NoClearanceException("P4 hat keine Freigabe");
|
||||
P4_WantActive = true;
|
||||
return;
|
||||
}
|
||||
P4_WantActive = false;
|
||||
Actuators.P4 = MotorState.Forward;
|
||||
}
|
||||
|
||||
public void DisableP4() {
|
||||
P4_WantActive = false;
|
||||
Actuators.P4 = MotorState.Halt;
|
||||
}
|
||||
|
||||
public void EnableP5() {
|
||||
if (!State.P5_HasClearance) {
|
||||
if (!State.P5_HasDryRunClearance || !State.P5_WantsPathClearance)
|
||||
throw new NoClearanceException("P5 hat keine Freigabe");
|
||||
P5_WantActive = true;
|
||||
return;
|
||||
}
|
||||
P5_WantActive = false;
|
||||
Actuators.P5 = MotorState.Forward;
|
||||
}
|
||||
|
||||
public void DisableP5() {
|
||||
P5_WantActive = false;
|
||||
Actuators.P5 = MotorState.Halt;
|
||||
}
|
||||
|
||||
public void EnableP6() {
|
||||
if (!State.P6_HasClearance) {
|
||||
if (!State.P6_HasDryRunClearance || !State.P6_WantsPathClearance)
|
||||
throw new NoClearanceException("P6 hat keine Freigabe");
|
||||
P6_WantActive = true;
|
||||
return;
|
||||
}
|
||||
P6_WantActive = false;
|
||||
Actuators.P6 = MotorState.Forward;
|
||||
}
|
||||
|
||||
public void DisableP6() {
|
||||
P6_WantActive = false;
|
||||
Actuators.P6 = MotorState.Halt;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
public readonly record struct PamhagenState {
|
||||
|
||||
private readonly LegacyPamhagenPlc.SensorStates Sensors;
|
||||
private readonly PamhagenPlc Plc;
|
||||
private LegacyPamhagenPlc.ActuatorStates Actuators => Plc == null ? default : Plc.Actuators;
|
||||
|
||||
public bool ManualControlMode => Plc != null && Plc.ManualControlMode;
|
||||
public bool OverridePathClearances => Plc != null && Plc.OverridePathClearances;
|
||||
public bool OverrideDryRunClearances => Plc != null && Plc.OverrideDryRunClearances;
|
||||
|
||||
public long Valves => Actuators.Valves;
|
||||
public readonly long OpenValves { get; }
|
||||
public readonly long ClosedValves { get; }
|
||||
|
||||
public bool MW1_IsSelected => Sensors.TroughSelector == 1;
|
||||
public bool MW2_IsSelected => Sensors.TroughSelector == 2;
|
||||
public bool MW1_WantSelected => Actuators.GetV(58);
|
||||
public bool MW2_WantSelected => !Actuators.GetV(58);
|
||||
public FillState MW1_FillLevel => Sensors.FillLevelMW1;
|
||||
public FillState MW2_FillLevel => Sensors.FillLevelMW2;
|
||||
|
||||
public FillState[] Tanks_FillLevel => Sensors.FillLevelTanks ?? [FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown, FillState.Unknown];
|
||||
public FillState T1_FillLevel => Sensors.FillLevelTanks[0];
|
||||
public FillState T2_FillLevel => Sensors.FillLevelTanks[1];
|
||||
public FillState T3_FillLevel => Sensors.FillLevelTanks[2];
|
||||
public FillState T4_FillLevel => Sensors.FillLevelTanks[3];
|
||||
public FillState T5_FillLevel => Sensors.FillLevelTanks[4];
|
||||
public FillState T6_FillLevel => Sensors.FillLevelTanks[5];
|
||||
public FillState T7_FillLevel => Sensors.FillLevelTanks[6];
|
||||
public FillState T8_FillLevel => Sensors.FillLevelTanks[7];
|
||||
public FillState T9_FillLevel => Sensors.FillLevelTanks[8];
|
||||
|
||||
public MotorState PressCrossAuger_State => Sensors.PressCrossAuger;
|
||||
public bool PressCrossAuger_IsActive => PressCrossAuger_State == MotorState.Forward;
|
||||
|
||||
public bool TroughAuger_IsActive => Actuators.TroughAuger;
|
||||
public bool Rebler_IsActive => Actuators.Rebler;
|
||||
public bool MW1_Stirrer_IsActive => Actuators.StirrerMW1;
|
||||
public bool MW2_Stirrer_IsActive => Actuators.StirrerMW2;
|
||||
public bool Auger1_IsActive => Actuators.Auger1;
|
||||
public bool Auger2_IsActive => Actuators.Auger2;
|
||||
public bool Auger3_IsActive => Actuators.Auger3;
|
||||
public bool WasteDisposal_IsActive => Auger1_IsActive || Auger2_IsActive || Auger3_IsActive;
|
||||
|
||||
public MotorState MP1_State => Actuators.MP1;
|
||||
public MotorState MP2_State => Actuators.MP2;
|
||||
public MotorState P12_State => Actuators.P12;
|
||||
public MotorState P3_State => Actuators.P3;
|
||||
public MotorState P4_State => Actuators.P4;
|
||||
public MotorState P5_State => Actuators.P5;
|
||||
public MotorState P6_State => Actuators.P6;
|
||||
public bool MP1_IsActive => Actuators.MP1 == MotorState.Forward || Actuators.MP1 == MotorState.Backward;
|
||||
public bool MP2_IsActive => Actuators.MP2 == MotorState.Forward || Actuators.MP2 == MotorState.Backward;
|
||||
public bool P12_IsActive => Actuators.P12 == MotorState.Forward;
|
||||
public bool P3_IsActive => Actuators.P3 == MotorState.Forward;
|
||||
public bool P4_IsActive => Actuators.P4 == MotorState.Forward;
|
||||
public bool P5_IsActive => Actuators.P5 == MotorState.Forward;
|
||||
public bool P6_IsActive => Actuators.P6 == MotorState.Forward;
|
||||
|
||||
public bool Press1_HasClearance => Sensors.ClearancePress1;
|
||||
public bool Press2_HasClearance => Sensors.ClearancePress2;
|
||||
public bool TroughAuger_HasClearance => Rebler_IsActive && !(MW1_IsSelected && MW1_FillLevel == FillState.Full) && !(MW2_IsSelected && MW2_FillLevel == FillState.Full);
|
||||
|
||||
private readonly bool MP1_PathClearance;
|
||||
private readonly bool MP2_PathClearance;
|
||||
private readonly bool P12_PathClearance;
|
||||
private readonly bool P3_PathClearance;
|
||||
private readonly bool P4_PathClearance;
|
||||
private readonly bool P5_PathClearance;
|
||||
private readonly bool P6_PathClearance;
|
||||
private readonly bool MP1_DryRunClearance;
|
||||
private readonly bool MP2_DryRunClearance;
|
||||
private readonly bool P12_DryRunClearance;
|
||||
private readonly bool P3_DryRunClearance;
|
||||
private readonly bool P4_DryRunClearance;
|
||||
private readonly bool P5_DryRunClearance;
|
||||
private readonly bool P6_DryRunClearance;
|
||||
|
||||
public readonly bool MP1_WantsPathClearance { get; }
|
||||
public readonly bool MP2_WantsPathClearance { get; }
|
||||
public readonly bool P12_WantsPathClearance { get; }
|
||||
public readonly bool P3_WantsPathClearance { get; }
|
||||
public readonly bool P4_WantsPathClearance { get; }
|
||||
public readonly bool P5_WantsPathClearance { get; }
|
||||
public readonly bool P6_WantsPathClearance { get; }
|
||||
|
||||
public bool MP1_WantActive => Plc.MP1_WantActive;
|
||||
public bool MP2_WantActive => Plc.MP2_WantActive;
|
||||
public bool P12_WantActive => Plc.P12_WantActive;
|
||||
public bool P3_WantActive => Plc.P3_WantActive;
|
||||
public bool P4_WantActive => Plc.P4_WantActive;
|
||||
public bool P5_WantActive => Plc.P5_WantActive;
|
||||
public bool P6_WantActive => Plc.P6_WantActive;
|
||||
|
||||
public bool MP1_HasPathClearance => OverridePathClearances || MP1_PathClearance;
|
||||
public bool MP2_HasPathClearance => OverridePathClearances || MP2_PathClearance;
|
||||
public bool P12_HasPathClearance => OverridePathClearances || P12_PathClearance;
|
||||
public bool P3_HasPathClearance => OverridePathClearances || P3_PathClearance;
|
||||
public bool P4_HasPathClearance => OverridePathClearances || P4_PathClearance;
|
||||
public bool P5_HasPathClearance => OverridePathClearances || P5_PathClearance;
|
||||
public bool P6_HasPathClearance => OverridePathClearances || P6_PathClearance;
|
||||
public bool MP1_HasDryRunClearance => OverrideDryRunClearances || MP1_DryRunClearance;
|
||||
public bool MP2_HasDryRunClearance => OverrideDryRunClearances || MP2_DryRunClearance;
|
||||
public bool P12_HasDryRunClearance => OverrideDryRunClearances || P12_DryRunClearance;
|
||||
public bool P3_HasDryRunClearance => OverrideDryRunClearances || P3_DryRunClearance;
|
||||
public bool P4_HasDryRunClearance => OverrideDryRunClearances || P4_DryRunClearance;
|
||||
public bool P5_HasDryRunClearance => OverrideDryRunClearances || P5_DryRunClearance;
|
||||
public bool P6_HasDryRunClearance => OverrideDryRunClearances || P6_DryRunClearance;
|
||||
public bool MP1_HasClearance => MP1_HasDryRunClearance && MP1_HasPathClearance;
|
||||
public bool MP2_HasClearance => MP2_HasDryRunClearance && MP2_HasPathClearance;
|
||||
public bool P12_HasClearance => P12_HasDryRunClearance && P12_HasPathClearance;
|
||||
public bool P3_HasClearance => P3_HasDryRunClearance && P3_HasPathClearance;
|
||||
public bool P4_HasClearance => P4_HasDryRunClearance && P4_HasPathClearance;
|
||||
public bool P5_HasClearance => P4_HasDryRunClearance && P5_HasPathClearance;
|
||||
public bool P6_HasClearance => P6_HasDryRunClearance && P6_HasPathClearance;
|
||||
|
||||
public PamhagenState(IEnumerable<LegacyPamhagenPlc.SensorStates> sensors, PamhagenPlc plc) {
|
||||
Sensors = sensors.First();
|
||||
Plc = plc;
|
||||
|
||||
OpenValves = sensors.Take(Plc.ConsiderLastSensorsOpen).Aggregate(-1L, (m, s) => m & ~s.PressureSensors);
|
||||
ClosedValves = sensors.Take(Plc.ConsiderLastSensorsClose).Aggregate(-1L, (m, s) => m & s.PressureSensors);
|
||||
|
||||
MP1_WantsPathClearance = WantsPathClearnace(this, Paths.MP1);
|
||||
MP2_WantsPathClearance = WantsPathClearnace(this, Paths.MP2);
|
||||
P12_WantsPathClearance = WantsPathClearnace(this, Paths.P12);
|
||||
P3_WantsPathClearance = WantsPathClearnace(this, Paths.P3);
|
||||
P4_WantsPathClearance = WantsPathClearnace(this, Paths.P4);
|
||||
P5_WantsPathClearance = WantsPathClearnace(this, Paths.P5);
|
||||
P6_WantsPathClearance = WantsPathClearnace(this, Paths.P6);
|
||||
|
||||
MP1_PathClearance = HasPathClearance(this, Paths.MP1);
|
||||
MP2_PathClearance = HasPathClearance(this, Paths.MP2);
|
||||
P12_PathClearance = HasPathClearance(this, Paths.P12);
|
||||
P3_PathClearance = HasPathClearance(this, Paths.P3);
|
||||
P4_PathClearance = HasPathClearance(this, Paths.P4);
|
||||
P5_PathClearance = HasPathClearance(this, Paths.P5);
|
||||
P6_PathClearance = HasPathClearance(this, Paths.P6);
|
||||
|
||||
MP1_DryRunClearance = MW1_FillLevel != FillState.Empty;
|
||||
MP2_DryRunClearance = MW2_FillLevel != FillState.Empty;
|
||||
P12_DryRunClearance = T1_FillLevel != FillState.Empty || T2_FillLevel != FillState.Empty;
|
||||
P3_DryRunClearance = T3_FillLevel != FillState.Empty;
|
||||
P4_DryRunClearance = T4_FillLevel != FillState.Empty;
|
||||
P5_DryRunClearance = T5_FillLevel != FillState.Empty;
|
||||
P6_DryRunClearance = true;
|
||||
}
|
||||
|
||||
public bool Valve_IsClosed(int n) => (ClosedValves & (1L << (n - 1))) != 0;
|
||||
public bool Valve_IsTransitioning(int n) => !Valve_IsClosed(n) && !Valve_IsOpen(n);
|
||||
public bool Valve_IsOpen(int n) => (OpenValves & (1L << (n - 1))) != 0;
|
||||
public bool? Valve_OpenState(int n) => Valve_IsOpen(n) ? true : Valve_IsClosed(n) ? false : null;
|
||||
public bool Valve_WantOpen(int n) => Actuators.GetV(n);
|
||||
public bool Valve_WantClosed(int n) => !Valve_WantOpen(n);
|
||||
|
||||
private record struct ValveStates(int[] Open, int[] Closed) {
|
||||
public readonly ValveStateMask ToMask() => new(Open.Aggregate(0L, (m, n) => m | (1L << (n - 1))), Open.Concat(Closed).Aggregate(0L, (m, n) => m | (1L << (n - 1))));
|
||||
public static ValveStates operator +(ValveStates a, ValveStates b) {
|
||||
return new([.. a.Open, .. b.Open], [.. a.Closed, .. b.Closed]);
|
||||
}
|
||||
}
|
||||
|
||||
private record struct ValveStateMask(long States, long Mask) {
|
||||
public static ValveStateMask[] From(IEnumerable<ValveStates> states) => [.. states.Select(s => s.ToMask())];
|
||||
public static bool operator ==(long a, ValveStateMask b) => (a & b.Mask) == b.States;
|
||||
public static bool operator >=(long a, ValveStateMask b) => (a & b.States) == b.States;
|
||||
public static bool operator !=(long a, ValveStateMask b) => !(a == b);
|
||||
public static bool operator <=(long a, ValveStateMask b) => !(a >= b);
|
||||
}
|
||||
|
||||
private static bool HasSinglePathClearance(PamhagenState state, IEnumerable<ValveStateMask> masks) {
|
||||
return masks.Any(m => state.Valves == m && state.OpenValves == m && ~state.ClosedValves == m);
|
||||
}
|
||||
|
||||
private static bool HasAnyPathClearance(PamhagenState state, IEnumerable<ValveStateMask> masks) {
|
||||
return masks.Any(m => state.Valves >= m && state.OpenValves >= m && ~state.ClosedValves >= m);
|
||||
}
|
||||
|
||||
private static bool WantsSinglePathClearance(PamhagenState state, IEnumerable<ValveStateMask> masks) {
|
||||
return masks.Any(m => state.Valves == m);
|
||||
}
|
||||
|
||||
private static bool WantsAnyPathClearance(PamhagenState state, IEnumerable<ValveStateMask> masks) {
|
||||
return masks.Any(m => state.Valves >= m);
|
||||
}
|
||||
|
||||
private static bool HasPathClearance(PamhagenState state, (ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) masks) {
|
||||
return
|
||||
(HasSinglePathClearance(state, masks.Press1) && state.Press1_HasClearance) ||
|
||||
(HasSinglePathClearance(state, masks.Press2) && state.Press2_HasClearance) ||
|
||||
(HasSinglePathClearance(state, masks.Tanks[0]) && state.T1_FillLevel != FillState.Full) ||
|
||||
(HasSinglePathClearance(state, masks.Tanks[1]) && state.T2_FillLevel != FillState.Full) ||
|
||||
(HasSinglePathClearance(state, masks.Tanks[2]) && state.T3_FillLevel != FillState.Full) ||
|
||||
(HasSinglePathClearance(state, masks.Tanks[3]) && state.T4_FillLevel != FillState.Full) ||
|
||||
(HasSinglePathClearance(state, masks.Tanks[4]) && state.T5_FillLevel != FillState.Full) ||
|
||||
(HasSinglePathClearance(state, masks.Tanks[5]) && state.T6_FillLevel != FillState.Full) ||
|
||||
(HasSinglePathClearance(state, masks.Tanks[6]) && state.T7_FillLevel != FillState.Full) ||
|
||||
(HasSinglePathClearance(state, masks.Tanks[7]) && state.T8_FillLevel != FillState.Full) ||
|
||||
(HasSinglePathClearance(state, masks.Tanks[8]) && state.T9_FillLevel != FillState.Full) ||
|
||||
false;
|
||||
}
|
||||
|
||||
private static bool WantsPathClearnace(PamhagenState state, (ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) masks) {
|
||||
return
|
||||
(WantsSinglePathClearance(state, masks.Press1) && state.Press1_HasClearance) ||
|
||||
(WantsSinglePathClearance(state, masks.Press2) && state.Press2_HasClearance) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[0]) && state.T1_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[1]) && state.T2_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[2]) && state.T3_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[3]) && state.T4_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[4]) && state.T5_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[5]) && state.T6_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[6]) && state.T7_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[7]) && state.T8_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[8]) && state.T9_FillLevel != FillState.Full) ||
|
||||
false;
|
||||
}
|
||||
|
||||
private static bool HasPathClearance(PamhagenState state, (ValveStateMask[] Press1, ValveStateMask[] Press2) masks) {
|
||||
return
|
||||
(HasSinglePathClearance(state, masks.Press1) && state.Press1_HasClearance) ||
|
||||
(HasSinglePathClearance(state, masks.Press2) && state.Press2_HasClearance) ||
|
||||
false;
|
||||
}
|
||||
|
||||
private static bool WantsPathClearnace(PamhagenState state, (ValveStateMask[] Press1, ValveStateMask[] Press2) masks) {
|
||||
return
|
||||
(WantsSinglePathClearance(state, masks.Press1) && state.Press1_HasClearance) ||
|
||||
(WantsSinglePathClearance(state, masks.Press2) && state.Press2_HasClearance) ||
|
||||
false;
|
||||
}
|
||||
|
||||
private static readonly (
|
||||
(ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) MP1,
|
||||
(ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) MP2,
|
||||
(ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) P12,
|
||||
(ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) P3,
|
||||
(ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) P4,
|
||||
(ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) P5,
|
||||
(ValveStateMask[] Press1, ValveStateMask[] Press2) P6
|
||||
) Paths;
|
||||
|
||||
static PamhagenState() {
|
||||
ValveStates[] wt_aa = [
|
||||
new([12], [15, 16, 20]), // bypass
|
||||
new([15, 18, 16], [11, 12, 14, 17, 19, 20]), // WT1
|
||||
new([15, 17, 20], [11, 12, 18, 19, 21]), // WT2
|
||||
new([15, 18, 19, 20], [11, 12, 14, 16, 17, 21]), // WT1+WT2
|
||||
];
|
||||
ValveStates[] wt_ab = [
|
||||
new([15, 18, 14], [11, 12, 13, 16, 17, 19, 21]), // WT1
|
||||
new([15, 17, 21], [11, 12, 13, 18, 19, 20]), // WT2
|
||||
new([15, 18, 19, 21], [11, 12, 13, 14, 16, 17, 20]), // WT1+WT2
|
||||
];
|
||||
ValveStates[] wt_ba = [
|
||||
new([11, 18, 16], [15, 12, 13, 14, 17, 19, 20]), // WT1
|
||||
new([11, 17, 20], [15, 12, 13, 18, 19, 21]), // WT2
|
||||
new([11, 18, 19, 20], [15, 12, 13, 14, 16, 17, 21]), // WT1+WT2
|
||||
];
|
||||
ValveStates[] wt_bb = [
|
||||
new([13], [11, 14, 21]), // bypass
|
||||
new([11, 18, 14], [15, 13, 16, 17, 19, 21]), // WT1
|
||||
new([11, 17, 21], [15, 13, 18, 19, 20]), // WT2
|
||||
new([11, 18, 19, 21], [15, 13, 14, 16, 17, 20]), // WT1+WT2
|
||||
];
|
||||
|
||||
ValveStates[][] tanks = [
|
||||
[new([22], [24, 26, 28]), new([23], [25, 27, 29])],
|
||||
[new([24], [22, 26, 28]), new([25], [23, 27, 29])],
|
||||
[new([26], [22, 24, 28]), new([27], [23, 25, 29])],
|
||||
[new([28, 30], [22, 24, 26, 32, 34]), new([29, 31], [23, 25, 27, 33, 35])],
|
||||
[new([28, 32], [22, 24, 26, 30, 34]), new([29, 33], [23, 25, 27, 31, 35])],
|
||||
[new([28, 34, 37], [22, 24, 26, 30, 32, 39, 41, 43]), new([29, 35, 36], [23, 25, 27, 31, 33, 38, 40, 42])],
|
||||
[new([28, 34, 39], [22, 24, 26, 30, 32, 37, 41, 43]), new([29, 35, 38], [23, 25, 27, 31, 33, 36, 40, 42])],
|
||||
[new([28, 34, 41], [22, 24, 26, 30, 32, 37, 39, 43]), new([29, 35, 40], [23, 25, 27, 31, 33, 36, 38, 42])],
|
||||
[new([28, 34, 43], [22, 24, 26, 30, 32, 37, 39, 41]), new([29, 35, 42], [23, 25, 27, 31, 33, 36, 38, 40])],
|
||||
];
|
||||
|
||||
ValveStates[] mp1_pr1 = [
|
||||
new([1, 6, 51], [3, 4, 5, 50, 52, 53, 55]),
|
||||
new([4, 8, 52], [1, 2, 7, 50, 51, 53, 56]),
|
||||
];
|
||||
ValveStates[] mp1_pr2 = [
|
||||
new([1, 6, 55], [3, 4, 5, 51, 54, 56, 57]),
|
||||
new([4, 8, 56], [1, 2, 7, 52, 54, 55, 57]),
|
||||
];
|
||||
ValveStates mp1_wt_a = new([1, 5], [3, 4, 6]);
|
||||
ValveStates mp1_wt_b = new([4, 7, 9], [1, 2, 8, 10]);
|
||||
ValveStates[] mp1_a = [.. wt_aa.Select(m => mp1_wt_a + m), .. wt_ba.Select(m => mp1_wt_b + m)];
|
||||
ValveStates[] mp1_b = [.. wt_ab.Select(m => mp1_wt_a + m), .. wt_bb.Select(m => mp1_wt_b + m)];
|
||||
ValveStates[][] mp1_t = [.. tanks.Select<ValveStates[], ValveStates[]>(t => [.. mp1_a.Select(m => m + t[0]), .. mp1_b.Select(m => m + t[1])])];
|
||||
|
||||
ValveStates[] mp2_pr1 = [
|
||||
new([2, 8, 52], [3, 4, 7, 50, 51, 53, 56]),
|
||||
new([3, 6, 51], [1, 2, 5, 50, 52, 53, 55]),
|
||||
];
|
||||
ValveStates[] mp2_pr2 = [
|
||||
new([2, 8, 56], [3, 4, 7, 52, 54, 55, 57]),
|
||||
new([3, 6, 55], [2, 1, 5, 51, 54, 56, 57]),
|
||||
];
|
||||
ValveStates mp2_wt_a = new([3, 5], [1, 2, 6]);
|
||||
ValveStates mp2_wt_b = new([2, 7, 9], [3, 4, 8, 10]);
|
||||
ValveStates[] mp2_a = [.. wt_aa.Select(m => mp2_wt_a + m), .. wt_ba.Select(m => mp2_wt_b + m)];
|
||||
ValveStates[] mp2_b = [.. wt_ab.Select(m => mp2_wt_a + m), .. wt_bb.Select(m => mp2_wt_b + m)];
|
||||
ValveStates[][] mp2_t = [.. tanks.Select<ValveStates[], ValveStates[]>(t => [.. mp2_a.Select(m => m + t[0]), .. mp2_b.Select(m => m + t[1])])];
|
||||
|
||||
ValveStates[] p12_pr1 = [new([44, 46, 49, 50], [10, 45, 47, 48, 54, 51, 52, 53])];
|
||||
ValveStates[] p12_pr2 = [new([44, 46, 49, 54], [10, 45, 47, 48, 50, 55, 56, 57])];
|
||||
ValveStates[] p12_b = [new([44, 10], [9, 45, 46])];
|
||||
ValveStates[][] p12_t = [.. tanks.Select<ValveStates[], ValveStates[]>(t => [.. p12_b.Select(m => m + t[1])])];
|
||||
|
||||
ValveStates[] p3_pr1 = [new([45, 46, 49, 50], [10, 44, 47, 48, 51, 52, 53, 54])];
|
||||
ValveStates[] p3_pr2 = [new([45, 46, 49, 54], [10, 44, 47, 48, 50, 55, 56, 57])];
|
||||
ValveStates[] p3_b = [new([45, 10], [9, 44, 46])];
|
||||
ValveStates[][] p3_t = [.. tanks.Select<ValveStates[], ValveStates[]>(t => [.. p3_b.Select(m => m + t[1])])];
|
||||
|
||||
ValveStates[] p4_pr1 = [new([47, 49, 50], [46, 48, 51, 52, 53, 54])];
|
||||
ValveStates[] p4_pr2 = [new([47, 49, 54], [46, 48, 50, 55, 56, 57])];
|
||||
ValveStates[] p4_b = [new([47, 46, 10], [9, 44, 45, 48, 49])];
|
||||
ValveStates[][] p4_t = [.. tanks.Select<ValveStates[], ValveStates[]>(t => [.. p4_b.Select(m => m + t[1])])];
|
||||
|
||||
ValveStates[] p5_pr1 = [new([48, 49, 50], [46, 47, 51, 52, 53, 54])];
|
||||
ValveStates[] p5_pr2 = [new([48, 49, 54], [46, 47, 50, 55, 56, 57])];
|
||||
ValveStates[] p5_b = [new([48, 46, 10], [9, 44, 45, 47, 49])];
|
||||
ValveStates[][] p5_t = [.. tanks.Select<ValveStates[], ValveStates[]>(t => [.. p5_b.Select(m => m + t[1])])];
|
||||
|
||||
ValveStates[] p6_pr1 = [new([53], [50, 51, 52, 57])];
|
||||
ValveStates[] p6_pr2 = [new([57], [53, 54, 55, 56])];
|
||||
|
||||
Paths = (
|
||||
(ValveStateMask.From(mp1_pr1), ValveStateMask.From(mp1_pr2), [.. mp1_t.Select(t => ValveStateMask.From(t))]),
|
||||
(ValveStateMask.From(mp2_pr1), ValveStateMask.From(mp2_pr2), [.. mp2_t.Select(t => ValveStateMask.From(t))]),
|
||||
(ValveStateMask.From(p12_pr1), ValveStateMask.From(p12_pr2), [.. p12_t.Select(t => ValveStateMask.From(t))]),
|
||||
(ValveStateMask.From(p3_pr1), ValveStateMask.From(p3_pr2), [.. p3_t.Select(t => ValveStateMask.From(t))]),
|
||||
(ValveStateMask.From(p4_pr1), ValveStateMask.From(p4_pr2), [.. p4_t.Select(t => ValveStateMask.From(t))]),
|
||||
(ValveStateMask.From(p5_pr1), ValveStateMask.From(p5_pr2), [.. p5_t.Select(t => ValveStateMask.From(t))]),
|
||||
(ValveStateMask.From(p6_pr1), ValveStateMask.From(p6_pr2))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Text;
|
||||
|
||||
namespace PamhagenSysCtrl.Helpers {
|
||||
namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
public class T1 : IDisposable {
|
||||
|
||||
public enum Mode { HALT = 1, RUN = 2, RUN_F = 3, HOLD = 4, ERROR = 6 }
|
||||
@@ -51,7 +51,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
Serial.WriteLine(line.ToString());
|
||||
}
|
||||
|
||||
protected async Task<(string, string)> ReceiveResponse(string? expectedCmd = null) {
|
||||
protected async Task<(string Command, string Data)> ReceiveResponse(string? expectedCmd = null) {
|
||||
var line = Serial.ReadLine();
|
||||
if (line.Length < 8 || !line.StartsWith("(A") || !line.EndsWith(')') || line[^4] != '&') {
|
||||
throw new FormatException("Invalid response from PLC (T1)");
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace PamhagenSysCtrl.Helpers {
|
||||
namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
public enum T1Error {
|
||||
UNKNOWN_ERROR = -1,
|
||||
NO_ERROR = 0,
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace PamhagenSysCtrl.Helpers {
|
||||
namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
public class T1Exception(string msg) : Exception(msg) {
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using PIEHidNetCore;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace PamhagenSysCtrl.Helpers {
|
||||
public class Xbe24Keyboard : IDisposable, PIEDataHandler, PIEErrorHandler {
|
||||
@@ -11,6 +11,21 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
public readonly bool GetKey(int n) => (Rows[n / 6] & (1 << (n % 6))) != 0;
|
||||
}
|
||||
|
||||
public static readonly Color DefaltBacklight = Color.FromArgb(3, 3, 3);
|
||||
public static readonly Color Neutral = Color.FromArgb(4, 4, 4);
|
||||
public static readonly Color Red = Color.FromArgb(255, 0, 0);
|
||||
public static readonly Color Green = Color.FromArgb(0, 255, 0);
|
||||
public static readonly Color Blue = Color.FromArgb(0, 0, 255);
|
||||
public static readonly Color Yellow = Color.FromArgb(255, 255, 0);
|
||||
public static readonly Color Magenta = Color.FromArgb(255, 0, 255);
|
||||
public static readonly Color Cyan = Color.FromArgb(0, 255, 255);
|
||||
public static readonly Color Orange = Color.FromArgb(255, 32, 0);
|
||||
public static readonly Color DarkPurple = Color.FromArgb(128, 0, 128);
|
||||
public static readonly Color Purple = Color.FromArgb(255, 64, 255);
|
||||
public static readonly Color LightRed = Color.FromArgb(32, 4, 4);
|
||||
public static readonly Color LightGreen = Color.FromArgb(4, 32, 4);
|
||||
public static readonly Color LightBlue = Color.FromArgb(4, 4, 32);
|
||||
|
||||
protected readonly PIEDevice XbeDevice;
|
||||
|
||||
private KeyState LastKeyState = new(new byte[4]);
|
||||
@@ -21,6 +36,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
public event EventHandler<int>? KeyDown;
|
||||
public event EventHandler<int>? KeyUp;
|
||||
public event EventHandler<KeyState>? KeysChanged;
|
||||
public event EventHandler<int>? Error;
|
||||
|
||||
public Xbe24Keyboard(int pid = 0x0555) {
|
||||
foreach (var device in PIEDevice.EnumeratePIE()) {
|
||||
@@ -39,9 +55,13 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
throw new IOException($"Unable to SetDataCallback for XBE keyboard: {res}");
|
||||
if ((res = XbeDevice.SetErrorCallback(this)) != 0)
|
||||
throw new IOException($"Unable to SetErrorCallback for XBE keyboard: {res}");
|
||||
|
||||
SetBacklight(DefaltBacklight);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
GC.SuppressFinalize(this);
|
||||
SetBacklight(DefaltBacklight);
|
||||
XbeDevice?.CloseInterface();
|
||||
}
|
||||
|
||||
@@ -57,7 +77,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
public void HandlePIEHidError(PIEDevice sourceDevice, int error) {
|
||||
if (sourceDevice != XbeDevice)
|
||||
return;
|
||||
// TODO
|
||||
Error?.Invoke(this, error);
|
||||
}
|
||||
|
||||
protected void HandleKeyStateChange(KeyState current, KeyState last) {
|
||||
|
||||
@@ -29,14 +29,14 @@ namespace PamhagenSysCtrl {
|
||||
if (App.Plant == null || sender is not Button b) return;
|
||||
var i = int.Parse($"{b.Content}"[1..]);
|
||||
if (i == 58) {
|
||||
if (App.Plant.WantMW1Selected) {
|
||||
if (App.Plant.State.MW1_WantSelected) {
|
||||
App.Plant.SelectMW2();
|
||||
} else {
|
||||
App.Plant.SelectMW1();
|
||||
}
|
||||
} else if (i > 57) {
|
||||
return;
|
||||
} else if (App.Plant.WantValveOpen(i)) {
|
||||
} else if (App.Plant.State.Valve_WantOpen(i)) {
|
||||
App.Plant.CloseV(i);
|
||||
} else {
|
||||
App.Plant.OpenV(i);
|
||||
@@ -60,8 +60,8 @@ namespace PamhagenSysCtrl {
|
||||
if (sender is not PamhagenPlant plant) return;
|
||||
|
||||
for (int i = 1; i <= 58; i++) {
|
||||
var target = plant.WantValveClosed(i);
|
||||
var actual = plant.IsValveClosed(i);
|
||||
var target = plant.State.Valve_WantClosed(i);
|
||||
var actual = plant.State.Valve_IsClosed(i);
|
||||
if (ValvePanel.Children[i - 1] is not Button b)
|
||||
continue;
|
||||
b.BorderBrush = target ? Brushes.DarkRed : Brushes.DarkGreen;
|
||||
@@ -69,98 +69,97 @@ namespace PamhagenSysCtrl {
|
||||
b.Background = actual ? Brushes.MistyRose : Brushes.MintCream;
|
||||
}
|
||||
|
||||
ReblerButton.BorderBrush = plant.IsReblerActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
ReblerButton.Foreground = plant.IsReblerActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
ReblerButton.Background = plant.IsReblerActive ? Brushes.MintCream: Brushes.MistyRose;
|
||||
ReblerButton.BorderBrush = plant.State.Rebler_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
ReblerButton.Foreground = plant.State.Rebler_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
ReblerButton.Background = plant.State.Rebler_IsActive ? Brushes.MintCream: Brushes.MistyRose;
|
||||
|
||||
TroughAugerButton.BorderBrush = plant.IsTroughAugerActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
TroughAugerButton.Foreground = plant.IsTroughAugerActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
TroughAugerButton.Background = plant.IsTroughAugerActive ? Brushes.MintCream : Brushes.MistyRose;
|
||||
TroughAugerButton.BorderBrush = plant.State.TroughAuger_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
TroughAugerButton.Foreground = plant.State.TroughAuger_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
TroughAugerButton.Background = plant.State.TroughAuger_IsActive ? Brushes.MintCream : Brushes.MistyRose;
|
||||
|
||||
StirrerMW1Button.BorderBrush = plant.IsStirrerMW1Active ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
StirrerMW1Button.Foreground = plant.IsStirrerMW1Active ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
StirrerMW1Button.Background = plant.IsStirrerMW1Active ? Brushes.MintCream : Brushes.MistyRose;
|
||||
StirrerMW1Button.BorderBrush = plant.State.MW1_Stirrer_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
StirrerMW1Button.Foreground = plant.State.MW1_Stirrer_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
StirrerMW1Button.Background = plant.State.MW1_Stirrer_IsActive ? Brushes.MintCream : Brushes.MistyRose;
|
||||
|
||||
StirrerMW2Button.BorderBrush = plant.IsStirrerMW2Active ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
StirrerMW2Button.Foreground = plant.IsStirrerMW2Active ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
StirrerMW2Button.Background = plant.IsStirrerMW2Active ? Brushes.MintCream : Brushes.MistyRose;
|
||||
StirrerMW2Button.BorderBrush = plant.State.MW2_Stirrer_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
StirrerMW2Button.Foreground = plant.State.MW2_Stirrer_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
StirrerMW2Button.Background = plant.State.MW2_Stirrer_IsActive ? Brushes.MintCream : Brushes.MistyRose;
|
||||
|
||||
Auger1Button.BorderBrush = plant.IsAuger1Active ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger1Button.Foreground = plant.IsAuger1Active ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger1Button.Background = plant.IsAuger1Active ? Brushes.MintCream : Brushes.MistyRose;
|
||||
Auger1Button.BorderBrush = plant.State.Auger1_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger1Button.Foreground = plant.State.Auger1_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger1Button.Background = plant.State.Auger1_IsActive ? Brushes.MintCream : Brushes.MistyRose;
|
||||
|
||||
Auger2Button.BorderBrush = plant.IsAuger2Active ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger2Button.Foreground = plant.IsAuger2Active ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger2Button.Background = plant.IsAuger2Active ? Brushes.MintCream : Brushes.MistyRose;
|
||||
Auger2Button.BorderBrush = plant.State.Auger2_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger2Button.Foreground = plant.State.Auger2_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger2Button.Background = plant.State.Auger2_IsActive ? Brushes.MintCream : Brushes.MistyRose;
|
||||
|
||||
Auger3Button.BorderBrush = plant.IsAuger3Active ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger3Button.Foreground = plant.IsAuger3Active ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger3Button.Background = plant.IsAuger3Active ? Brushes.MintCream : Brushes.MistyRose;
|
||||
Auger3Button.BorderBrush = plant.State.Auger3_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger3Button.Foreground = plant.State.Auger3_IsActive ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
Auger3Button.Background = plant.State.Auger3_IsActive ? Brushes.MintCream : Brushes.MistyRose;
|
||||
|
||||
MP1BackwardButton.BorderBrush = plant.MP1 == MotorState.Backward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP1BackwardButton.Foreground = plant.MP1 == MotorState.Backward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP1BackwardButton.Background = plant.MP1 == MotorState.Backward ? Brushes.MintCream : Brushes.WhiteSmoke;
|
||||
MP1HaltButton.BorderBrush = plant.MP1 == MotorState.Halt ? Brushes.DarkRed : Brushes.SlateGray;
|
||||
MP1HaltButton.Foreground = plant.MP1 == MotorState.Halt ? Brushes.DarkRed : Brushes.SlateGray;
|
||||
MP1HaltButton.Background = plant.MP1 == MotorState.Halt ? Brushes.MistyRose : Brushes.WhiteSmoke;
|
||||
MP1ForwardButton.BorderBrush = plant.MP1 == MotorState.Forward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP1ForwardButton.Foreground = plant.MP1 == MotorState.Forward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP1ForwardButton.Background = plant.MP1 == MotorState.Forward ? Brushes.MintCream: Brushes.WhiteSmoke;
|
||||
MP1BackwardButton.BorderBrush = plant.State.MP1_State == MotorState.Backward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP1BackwardButton.Foreground = plant.State.MP1_State == MotorState.Backward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP1BackwardButton.Background = plant.State.MP1_State == MotorState.Backward ? Brushes.MintCream : Brushes.WhiteSmoke;
|
||||
MP1HaltButton.BorderBrush = plant.State.MP1_State == MotorState.Halt ? Brushes.DarkRed : Brushes.SlateGray;
|
||||
MP1HaltButton.Foreground = plant.State.MP1_State == MotorState.Halt ? Brushes.DarkRed : Brushes.SlateGray;
|
||||
MP1HaltButton.Background = plant.State.MP1_State == MotorState.Halt ? Brushes.MistyRose : Brushes.WhiteSmoke;
|
||||
MP1ForwardButton.BorderBrush = plant.State.MP1_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP1ForwardButton.Foreground = plant.State.MP1_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP1ForwardButton.Background = plant.State.MP1_State == MotorState.Forward ? Brushes.MintCream: Brushes.WhiteSmoke;
|
||||
|
||||
MP2BackwardButton.BorderBrush = plant.MP2 == MotorState.Backward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP2BackwardButton.Foreground = plant.MP2 == MotorState.Backward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP2BackwardButton.Background = plant.MP2 == MotorState.Backward ? Brushes.MintCream : Brushes.WhiteSmoke;
|
||||
MP2HaltButton.BorderBrush = plant.MP2 == MotorState.Halt ? Brushes.DarkRed : Brushes.SlateGray;
|
||||
MP2HaltButton.Foreground = plant.MP2 == MotorState.Halt ? Brushes.DarkRed : Brushes.SlateGray;
|
||||
MP2HaltButton.Background = plant.MP2 == MotorState.Halt ? Brushes.MistyRose : Brushes.WhiteSmoke;
|
||||
MP2ForwardButton.BorderBrush = plant.MP2 == MotorState.Forward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP2ForwardButton.Foreground = plant.MP2 == MotorState.Forward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP2ForwardButton.Background = plant.MP2 == MotorState.Forward ? Brushes.MintCream : Brushes.WhiteSmoke;
|
||||
MP2BackwardButton.BorderBrush = plant.State.MP2_State == MotorState.Backward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP2BackwardButton.Foreground = plant.State.MP2_State == MotorState.Backward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP2BackwardButton.Background = plant.State.MP2_State == MotorState.Backward ? Brushes.MintCream : Brushes.WhiteSmoke;
|
||||
MP2HaltButton.BorderBrush = plant.State.MP2_State == MotorState.Halt ? Brushes.DarkRed : Brushes.SlateGray;
|
||||
MP2HaltButton.Foreground = plant.State.MP2_State == MotorState.Halt ? Brushes.DarkRed : Brushes.SlateGray;
|
||||
MP2HaltButton.Background = plant.State.MP2_State == MotorState.Halt ? Brushes.MistyRose : Brushes.WhiteSmoke;
|
||||
MP2ForwardButton.BorderBrush = plant.State.MP2_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP2ForwardButton.Foreground = plant.State.MP2_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.SlateGray;
|
||||
MP2ForwardButton.Background = plant.State.MP2_State == MotorState.Forward ? Brushes.MintCream : Brushes.WhiteSmoke;
|
||||
|
||||
P12Button.BorderBrush = plant.P12 == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P12Button.Foreground = plant.P12 == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P12Button.Background = plant.P12 == MotorState.Forward ? Brushes.MintCream : Brushes.MistyRose;
|
||||
P12Button.BorderBrush = plant.State.P12_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P12Button.Foreground = plant.State.P12_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P12Button.Background = plant.State.P12_State == MotorState.Forward ? Brushes.MintCream : Brushes.MistyRose;
|
||||
|
||||
P3Button.BorderBrush = plant.P3 == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P3Button.Foreground = plant.P3 == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P3Button.Background = plant.P3 == MotorState.Forward ? Brushes.MintCream : Brushes.MistyRose;
|
||||
P3Button.BorderBrush = plant.State.P3_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P3Button.Foreground = plant.State.P3_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P3Button.Background = plant.State.P3_State == MotorState.Forward ? Brushes.MintCream : Brushes.MistyRose;
|
||||
|
||||
P4Button.BorderBrush = plant.P4 == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P4Button.Foreground = plant.P4 == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P4Button.Background = plant.P4 == MotorState.Forward ? Brushes.MintCream : Brushes.MistyRose;
|
||||
P4Button.BorderBrush = plant.State.P4_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P4Button.Foreground = plant.State.P4_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P4Button.Background = plant.State.P4_State == MotorState.Forward ? Brushes.MintCream : Brushes.MistyRose;
|
||||
|
||||
P5Button.BorderBrush = plant.P5 == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P5Button.Foreground = plant.P5 == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P5Button.Background = plant.P5 == MotorState.Forward ? Brushes.MintCream : Brushes.MistyRose;
|
||||
P5Button.BorderBrush = plant.State.P5_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P5Button.Foreground = plant.State.P5_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P5Button.Background = plant.State.P5_State == MotorState.Forward ? Brushes.MintCream : Brushes.MistyRose;
|
||||
|
||||
P6Button.BorderBrush = plant.P6 == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P6Button.Foreground = plant.P6 == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P6Button.Background = plant.P6 == MotorState.Forward ? Brushes.MintCream : Brushes.MistyRose;
|
||||
P6Button.BorderBrush = plant.State.P6_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P6Button.Foreground = plant.State.P6_State == MotorState.Forward ? Brushes.DarkGreen : Brushes.DarkRed;
|
||||
P6Button.Background = plant.State.P6_State == MotorState.Forward ? Brushes.MintCream : Brushes.MistyRose;
|
||||
|
||||
Status.Text = $"""
|
||||
Gradation °Oe: {plant.GradationOe:N2}
|
||||
Presse Querschnecke: {plant.PresseQuerSchnecke}
|
||||
Presse Querschnecke: {plant.State.PressCrossAuger_State}
|
||||
Füllstände:
|
||||
Maischewanne 1: {plant.FillLevelMW1} (ausgewählt: {plant.WantMW1Selected}, Status: {plant.IsMW1Selected})
|
||||
Maischewanne 2: {plant.FillLevelMW2} (ausgewählt: {plant.WantMW2Selected}, Status: {plant.IsMW2Selected})
|
||||
Presse 1: {plant.Press1HasClearance}
|
||||
Presse 2: {plant.Press2HasClearance}
|
||||
Tank 1: {plant.FillLevelT1}
|
||||
Tank 2: {plant.FillLevelT2}
|
||||
Tank 3: {plant.FillLevelT3}
|
||||
Tank 4: {plant.FillLevelT4}
|
||||
Tank 5: {plant.FillLevelT5}
|
||||
Tank 6: {plant.FillLevelT6}
|
||||
Tank 7: {plant.FillLevelT7}
|
||||
Tank 8: {plant.FillLevelT8}
|
||||
Tank 9: {plant.FillLevelT9}
|
||||
Maischewanne 1: {plant.State.MW2_FillLevel} (ausgewählt: {plant.State.MW1_WantSelected}, Status: {plant.State.MW1_IsSelected})
|
||||
Maischewanne 2: {plant.State.MW2_FillLevel} (ausgewählt: {plant.State.MW2_WantSelected}, Status: {plant.State.MW2_IsSelected})
|
||||
Presse 1: {plant.State.Press1_HasClearance}
|
||||
Presse 2: {plant.State.Press2_HasClearance}
|
||||
Tank 1: {plant.State.T1_FillLevel}
|
||||
Tank 2: {plant.State.T2_FillLevel}
|
||||
Tank 3: {plant.State.T3_FillLevel}
|
||||
Tank 4: {plant.State.T4_FillLevel}
|
||||
Tank 5: {plant.State.T5_FillLevel}
|
||||
Tank 6: {plant.State.T6_FillLevel}
|
||||
Tank 7: {plant.State.T7_FillLevel}
|
||||
Tank 8: {plant.State.T8_FillLevel}
|
||||
Tank 9: {plant.State.T9_FillLevel}
|
||||
""";
|
||||
}
|
||||
|
||||
private void TroughAugerButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.IsTroughAugerActive) {
|
||||
if (App.Plant.State.TroughAuger_IsActive) {
|
||||
App.Plant.StopTroughAuger();
|
||||
} else {
|
||||
App.Plant.StartTroughAuger();
|
||||
@@ -173,7 +172,7 @@ namespace PamhagenSysCtrl {
|
||||
private void ReblerButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.IsReblerActive) {
|
||||
if (App.Plant.State.Rebler_IsActive) {
|
||||
App.Plant.StopRebler();
|
||||
} else {
|
||||
App.Plant.StartRebler();
|
||||
@@ -186,7 +185,7 @@ namespace PamhagenSysCtrl {
|
||||
private void StirrerMW1Button_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.IsStirrerMW1Active) {
|
||||
if (App.Plant.State.MW1_Stirrer_IsActive) {
|
||||
App.Plant.StopStirrerMW1();
|
||||
} else {
|
||||
App.Plant.StartStirrerMW1();
|
||||
@@ -199,7 +198,7 @@ namespace PamhagenSysCtrl {
|
||||
private void StirrerMW2Button_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.IsStirrerMW2Active) {
|
||||
if (App.Plant.State.MW2_Stirrer_IsActive) {
|
||||
App.Plant.StopStirrerMW2();
|
||||
} else {
|
||||
App.Plant.StartStirrerMW2();
|
||||
@@ -212,7 +211,7 @@ namespace PamhagenSysCtrl {
|
||||
private void Auger1Button_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.IsAuger1Active) {
|
||||
if (App.Plant.State.Auger1_IsActive) {
|
||||
App.Plant.StopAuger1();
|
||||
} else {
|
||||
App.Plant.StartAuger1();
|
||||
@@ -225,7 +224,7 @@ namespace PamhagenSysCtrl {
|
||||
private void Auger2Button_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.IsAuger2Active) {
|
||||
if (App.Plant.State.Auger2_IsActive) {
|
||||
App.Plant.StopAuger2();
|
||||
} else {
|
||||
App.Plant.StartAuger2();
|
||||
@@ -238,7 +237,7 @@ namespace PamhagenSysCtrl {
|
||||
private void Auger3Button_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.IsAuger3Active) {
|
||||
if (App.Plant.State.Auger3_IsActive) {
|
||||
App.Plant.StopAuger3();
|
||||
} else {
|
||||
App.Plant.StartAuger3();
|
||||
@@ -306,10 +305,10 @@ namespace PamhagenSysCtrl {
|
||||
private void P12Button_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.P12 == MotorState.Forward) {
|
||||
App.Plant.StopP12();
|
||||
if (App.Plant.State.P12_IsActive) {
|
||||
App.Plant.DisableP12();
|
||||
} else {
|
||||
App.Plant.StartP12();
|
||||
App.Plant.EnableP12();
|
||||
}
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
@@ -319,10 +318,10 @@ namespace PamhagenSysCtrl {
|
||||
private void P3Button_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.P3 == MotorState.Forward) {
|
||||
App.Plant.StopP3();
|
||||
if (App.Plant.State.P3_IsActive) {
|
||||
App.Plant.DisableP3();
|
||||
} else {
|
||||
App.Plant.StartP3();
|
||||
App.Plant.EnableP3();
|
||||
}
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
@@ -332,10 +331,10 @@ namespace PamhagenSysCtrl {
|
||||
private void P4Button_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.P4 == MotorState.Forward) {
|
||||
App.Plant.StopP4();
|
||||
if (App.Plant.State.P4_IsActive) {
|
||||
App.Plant.DisableP4();
|
||||
} else {
|
||||
App.Plant.StartP4();
|
||||
App.Plant.EnableP4();
|
||||
}
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
@@ -345,10 +344,10 @@ namespace PamhagenSysCtrl {
|
||||
private void P5Button_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.P5 == MotorState.Forward) {
|
||||
App.Plant.StopP5();
|
||||
if (App.Plant.State.P5_IsActive) {
|
||||
App.Plant.DisableP5();
|
||||
} else {
|
||||
App.Plant.StartP5();
|
||||
App.Plant.EnableP5();
|
||||
}
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
@@ -358,10 +357,10 @@ namespace PamhagenSysCtrl {
|
||||
private void P6Button_Click(object? sender, RoutedEventArgs? evt) {
|
||||
if (App.Plant == null) return;
|
||||
try {
|
||||
if (App.Plant.P6 == MotorState.Forward) {
|
||||
App.Plant.StopP6();
|
||||
if (App.Plant.State.P6_IsActive) {
|
||||
App.Plant.DisableP6();
|
||||
} else {
|
||||
App.Plant.StartP6();
|
||||
App.Plant.EnableP6();
|
||||
}
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using PamhagenSysCtrl.Helpers;
|
||||
using PamhagenSysCtrl.Helpers.Pipeline;
|
||||
using PamhagenSysCtrl.Helpers.Plc;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -26,7 +27,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
public Path? HoveringPath {
|
||||
get {
|
||||
foreach (var b in FastSelectPaths.Where(b => b.Key.IsMouseOver)) {
|
||||
if (Graph.SelectedPaths.Any(p => p.Start == b.Value.Source && p.Hops.Last().Node == b.Value.Sink))
|
||||
if (Graph.SelectedPaths.Any(p => p.Matches(b.Value.Source, b.Value.Sink)))
|
||||
continue;
|
||||
return Graph.GetFreePath([b.Value.Source, b.Value.Sink], true);
|
||||
}
|
||||
@@ -67,8 +68,10 @@ namespace PamhagenSysCtrl.Windows {
|
||||
[FastSelectButton_MW1_Tank5] = (Graph.MW1, Graph.MP1, Graph.Tank5),
|
||||
[FastSelectButton_MW2_Tank5] = (Graph.MW2, Graph.MP2, Graph.Tank5),
|
||||
};
|
||||
App.Plant?.Update += OnUpdate;
|
||||
App.Plant?.InitializePaths();
|
||||
if (App.Plant != null) {
|
||||
Status_Connection.Text = $"Nein ({App.Plant.PlcComPort})";
|
||||
App.Plant.Update += OnUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClosed(object sender, EventArgs evt) {
|
||||
@@ -213,7 +216,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
private void FastSelectButton_Click(object sender, RoutedEventArgs? evt) {
|
||||
if (sender is not Button b || !FastSelectPaths.TryGetValue(b, out var val))
|
||||
return;
|
||||
App.Plant?.FastSelect(val.Source, val.Sink);
|
||||
App.Plant?.FastSelect(val.Source, null, val.Sink);
|
||||
OnUpdate(null, null);
|
||||
_lastSource = null;
|
||||
}
|
||||
@@ -351,7 +354,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
} else {
|
||||
if (_lastSource == null && Graph.SelectedPaths.Any(p => p.Start == c)) {
|
||||
var path = Graph.SelectedPaths.First(p => p.Start == c);
|
||||
if (!path.Hops.Any(h => (h.Node as Pump)?.IsActive ?? false)) {
|
||||
if (!path.HasActivePump) {
|
||||
Graph.RemovePath(path);
|
||||
}
|
||||
} else if (_lastSource != null && c is ISink sink) {
|
||||
@@ -385,7 +388,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
App.Plant?.StartRebler();
|
||||
}
|
||||
} else if (c is Switcher switcher) {
|
||||
if (App.Plant?.WantMW1Selected ?? false) {
|
||||
if (App.Plant?.State.MW1_WantSelected ?? false) {
|
||||
App.Plant?.SelectMW2();
|
||||
} else {
|
||||
App.Plant?.SelectMW1();
|
||||
@@ -425,33 +428,33 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
} else if (pump == Graph.P12) {
|
||||
if (pump.IsActive) {
|
||||
App.Plant?.StopP12();
|
||||
App.Plant?.DisableP12();
|
||||
} else {
|
||||
App.Plant?.StartP12();
|
||||
App.Plant?.EnableP12();
|
||||
}
|
||||
} else if (pump == Graph.P3) {
|
||||
if (pump.IsActive) {
|
||||
App.Plant?.StopP3();
|
||||
App.Plant?.DisableP3();
|
||||
} else {
|
||||
App.Plant?.StartP3();
|
||||
App.Plant?.EnableP3();
|
||||
}
|
||||
} else if (pump == Graph.P4) {
|
||||
if (pump.IsActive) {
|
||||
App.Plant?.StopP4();
|
||||
App.Plant?.DisableP4();
|
||||
} else {
|
||||
App.Plant?.StartP4();
|
||||
App.Plant?.EnableP4();
|
||||
}
|
||||
} else if (pump == Graph.P5) {
|
||||
if (pump.IsActive) {
|
||||
App.Plant?.StopP5();
|
||||
App.Plant?.DisableP5();
|
||||
} else {
|
||||
App.Plant?.StartP5();
|
||||
App.Plant?.EnableP5();
|
||||
}
|
||||
} else if (pump == Graph.P6) {
|
||||
if (pump.IsActive) {
|
||||
App.Plant?.StopP6();
|
||||
App.Plant?.DisableP6();
|
||||
} else {
|
||||
App.Plant?.StartP6();
|
||||
App.Plant?.EnableP6();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -482,7 +485,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
private void UpdateFastSelectPathButton(IEnumerable<Path> paths, Path? hoverPathDeactivate, Button b) {
|
||||
var e = FastSelectPaths[b];
|
||||
SetFastSelectButton(b,
|
||||
paths.Any(p => p.Start == e.Source && p.Hops.Last().Node == e.Sink) ? (hoverPathDeactivate?.Start == e.Source && hoverPathDeactivate?.Hops.Last().Node == e.Sink) ? 2 : 1 : 0,
|
||||
paths.Any(p => p.Matches(e.Source, e.Sink)) ? (hoverPathDeactivate?.Matches(e.Source, e.Sink) ?? false) ? 2 : 1 : 0,
|
||||
e.Pump.IsActive || Graph.GetFreePath([e.Source, e.Sink], overrideStart: true) == null);
|
||||
}
|
||||
|
||||
@@ -497,21 +500,21 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
SetFastSelectButton(FastSelectButton_EntryTrough_Start, App.Plant?.IsTroughAugerActive ?? false ? 1 : 0, !(App.Plant?.TroughAugerHasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_EntryTrough_Stop, App.Plant?.IsTroughAugerActive ?? false ? 0 : 2);
|
||||
SetFastSelectButton(FastSelectButton_MW1, App.Plant?.IsMW1Selected ?? false ? 1 : 0);
|
||||
SetFastSelectButton(FastSelectButton_MW2, App.Plant?.IsMW2Selected ?? false ? 1 : 0);
|
||||
SetFastSelectButton(FastSelectButton_MP1_Forward, App.Plant?.MP1 == MotorState.Forward ? 1 : 0, !(App.Plant?.MP1HasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_MP1_Stop, App.Plant?.MP1 == MotorState.Halt ? 2 : 0);
|
||||
SetFastSelectButton(FastSelectButton_MP2_Forward, App.Plant?.MP2 == MotorState.Forward ? 1 : 0, !(App.Plant?.MP2HasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_MP2_Stop, App.Plant?.MP2 == MotorState.Halt ? 2 : 0);
|
||||
SetFastSelectButton(FastSelectButton_EntryTrough_Start, App.Plant?.State.TroughAuger_IsActive ?? false ? 1 : 0, !(App.Plant?.State.TroughAuger_HasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_EntryTrough_Stop, App.Plant?.State.TroughAuger_IsActive ?? false ? 0 : 2);
|
||||
SetFastSelectButton(FastSelectButton_MW1, App.Plant?.State.MW1_IsSelected?? false ? 1 : 0);
|
||||
SetFastSelectButton(FastSelectButton_MW2, App.Plant?.State.MW2_IsSelected ?? false ? 1 : 0);
|
||||
SetFastSelectButton(FastSelectButton_MP1_Forward, App.Plant?.State.MP1_State == MotorState.Forward ? 1 : 0, !(App.Plant?.State.MP1_HasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_MP1_Stop, App.Plant?.State.MP1_State == MotorState.Halt ? 2 : 0);
|
||||
SetFastSelectButton(FastSelectButton_MP2_Forward, App.Plant?.State.MP2_State == MotorState.Forward ? 1 : 0, !(App.Plant?.State.MP2_HasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_MP2_Stop, App.Plant?.State.MP2_State == MotorState.Halt ? 2 : 0);
|
||||
|
||||
_hover = Graph.GetHover(pos.X, pos.Y, RoundedScale);
|
||||
var hoverButtons = FastSelectPaths.Where(b => b.Key.IsMouseOver).ToDictionary();
|
||||
Path? hoverPathDeactivate = null;
|
||||
if (App.Plant?.ManualControlMode ?? false) {
|
||||
foreach (var src in Graph.Nodes.Where(n => n is Pump)) {
|
||||
Graph.ColorPipesByValves(src, PamhagenBrushes.Green, (src as Pump)?.State ?? default, PamhagenBrushes.DimOrange);
|
||||
PamhagenGraph.ColorPipesByValves(src, PamhagenBrushes.Green, (src as Pump)?.State ?? default, PamhagenBrushes.DimOrange);
|
||||
}
|
||||
MP1_Target.Text = "Vor";
|
||||
MP2_Target.Text = "Vor";
|
||||
@@ -519,27 +522,21 @@ namespace PamhagenSysCtrl.Windows {
|
||||
MP2_Target.FontSize = 16;
|
||||
} else {
|
||||
foreach (var p in Graph.SelectedPaths) {
|
||||
Graph.ColorPipesAdjacientToPath(p, PamhagenBrushes.Green, p.Hops.Select(h => (h.Node as Pump)?.State ?? default).FirstOrDefault(n => n != MotorState.Halt), PamhagenBrushes.DimOrange);
|
||||
PamhagenGraph.ColorPipesAdjacientToPath(p, PamhagenBrushes.Green, p.Pumps.Select(p => p.State).FirstOrDefault(n => n != MotorState.Halt), PamhagenBrushes.DimOrange);
|
||||
}
|
||||
if (_lastSource == null && _hover.Count > 0 && Graph.SelectedPaths.Select(p => (Path?)p).FirstOrDefault(p => p?.Start == _hover.First()) is Path path1) {
|
||||
var pumpActive = path1.Hops.Any(h => (h.Node as Pump)?.IsActive ?? false);
|
||||
if (pumpActive) {
|
||||
foreach (var pump in path1.Hops.Select(h => h.Node as Pump).Where(p => p != null)) {
|
||||
pump?.Highlight = PamhagenBrushes.Red;
|
||||
}
|
||||
if (path1.HasActivePump) {
|
||||
foreach (var p in path1.Pumps) p.Highlight = PamhagenBrushes.Red;
|
||||
} else {
|
||||
hoverPathDeactivate = path1;
|
||||
Graph.ColorPipesAdjacientToPath(path1, PamhagenBrushes.Red, default, null);
|
||||
PamhagenGraph.ColorPipesAdjacientToPath(path1, PamhagenBrushes.Red, default, null);
|
||||
}
|
||||
} else if (hoverButtons.Count != 0 && Graph.SelectedPaths.Select(p => (Path?)p).FirstOrDefault(p => p?.Start == hoverButtons.First().Value.Source) is Path path2) {
|
||||
var pumpActive = path2.Hops.Any(h => (h.Node as Pump)?.IsActive ?? false);
|
||||
if (pumpActive) {
|
||||
foreach (var pump in path2.Hops.Select(h => h.Node as Pump).Where(p => p != null)) {
|
||||
pump?.Highlight = PamhagenBrushes.Red;
|
||||
}
|
||||
if (path2.HasActivePump) {
|
||||
foreach (var p in path2.Pumps) p.Highlight = PamhagenBrushes.Red;
|
||||
} else {
|
||||
hoverPathDeactivate = path2;
|
||||
Graph.ColorPipesAdjacientToPath(path2, PamhagenBrushes.Red, default, null);
|
||||
PamhagenGraph.ColorPipesAdjacientToPath(path2, PamhagenBrushes.Red, default, null);
|
||||
}
|
||||
}
|
||||
if (_lastSource != null) {
|
||||
@@ -548,7 +545,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
}
|
||||
if (HoveringPath is Path hoveringPath) {
|
||||
Graph.ColorPipesAdjacientToPath(hoveringPath, PamhagenBrushes.Green, default, PamhagenBrushes.DimOrange);
|
||||
PamhagenGraph.ColorPipesAdjacientToPath(hoveringPath, PamhagenBrushes.Green, default, PamhagenBrushes.DimOrange);
|
||||
}
|
||||
|
||||
if (Graph.SelectedPaths.Select(p => (Path?)p).FirstOrDefault(p => p?.Start == Graph.MW1) is Path pmw1) {
|
||||
@@ -583,39 +580,19 @@ namespace PamhagenSysCtrl.Windows {
|
||||
|
||||
public void OnUpdate(object? sender, PlantEventArgs? evt) {
|
||||
if (App.Plant is PamhagenPlant p) {
|
||||
Status_Connection.Text = $"Ja ({p.PlcPortName}" + (p.LastRttNs != null ? $", {p.LastRttNs / 1000000.0:N0} ms" : "") + ")";
|
||||
Status_Plc.Text = $"{p.LastPlcStatus?.Mode} ({p.LastPlcStatus?.Flags:X3}) / {p.LastPlcError?.GetName()} ({(int?)p.LastPlcError:0000})";
|
||||
Status_CompressedAir.Text = Enumerable.Range(1, 57).Any(p.IsValveClosed) ? "Ein" : Enumerable.Range(1, 57).Any(p.WantValveClosed) ? "Aus" : "?";
|
||||
Status_ValvesOpen.Text = Enumerable.Range(1, 57).Count(p.IsValveOpen) + " / " + Enumerable.Range(1, 57).Count(p.WantValveOpen) + " / 57";
|
||||
if (p.IsPlcConnected) {
|
||||
Status_Connection.Text = $"Ja ({p.PlcComPort}" + (p.LastRttNs != null ? $", {p.LastRttNs / 1000000.0:N0} ms" : "") + ")";
|
||||
Status_Plc.Text = $"{p.LastPlcStatus?.Mode} ({p.LastPlcStatus?.Flags:X3}) / {p.LastPlcError?.GetName()} ({(int?)p.LastPlcError:0000})";
|
||||
Status_CompressedAir.Text = Enumerable.Range(1, 57).Any(p.State.Valve_IsClosed) ? "Ein" : Enumerable.Range(1, 57).Any(p.State.Valve_WantClosed) ? "Aus" : "?";
|
||||
Status_ValvesOpen.Text = Enumerable.Range(1, 57).Count(p.State.Valve_IsOpen) + " / " + Enumerable.Range(1, 57).Count(p.State.Valve_WantOpen) + " / 57";
|
||||
} else {
|
||||
Status_Connection.Text = p.PlcConnectionError is string err ? $"Nein ({p.PlcComPort}, {err})" : $"Nein ({p.PlcComPort})";
|
||||
Status_Plc.Text = "-";
|
||||
Status_CompressedAir.Text = "-";
|
||||
Status_ValvesOpen.Text = "-";
|
||||
}
|
||||
}
|
||||
UpdateScheme(Mouse.GetPosition(SchemeCanvas), Mouse.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
public void InitializePaths() {
|
||||
var add = ReconstructSelectedPaths().ToList();
|
||||
var remove = Graph.SelectedPaths.ToList();
|
||||
foreach (var p in remove) Graph.RemovePath(p);
|
||||
for (int i = 1; i <= 57; i++) {
|
||||
App.Plant?.CloseV(i);
|
||||
}
|
||||
foreach (var p in add) {
|
||||
if (p.Hops.Any(h => h.Node is ControlledValve v && v.IsLocked)) continue;
|
||||
Graph.AddPath(p);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Path> ReconstructSelectedPaths() {
|
||||
if (App.Plant is not PamhagenPlant p) yield break;
|
||||
var sources = Graph.Nodes.Where(n => n is ISource).ToList();
|
||||
var sinks = Graph.Nodes.Where(n => n is ISink).ToList();
|
||||
foreach (var src in sources) {
|
||||
var paths = new List<Path>();
|
||||
foreach (var sink in sinks) {
|
||||
paths.AddRange(Graph.GetPaths(src, sink, null, (n) => n is not ISink && (n is not ControlledValve v || p.WantValveOpen(v.Nr))));
|
||||
}
|
||||
if (paths.Count == 1)
|
||||
yield return paths.First();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user