Ejemplo n.º 1
0
        /// <summary>
        ///     Adds the server group by group name and group state (optional).
        /// </summary>
        /// <param name="name">The group name.</param>
        /// <param name="state">The group state.</param>
        /// <returns>
        ///     Added group.
        /// </returns>
        public OpcDaGroup AddGroup(string name, OpcDaGroupState state = null)
        {
            CheckConnected();

            if (state == null)
            {
                state = new OpcDaGroupState();
            }

            int      serverGroupHandle;
            TimeSpan revisedUpdateRate;
            int      localeId = CultureHelper.GetLocaleId(state.Culture);

            object opcDaGroup = As <OpcServer>().AddGroup(name,
                                                          state.IsActive.GetValueOrDefault(false),
                                                          state.UpdateRate.GetValueOrDefault(TimeSpan.FromSeconds(1)),
                                                          state.ClientHandle.GetValueOrDefault(0),
                                                          state.TimeBias,
                                                          state.PercentDeadband,
                                                          localeId, out serverGroupHandle, out revisedUpdateRate);

            OpcDaGroup @group = CreateGroupWrapper(opcDaGroup);

            @group.UserData = state.UserData;
            OnGroupsChanged(new OpcDaServerGroupsChangedEventArgs(group, null));
            return(@group);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the group state.
        /// </summary>
        /// <param name="state">the group state.</param>
        public void SetState(OpcDaGroupState state)
        {
            int      localeId   = CultureHelper.GetLocaleId(state.Culture);
            TimeSpan updateRate = As <OpcGroupStateMgt>().SetState(state.UpdateRate, state.IsActive, state.TimeBias,
                                                                   state.PercentDeadband, localeId, state.ClientHandle);

            if (state.UpdateRate.HasValue)
            {
                _updateRate = updateRate;
            }

            if (state.IsActive.HasValue)
            {
                _isActive = state.IsActive.Value;
            }

            if (state.TimeBias.HasValue)
            {
                _timeBias = state.TimeBias.Value;
            }

            if (state.PercentDeadband.HasValue)
            {
                _percentDeadband = state.PercentDeadband.Value;
            }

            if (state.Culture != null)
            {
                _culture = state.Culture;
            }

            if (state.ClientHandle.HasValue)
            {
                _clientHandle = state.ClientHandle.Value;
            }
        }