Compare commits

..

No commits in common. "72256a214c51c715e3037737c53a5d5033fcd760" and "b7cddacde5a612a6b4d1b914b4e598a1ea859bc6" have entirely different histories.

1 changed files with 9 additions and 60 deletions

View File

@ -6,7 +6,6 @@ using System.Text.RegularExpressions;
using System.ComponentModel; using System.ComponentModel;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
namespace LibS7Adv namespace LibS7Adv
{ {
@ -43,16 +42,11 @@ namespace LibS7Adv
string lastError; string lastError;
} }
public partial class PLCViewModel : ObservableObject public partial class PLCViewModel : ObservableObject
{ {
[JsonIgnore] [JsonIgnore]
private IInstance Instance { get; set; } private IInstance Instance { get; set; }
[JsonIgnore]
private Stopwatch stopwatch = new Stopwatch();
private bool IsConfigured { get; set; } private bool IsConfigured { get; set; }
[ObservableProperty] [ObservableProperty]
@ -60,7 +54,7 @@ namespace LibS7Adv
public PLCViewModel() public PLCViewModel()
{ {
} }
public void ucLoaded() public void ucLoaded()
@ -85,9 +79,9 @@ namespace LibS7Adv
[property: JsonIgnore] [property: JsonIgnore]
public void ConnectButton() public void ConnectButton()
{ {
if (isConnected) if (isConnected)
Disconnect(); Disconnect();
else else
Connect(); Connect();
} }
@ -153,7 +147,7 @@ namespace LibS7Adv
return false; return false;
} }
if (sTag == null) if (sTag == null)
{ return false; } { return false; }
var tag = ParseTagAddress(sTag); var tag = ParseTagAddress(sTag);
if (tag.tagType == EDataType.Unknown) // Normal Tag? if (tag.tagType == EDataType.Unknown) // Normal Tag?
{ {
@ -243,7 +237,7 @@ namespace LibS7Adv
{ {
var val = Instance?.MarkerArea.ReadByte(tag.word_offset); var val = Instance?.MarkerArea.ReadByte(tag.word_offset);
if (Signed) if (Signed)
return val > 127 ? (val - 256).ToString() : val.ToString(); return val > 127 ? (val-256).ToString() : val.ToString();
return val.ToString(); return val.ToString();
} }
} }
@ -335,10 +329,7 @@ namespace LibS7Adv
{ {
try try
{ {
stopwatch.Restart();
Instance?.WriteBool(pTag, pValue); Instance?.WriteBool(pTag, pValue);
stopwatch.Stop();
Debug.WriteLine($" EscribirTagBool took {stopwatch.Elapsed.TotalMilliseconds} ms");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -349,10 +340,7 @@ namespace LibS7Adv
{ {
try try
{ {
stopwatch.Restart();
Instance?.WriteInt16(pTag, (short)pValue); Instance?.WriteInt16(pTag, (short)pValue);
stopwatch.Stop();
Debug.WriteLine($" EscribirTagInt16 took {stopwatch.Elapsed.TotalMilliseconds} ms");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -364,11 +352,7 @@ namespace LibS7Adv
{ {
try try
{ {
stopwatch.Restart(); return Instance?.ReadBool(pTag) ?? false;
bool result = Instance?.ReadBool(pTag) ?? false;
stopwatch.Stop();
Debug.WriteLine($" LeerTagBool took {stopwatch.Elapsed.TotalMilliseconds} ms");
return result;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -381,11 +365,7 @@ namespace LibS7Adv
{ {
try try
{ {
stopwatch.Restart(); return Instance?.ReadInt16(pTag);
int? result = Instance?.ReadInt16(pTag);
stopwatch.Stop();
Debug.WriteLine($" LeerTagInt16 took {stopwatch.Elapsed.TotalMilliseconds} ms");
return result;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -394,42 +374,11 @@ 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) public static TagAddress ParseTagAddress(string tag)
{ {
TagAddress tagAddress = new TagAddress(); TagAddress tagAddress = new TagAddress();
if (tag == null) if (tag==null)
return null; return null;
if (tag.StartsWith("%")) if (tag.StartsWith("%"))
{ {