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

@@ -47,6 +47,5 @@ namespace Examples {
[Register(7012)]
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;
}

View File

@@ -10,17 +10,34 @@ using System.Threading.Tasks;
namespace MewtocolNet.RegisterAttributes {
/// <summary>
/// A register collection base with full auto read and notification support built in
/// </summary>
public class RegisterCollectionBase : INotifyPropertyChanged {
/// <summary>
/// Reference to its bound interface
/// </summary>
public MewtocolInterface PLCInterface { get; set; }
/// <summary>
/// Whenever one of its props changes
/// </summary>
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;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public virtual void OnInterfaceLinked (MewtocolInterface plc) { }
public virtual void OnInterfaceLinkedAndOnline (MewtocolInterface plc) { }
}
}