mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 03:01:24 +00:00
Added auto register reset to default typed value on disconnect
This commit is contained in:
@@ -34,7 +34,7 @@ class Program {
|
|||||||
Task.Factory.StartNew(async () => {
|
Task.Factory.StartNew(async () => {
|
||||||
|
|
||||||
//attaching the logger
|
//attaching the logger
|
||||||
Logger.LogLevel = LogLevel.Critical;
|
Logger.LogLevel = LogLevel.Verbose;
|
||||||
Logger.OnNewLogMessage((date, msg) => {
|
Logger.OnNewLogMessage((date, msg) => {
|
||||||
Console.WriteLine($"{date.ToString("HH:mm:ss")} {msg}");
|
Console.WriteLine($"{date.ToString("HH:mm:ss")} {msg}");
|
||||||
});
|
});
|
||||||
@@ -50,6 +50,7 @@ class Program {
|
|||||||
while (true) {
|
while (true) {
|
||||||
if (isProgressReadout) continue;
|
if (isProgressReadout) continue;
|
||||||
Console.Title = $"Polling Paused: {interf.PollingPaused}, " +
|
Console.Title = $"Polling Paused: {interf.PollingPaused}, " +
|
||||||
|
$"Poller active: {interf.PollerActive}, " +
|
||||||
$"Speed UP: {interf.BytesPerSecondUpstream} B/s, " +
|
$"Speed UP: {interf.BytesPerSecondUpstream} B/s, " +
|
||||||
$"Speed DOWN: {interf.BytesPerSecondDownstream} B/s, " +
|
$"Speed DOWN: {interf.BytesPerSecondDownstream} B/s, " +
|
||||||
$"Poll delay: {interf.PollerDelayMs} ms, " +
|
$"Poll delay: {interf.PollerDelayMs} ms, " +
|
||||||
@@ -58,7 +59,21 @@ class Program {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await interf.ConnectAsync((plcinf) => AfterConnect(interf, registers));
|
//await interf.ConnectAsync((plcinf) => AfterConnect(interf, registers));
|
||||||
|
|
||||||
|
bool flip = false;
|
||||||
|
while(true) {
|
||||||
|
|
||||||
|
if(!flip) {
|
||||||
|
await interf.ConnectAsync();
|
||||||
|
} else {
|
||||||
|
interf.Disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
flip = !flip;
|
||||||
|
await Task.Delay(5000);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,17 @@ namespace MewtocolNet {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool PollingPaused => pollerIsPaused;
|
public bool PollingPaused => pollerIsPaused;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if the poller is actvice (can be paused)
|
||||||
|
/// </summary>
|
||||||
|
public bool PollerActive => !pollerTaskStopped;
|
||||||
|
|
||||||
internal event Action PolledCycle;
|
internal event Action PolledCycle;
|
||||||
|
|
||||||
internal volatile bool pollerTaskRunning;
|
internal volatile bool pollerTaskRunning;
|
||||||
internal volatile bool pollerTaskStopped;
|
internal volatile bool pollerTaskStopped;
|
||||||
internal volatile bool pollerIsPaused;
|
internal volatile bool pollerIsPaused;
|
||||||
|
internal volatile bool pollerFirstCycle = false;
|
||||||
|
|
||||||
internal bool usePoller = false;
|
internal bool usePoller = false;
|
||||||
|
|
||||||
@@ -37,6 +43,8 @@ namespace MewtocolNet {
|
|||||||
pollerTaskRunning = false;
|
pollerTaskRunning = false;
|
||||||
pollerTaskStopped = true;
|
pollerTaskStopped = true;
|
||||||
|
|
||||||
|
ClearRegisterVals();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -80,6 +88,8 @@ namespace MewtocolNet {
|
|||||||
if (pollerTaskRunning)
|
if (pollerTaskRunning)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
pollerFirstCycle = true;
|
||||||
|
|
||||||
Task.Factory.StartNew(async () => {
|
Task.Factory.StartNew(async () => {
|
||||||
|
|
||||||
Logger.Log("Poller is attaching", LogLevel.Info, this);
|
Logger.Log("Poller is attaching", LogLevel.Info, this);
|
||||||
@@ -167,6 +177,7 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
iteration++;
|
iteration++;
|
||||||
|
pollerFirstCycle = false;
|
||||||
|
|
||||||
await Task.Delay(pollerDelayMs);
|
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
|
#endregion
|
||||||
|
|
||||||
#region Register Collection
|
#region Register Collection
|
||||||
|
|||||||
@@ -94,6 +94,38 @@ namespace MewtocolNet.Registers {
|
|||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));
|
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>
|
/// <summary>
|
||||||
/// Gets the starting memory are either numeric or A,B,C,D etc for special areas like inputs
|
/// Gets the starting memory are either numeric or A,B,C,D etc for special areas like inputs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<PackageId>Mewtocol.NET</PackageId>
|
<PackageId>Mewtocol.NET</PackageId>
|
||||||
<Version>0.6.1</Version>
|
<Version>0.6.2</Version>
|
||||||
<Authors>Felix Weiss</Authors>
|
<Authors>Felix Weiss</Authors>
|
||||||
<Company>Womed</Company>
|
<Company>Womed</Company>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
|||||||
Reference in New Issue
Block a user