Compare commits
2 Commits
b7cddacde5
...
72256a214c
Author | SHA1 | Date |
---|---|---|
|
72256a214c | |
|
5208ae54b3 |
|
@ -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]
|
||||
|
@ -54,7 +60,7 @@ namespace LibS7Adv
|
|||
|
||||
public PLCViewModel()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ucLoaded()
|
||||
|
@ -79,9 +85,9 @@ namespace LibS7Adv
|
|||
[property: JsonIgnore]
|
||||
public void ConnectButton()
|
||||
{
|
||||
if (isConnected)
|
||||
if (isConnected)
|
||||
Disconnect();
|
||||
else
|
||||
else
|
||||
Connect();
|
||||
}
|
||||
|
||||
|
@ -147,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?
|
||||
{
|
||||
|
@ -237,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();
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -374,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("%"))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue