diff --git a/TFU002/TFU002.Logic/GatewayNotificationsExtensions.cs b/TFU002/TFU002.Logic/GatewayNotificationsExtensions.cs index 4da0410..4484c47 100644 --- a/TFU002/TFU002.Logic/GatewayNotificationsExtensions.cs +++ b/TFU002/TFU002.Logic/GatewayNotificationsExtensions.cs @@ -7,6 +7,7 @@ using Serilog; using Sharp7.Rx.Enums; using Sharp7.Rx.Interfaces; +using TFU002.Interfaces.Extensions; using TwinCAT.Ads; using TwinCAT.Ads.Reactive; using TwinCAT.TypeSystem; @@ -66,9 +67,11 @@ public static IDisposable GetTypedBeckhoffNotification(this AdsClient beckhoff, { if (type == typeof(byte[])) { - return beckhoff.WhenNotification(symbol.InstancePath, new NotificationSettings(AdsTransMode.Cyclic, 1000, 1000) ) + return Observable.Timer(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1)) + .Select(_ => beckhoff.ReadVariable(symbol)) .Do(value => Log.Logger.Debug($"Writing {symbol.InstancePath} to {address}: {ByteToString(value)}")) .SelectMany(value => plc.Write(address, value)) + .Retry() .Subscribe(); } @@ -139,5 +142,18 @@ private static async Task Write(this IPlc plc, string address, T value) } return Unit.Default; } + + private static T ReadVariable(this AdsClient beckhoff, ISymbol symbol) + { + try + { + return (T) beckhoff.ReadValue(symbol); + } + catch (Exception e) + { + Log.Logger.Error(e, $"Error while reading symbol {symbol.InstancePath}"); + throw; + } + } } }