From 72256a214c51c715e3037737c53a5d5033fcd760 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 14 Feb 2025 14:04:29 +0100 Subject: [PATCH] Agregada funcion de analizar la matriz de exportacion de tags. Creada un submenu para cargar los ultimos directorios ustilizados. Cambiado intercambio de datos para los Motores simulados a DINT --- PLCViewModel.cs | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/PLCViewModel.cs b/PLCViewModel.cs index 238123c..19d6f94 100644 --- a/PLCViewModel.cs +++ b/PLCViewModel.cs @@ -60,7 +60,7 @@ namespace LibS7Adv public PLCViewModel() { - + } public void ucLoaded() @@ -85,9 +85,9 @@ namespace LibS7Adv [property: JsonIgnore] public void ConnectButton() { - if (isConnected) + if (isConnected) Disconnect(); - else + else Connect(); } @@ -153,7 +153,7 @@ namespace LibS7Adv return false; } if (sTag == null) - { return false; } + { return false; } var tag = ParseTagAddress(sTag); if (tag.tagType == EDataType.Unknown) // Normal Tag? { @@ -243,7 +243,7 @@ namespace LibS7Adv { var val = Instance?.MarkerArea.ReadByte(tag.word_offset); if (Signed) - return val > 127 ? (val-256).ToString() : val.ToString(); + return val > 127 ? (val - 256).ToString() : val.ToString(); return val.ToString(); } } @@ -367,7 +367,7 @@ namespace LibS7Adv stopwatch.Restart(); bool result = Instance?.ReadBool(pTag) ?? false; stopwatch.Stop(); - Debug.WriteLine($" LeerTagBool took {stopwatch.Elapsed.TotalMilliseconds} ms"); + Debug.WriteLine($" LeerTagBool took {stopwatch.Elapsed.TotalMilliseconds} ms"); return result; } catch (Exception ex) @@ -394,11 +394,42 @@ namespace LibS7Adv } } + public int? LeerTagDInt(string pTag) + { + try + { + stopwatch.Restart(); + int? result = Instance?.ReadInt32(pTag); + stopwatch.Stop(); + Debug.WriteLine($" LeerTagDInt took {stopwatch.Elapsed.TotalMilliseconds} ms"); + return result; + } + catch (Exception ex) + { + PlcData.LastError = pTag + ":" + ex.Message; + return 0; + } + } + + public void EscribirTagDInt(string pTag, int pValue) + { + try + { + stopwatch.Restart(); + Instance?.WriteInt32(pTag, pValue); + stopwatch.Stop(); + Debug.WriteLine($" EscribirTagDInt took {stopwatch.Elapsed.TotalMilliseconds} ms"); + } + catch (Exception ex) + { + PlcData.LastError = pTag + ":" + ex.Message; + } + } public static TagAddress ParseTagAddress(string tag) { TagAddress tagAddress = new TagAddress(); - if (tag==null) + if (tag == null) return null; if (tag.StartsWith("%")) {