From 5208ae54b3f4d9f2e8c780b0a23dbd68aae0867a Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 13 Feb 2025 14:01:54 +0100 Subject: [PATCH] Agregado Timers para ver donde se pierde tiempo --- PLCViewModel.cs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/PLCViewModel.cs b/PLCViewModel.cs index a73942e..238123c 100644 --- a/PLCViewModel.cs +++ b/PLCViewModel.cs @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using System.ComponentModel; using Newtonsoft.Json.Linq; using System.ComponentModel.DataAnnotations; +using System.Diagnostics; namespace LibS7Adv { @@ -42,11 +43,16 @@ namespace LibS7Adv string lastError; } + + public partial class PLCViewModel : ObservableObject { [JsonIgnore] private IInstance Instance { get; set; } - + + [JsonIgnore] + private Stopwatch stopwatch = new Stopwatch(); + private bool IsConfigured { get; set; } [ObservableProperty] @@ -329,7 +335,10 @@ namespace LibS7Adv { try { + stopwatch.Restart(); Instance?.WriteBool(pTag, pValue); + stopwatch.Stop(); + Debug.WriteLine($" EscribirTagBool took {stopwatch.Elapsed.TotalMilliseconds} ms"); } catch (Exception ex) { @@ -340,7 +349,10 @@ namespace LibS7Adv { try { + stopwatch.Restart(); Instance?.WriteInt16(pTag, (short)pValue); + stopwatch.Stop(); + Debug.WriteLine($" EscribirTagInt16 took {stopwatch.Elapsed.TotalMilliseconds} ms"); } catch (Exception ex) { @@ -352,7 +364,11 @@ namespace LibS7Adv { try { - return Instance?.ReadBool(pTag) ?? false; + stopwatch.Restart(); + bool result = Instance?.ReadBool(pTag) ?? false; + stopwatch.Stop(); + Debug.WriteLine($" LeerTagBool took {stopwatch.Elapsed.TotalMilliseconds} ms"); + return result; } catch (Exception ex) { @@ -365,7 +381,11 @@ namespace LibS7Adv { try { - return Instance?.ReadInt16(pTag); + stopwatch.Restart(); + int? result = Instance?.ReadInt16(pTag); + stopwatch.Stop(); + Debug.WriteLine($" LeerTagInt16 took {stopwatch.Elapsed.TotalMilliseconds} ms"); + return result; } catch (Exception ex) {