Skip to content

Commit

Permalink
added debug messages while writing bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarresi committed May 19, 2020
1 parent c18467c commit 028961e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions TFU002/TFU002.Logic/GatewayNotificationsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading;
Expand All @@ -19,6 +20,7 @@ public static IDisposable GetTypedS7Notification(this IPlc plc, Type type, strin
if (type == typeof(byte[]))
{
return plc.CreateNotification<byte[]>(address, TransmissionMode.Cyclic, TimeSpan.FromMilliseconds(1000))
.Do(value => Log.Logger.Debug($"Writing {address} to {symbol.InstancePath} {ByteToString(value)}"))
.SelectMany(value => beckhoff.Write(symbol, value))
.Subscribe();
}
Expand Down Expand Up @@ -65,6 +67,7 @@ public static IDisposable GetTypedBeckhoffNotification(this AdsClient beckhoff,
if (type == typeof(byte[]))
{
return beckhoff.WhenNotification<byte[]>(symbol.InstancePath, new NotificationSettings(AdsTransMode.Cyclic, 1000, 1000) )
.Do(value => Log.Logger.Debug($"Writing {symbol.InstancePath} to {address}: {ByteToString(value)}"))
.SelectMany(value => plc.Write(address, value))
.Subscribe();
}
Expand Down Expand Up @@ -106,6 +109,11 @@ public static IDisposable GetTypedBeckhoffNotification(this AdsClient beckhoff,
}
}

private static string ByteToString(byte[] value)
{
return string.Join(" ", value.Select(b => b.ToString("X2")));
}

private static async Task<Unit> Write<T>(this AdsClient beckhoff, ISymbol symbol, T value)
{
try
Expand Down

0 comments on commit 028961e

Please sign in to comment.