From f4af3dd05e8f61d5e2efecb89311e43837c2c920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Wei=C3=9F?= <72068105+Sandoun@users.noreply.github.com> Date: Fri, 28 Jul 2023 15:51:31 +0200 Subject: [PATCH] Register str data auto updates --- Examples.WPF/Views/PlcDataView.xaml | 14 ++++++++++++-- MewtocolNet/IPlc.cs | 2 ++ MewtocolNet/Registers/Base/IRegister.cs | 10 ++++++++++ MewtocolNet/Registers/Base/Register.cs | 17 ++++++++++++++--- MewtocolNet/UnderlyingRegisters/DTArea.cs | 14 ++++++-------- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/Examples.WPF/Views/PlcDataView.xaml b/Examples.WPF/Views/PlcDataView.xaml index 4d84bda..0de5a41 100644 --- a/Examples.WPF/Views/PlcDataView.xaml +++ b/Examples.WPF/Views/PlcDataView.xaml @@ -14,7 +14,6 @@ - @@ -71,6 +70,17 @@ - + + + + + + + + + diff --git a/MewtocolNet/IPlc.cs b/MewtocolNet/IPlc.cs index 22dd3e7..9416f9a 100644 --- a/MewtocolNet/IPlc.cs +++ b/MewtocolNet/IPlc.cs @@ -68,6 +68,8 @@ namespace MewtocolNet { /// int ConnectTimeout { get; set; } + IEnumerable Registers { get; } + /// /// Tries to establish a connection with the device asynchronously /// diff --git a/MewtocolNet/Registers/Base/IRegister.cs b/MewtocolNet/Registers/Base/IRegister.cs index 1eedbf5..9c78d5f 100644 --- a/MewtocolNet/Registers/Base/IRegister.cs +++ b/MewtocolNet/Registers/Base/IRegister.cs @@ -34,6 +34,16 @@ namespace MewtocolNet.Registers { /// object ValueObj { get; } + /// + /// The current value of the register as a string + /// + string ValueStr { get; } + + /// + /// The system (.NET) type of the underlying value thats held inside the register + /// + Type UnderlyingSystemType { get; } + /// /// The plc memory address of the register /// diff --git a/MewtocolNet/Registers/Base/Register.cs b/MewtocolNet/Registers/Base/Register.cs index ced697c..3edc0aa 100644 --- a/MewtocolNet/Registers/Base/Register.cs +++ b/MewtocolNet/Registers/Base/Register.cs @@ -39,14 +39,20 @@ namespace MewtocolNet.Registers { internal bool wasOverlapFitted = false; /// - public RegisterCollection ContainedCollection => containedCollection; + internal RegisterCollection ContainedCollection => containedCollection; /// - public MewtocolInterface AttachedInterface => attachedInterface; + internal MewtocolInterface AttachedInterface => attachedInterface; + + /// + public Type UnderlyingSystemType => underlyingSystemType; /// public object ValueObj => lastValue; + /// + public string ValueStr => GetValueString(); + /// public RegisterPrefix RegisterType { get; internal set; } @@ -63,7 +69,12 @@ namespace MewtocolNet.Registers { public event PropertyChangedEventHandler PropertyChanged; - public void TriggerNotifyChange() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ValueObj))); + public void TriggerNotifyChange() { + + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ValueObj))); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ValueStr))); + + } #endregion diff --git a/MewtocolNet/UnderlyingRegisters/DTArea.cs b/MewtocolNet/UnderlyingRegisters/DTArea.cs index 6c36a90..ad8c675 100644 --- a/MewtocolNet/UnderlyingRegisters/DTArea.cs +++ b/MewtocolNet/UnderlyingRegisters/DTArea.cs @@ -64,19 +64,17 @@ namespace MewtocolNet.UnderlyingRegisters { internal async Task RequestByteReadAsync(ulong addStart, ulong addEnd) { - var station = mewInterface.GetStationNumber(); + var byteCount = (addEnd - addStart + 1) * 2; + var result = await mewInterface.ReadByteRangeNonBlocking((int)addStart, (int)byteCount); - string requeststring = $"%{station}#RD{GetMewtocolIdent(addStart, addEnd)}"; - var result = await mewInterface.SendCommandAsync(requeststring); + if (result != null) { - if (result.Success) { - - var resBytes = result.Response.ParseDTRawStringAsBytes(); - SetUnderlyingBytes(resBytes, addStart); + SetUnderlyingBytes(result, addStart); + return true; } - return result.Success; + return false; }