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("%")) {