/// <summary> /// Create a Subscription to watch data changes /// </summary> /// <returns></returns> public static Subscription CreateSubscription(this PlcDataMapper papper, ChangeDetectionStrategy changeDetectionStrategy = ChangeDetectionStrategy.Polling) { var sub = new Subscription(papper, changeDetectionStrategy); papper.AddSubscription(sub); return(sub); }
/// <summary> /// Subscribe to changes of variables /// </summary> /// <param name="mapper">Reference to plc data mapper</param> /// <param name="callback">Callback method</param> /// <param name="items">items to watch</param> /// <param name="changeDetectionStrategy">setup the strategy to detect changes. <see cref="ChangeDetectionStrategy"/>. This setting depends on the access library.</param> /// <returns></returns> public static Subscription SubscribeDataChanges(this PlcDataMapper mapper, OnChangeEventHandler callback, int interval, IEnumerable <PlcWatchReference> items, ChangeDetectionStrategy changeDetectionStrategy = ChangeDetectionStrategy.Polling) { var subscription = new Subscription(mapper, changeDetectionStrategy, items, interval); RunWatchTask(subscription, callback); return(subscription); }
/// <summary> /// Create an instance of a subscription to detect plc data changes /// </summary> /// <param name="mapper">The reference to the plcDatamapper.</param> /// <param name="vars">The variables we should watch.</param> /// <param name="defaultInterval">setup the default interval, if none was given by the <see cref="PlcWatchReference"/></param> public Subscription(PlcDataMapper mapper, ChangeDetectionStrategy changeDetectionStrategy = ChangeDetectionStrategy.Polling, IEnumerable <PlcWatchReference> vars = null, int defaultInterval = 1000) { _mapper = mapper ?? ExceptionThrowHelper.ThrowArgumentNullException <PlcDataMapper>(nameof(mapper)); _changeDetectionStrategy = changeDetectionStrategy; _defaultInterval = defaultInterval; _lock = new ReaderWriterLockSlim(); UpdateWatchCycle(vars); if (changeDetectionStrategy == ChangeDetectionStrategy.Event) { _changeEvent = new AsyncAutoResetEvent <IEnumerable <DataPack> >(); } if (vars != null) { AddItems(vars); } }
/// <summary> /// Subscribe to changes of variables /// </summary> /// <param name="mapper">Reference to plc data mapper</param> /// <param name="callback">Callback method</param> /// <param name="items">items to watch</param> /// <param name="changeDetectionStrategy">setup the strategy to detect changes. <see cref="ChangeDetectionStrategy"/>. This setting depends on the access library.</param> /// <returns></returns> public static Subscription SubscribeDataChanges(this PlcDataMapper mapper, OnChangeEventHandler callback, IEnumerable <PlcWatchReference> items, ChangeDetectionStrategy changeDetectionStrategy = ChangeDetectionStrategy.Polling) => SubscribeDataChanges(mapper, callback, DefaultInterval, items as IEnumerable <PlcWatchReference>, changeDetectionStrategy);