mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 11:11:23 +00:00
Added auto register reset to default typed value on disconnect
This commit is contained in:
@@ -19,11 +19,17 @@ namespace MewtocolNet {
|
||||
/// </summary>
|
||||
public bool PollingPaused => pollerIsPaused;
|
||||
|
||||
/// <summary>
|
||||
/// True if the poller is actvice (can be paused)
|
||||
/// </summary>
|
||||
public bool PollerActive => !pollerTaskStopped;
|
||||
|
||||
internal event Action PolledCycle;
|
||||
|
||||
internal volatile bool pollerTaskRunning;
|
||||
internal volatile bool pollerTaskStopped;
|
||||
internal volatile bool pollerIsPaused;
|
||||
internal volatile bool pollerFirstCycle = false;
|
||||
|
||||
internal bool usePoller = false;
|
||||
|
||||
@@ -37,6 +43,8 @@ namespace MewtocolNet {
|
||||
pollerTaskRunning = false;
|
||||
pollerTaskStopped = true;
|
||||
|
||||
ClearRegisterVals();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -80,6 +88,8 @@ namespace MewtocolNet {
|
||||
if (pollerTaskRunning)
|
||||
return;
|
||||
|
||||
pollerFirstCycle = true;
|
||||
|
||||
Task.Factory.StartNew(async () => {
|
||||
|
||||
Logger.Log("Poller is attaching", LogLevel.Info, this);
|
||||
@@ -167,6 +177,7 @@ namespace MewtocolNet {
|
||||
}
|
||||
|
||||
iteration++;
|
||||
pollerFirstCycle = false;
|
||||
|
||||
await Task.Delay(pollerDelayMs);
|
||||
|
||||
|
||||
@@ -395,6 +395,17 @@ namespace MewtocolNet {
|
||||
|
||||
}
|
||||
|
||||
private void ClearRegisterVals () {
|
||||
|
||||
for (int i = 0; i < Registers.Count; i++) {
|
||||
|
||||
var reg = Registers[i];
|
||||
reg.ClearValue();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Register Collection
|
||||
|
||||
@@ -94,6 +94,38 @@ namespace MewtocolNet.Registers {
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));
|
||||
}
|
||||
|
||||
internal void ClearValue () {
|
||||
|
||||
if (enumType != null && this is NRegister<int> intEnumReg) {
|
||||
intEnumReg.SetValueFromPLC((int)0);
|
||||
}
|
||||
if (this is NRegister<short> shortReg) {
|
||||
shortReg.SetValueFromPLC((short)0);
|
||||
}
|
||||
if (this is NRegister<ushort> ushortReg) {
|
||||
ushortReg.SetValueFromPLC((ushort)0);
|
||||
}
|
||||
if (this is NRegister<int> intReg) {
|
||||
intReg.SetValueFromPLC((int)0);
|
||||
}
|
||||
if (this is NRegister<uint> uintReg) {
|
||||
uintReg.SetValueFromPLC((uint)0);
|
||||
}
|
||||
if (this is NRegister<float> floatReg) {
|
||||
floatReg.SetValueFromPLC((float)0);
|
||||
}
|
||||
if (this is NRegister<TimeSpan> tsReg) {
|
||||
tsReg.SetValueFromPLC(TimeSpan.Zero);
|
||||
}
|
||||
if (this is BRegister boolReg) {
|
||||
boolReg.SetValueFromPLC(false);
|
||||
}
|
||||
if (this is SRegister stringReg) {
|
||||
stringReg.SetValueFromPLC(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the starting memory are either numeric or A,B,C,D etc for special areas like inputs
|
||||
/// </summary>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<PackageId>Mewtocol.NET</PackageId>
|
||||
<Version>0.6.1</Version>
|
||||
<Version>0.6.2</Version>
|
||||
<Authors>Felix Weiss</Authors>
|
||||
<Company>Womed</Company>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
|
||||
Reference in New Issue
Block a user