Try to decouple NotifyValueChangedTag from application
patopat opened this issue · 0 comments
patopat commented
Hi,
From your example class NotifyValueChangedTag<M, T>, I would like decouple the Plc access and Plc client in order to facilitate the unit testing. I created PlcAccess.cs that implements an interface IPlcAccess, and PlcClient.cs
In PlcClient.cs, I declared :
public void SubscribeNotificationVar1(EventHandler<EventArgs> eventHandler) => _con.SubscribeNotificationChangedTag<MyTagPlcMapper, MyTagPlc>("Main.var1", eventHandler);
public void SubscribeNotificationVar2(EventHandler<EventArgs> eventHandler) => _con.SubscribeNotificationChangedTag<MyTagPlcMapper, MyTagPlc>("Main.var2", eventHandler);
In PlcAccess.cs, I declared :
public void SubscribeNotificationChangedTag<M, T>(string name, EventHandler<EventArgs> eventHandler) where M : IPlcMapper<T>, new()
{
var valueChangedTag = new NotifyValueChangedTag<M, T>()
{
Name = name,
Gateway = _gateway,
Path = _path,
PlcType = PlcType.ControlLogix,
Protocol = Protocol.ab_eip,
AutoSyncReadInterval = TimeSpan.FromMilliseconds(1000)
};
valueChangedTag.ValueChanged += eventHandler;
valueChangedTag.Initialize();
}
In IPlcAccess.cs :
public interface IPlcAccess
{
public void SubscribeNotificationChangedTag<M, T>(string name, EventHandler<EventArgs> eventHandler) where M : IPlcMapper<T>, new();
}
This doesn't work because the valueChangedTag is not saved, do you have an idea for an implementation that meets the decoupling ?
Regards,
Pat