Added register collection base methods

This commit is contained in:
Felix Weiß
2022-06-21 16:45:22 +02:00
parent f4fad297fb
commit 325aa56d8a
3 changed files with 27 additions and 3 deletions

View File

@@ -45,8 +45,7 @@ namespace Examples {
//corresponds to a DT7012 - DT7013 as a 32bit time value that gets parsed as a timespan (TIME) //corresponds to a DT7012 - DT7013 as a 32bit time value that gets parsed as a timespan (TIME)
//the smallest value to communicate to the PLC is 10ms //the smallest value to communicate to the PLC is 10ms
[Register(7012)] [Register(7012)]
public TimeSpan TestTime { get; private set; } public TimeSpan TestTime { get; private set; }
} }
} }

View File

@@ -356,6 +356,14 @@ namespace MewtocolNet {
}; };
if (collection != null)
collection.OnInterfaceLinked(this);
Connected += (i) => {
if(collection != null)
collection.OnInterfaceLinkedAndOnline(this);
};
return this; return this;
} }

View File

@@ -10,17 +10,34 @@ using System.Threading.Tasks;
namespace MewtocolNet.RegisterAttributes { namespace MewtocolNet.RegisterAttributes {
/// <summary>
/// A register collection base with full auto read and notification support built in
/// </summary>
public class RegisterCollectionBase : INotifyPropertyChanged { public class RegisterCollectionBase : INotifyPropertyChanged {
/// <summary>
/// Reference to its bound interface
/// </summary>
public MewtocolInterface PLCInterface { get; set; } public MewtocolInterface PLCInterface { get; set; }
/// <summary>
/// Whenever one of its props changes
/// </summary>
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
internal void TriggerPropertyChanged (string propertyName = null) { /// <summary>
/// Triggers a property changed event
/// </summary>
/// <param name="propertyName">Name of the property to trigger for</param>
public void TriggerPropertyChanged (string propertyName = null) {
var handler = PropertyChanged; var handler = PropertyChanged;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
public virtual void OnInterfaceLinked (MewtocolInterface plc) { }
public virtual void OnInterfaceLinkedAndOnline (MewtocolInterface plc) { }
} }
} }