/// <summary> /// Add items (according to "itemList" parameter) into OPC.Subscription /// </summary> /// <param name="itemList"></param> /// <param name="updateRate"></param> /// <returns></returns> public bool AddItems(Opc.Da.Item[] itemList, int updateRate = 0) { var state = new Opc.Da.SubscriptionState(); try { // Remove items if (Items != null) { Subscription.RemoveItems(Items); } state.Active = false; Subscription.ModifyState((int)Opc.Da.StateMask.Active, state); state.UpdateRate = updateRate > 0 ? updateRate : 1000; Subscription.ModifyState((int)Opc.Da.StateMask.UpdateRate, state); foreach (var item in itemList) { item.ClientHandle = Guid.NewGuid().ToString(); } Items = Subscription.AddItems(itemList); Advised = false; return(true); } catch (Exception e) { //MessageBox.Show(ex.Message); throw e; } }
/// <summary> /// Active/Deactive the OPC Server as the "auto" mode. /// When timer reaches, update the data from OPC server automatically. /// </summary> public void AdviseDeadvise() { if (Subscription == null) { return; } Advised = !Advised; try { var state = new Opc.Da.SubscriptionState { Active = Advised }; Subscription.ModifyState((int)Opc.Da.StateMask.Active, state); } catch (Exception e) { throw e; } }