Cleanup and Enhancement

This commit is contained in:
2026-07-10 12:01:21 +02:00
parent fb35ddb389
commit ac2eafc8c6
4 changed files with 21 additions and 11 deletions
+4 -5
View File
@@ -68,7 +68,6 @@ namespace PamhagenSysCtrl.Helpers {
public void Dispose() {
IsRunning = false;
BackgroundThread?.Interrupt();
BackgroundThread?.Join();
Plc?.Dispose();
GC.SuppressFinalize(this);
@@ -83,8 +82,6 @@ namespace PamhagenSysCtrl.Helpers {
}
Sensors = await Plc.ReadInputs();
RaiseUpdateEvent(EventArgs.Empty);
} catch (ThreadInterruptedException) {
// ignore
} catch (Exception exc) {
var str = "Bei der SPS ist ein Fehler aufgetreten:\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
@@ -93,12 +90,14 @@ namespace PamhagenSysCtrl.Helpers {
Plc?.Dispose();
Plc = null;
IsRunning = false;
} else {
await Task.Delay(1000);
}
}
}
try {
if (Plc != null)
await Plc.WriteOutputs(new());
await Plc.WriteOutputs(new() { Valves = Actuators.Valves });
} catch (Exception exc) {
var str = "Beim Schließen der Verbindung zur SPS ist ein Fehler aufgetreten:\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
@@ -150,7 +149,7 @@ namespace PamhagenSysCtrl.Helpers {
public void CloseV(int n) => SetV(n, false);
protected void SetV(int n, bool val) {
if (n < 1 || n > 60) throw new ArgumentException("Invalid value for n: 1 <= #V <= 60");
if (n < 1 || n > 57) throw new ArgumentException("Invalid value for n: 1 <= #V <= 57");
Actuators.SetV(n, val);
}