Cleanup and Enhancement
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user