Exemple #1
0
        public bool SetActiveState(int[] p_ArrHSrv, bool p_Activate, out int[] p_ArrErr)
        {
            p_ArrErr = null;
            int    l_Count = p_ArrHSrv.Length;
            IntPtr l_PtrErr;

            int l_HResult = m_IfItems.SetActiveState(l_Count, p_ArrHSrv, p_Activate, out l_PtrErr);

            if (HResults.Failed(l_HResult))
            {
                Marshal.ThrowExceptionForHR(l_HResult);
            }

            p_ArrErr = new int[l_Count];
            Marshal.Copy(l_PtrErr, p_ArrErr, 0, l_Count);
            Marshal.FreeCoTaskMem(l_PtrErr);

            return(l_HResult == HResults.S_OK);
        }
Exemple #2
0
        public bool SetActiveState(bool active, params short[] items)
        {
            int count = items.Length;

            int[] arrSvr = new int[count];
            for (int i = 0; i < count; i++)
            {
                ITag item = GetItemByID(items[i]);
                if (item != null)
                {
                    arrSvr[i] = item.Address.Start;
                }
            }
            IntPtr ptrErr;

            if (HRESULTS.Succeeded(_itemMgt.SetActiveState(count, arrSvr, active, out ptrErr)))
            {
                Marshal.FreeCoTaskMem(ptrErr);
                return(true);
            }
            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Sets the active state for a set of items in a group.
        /// </summary>
        public void ActivateItems(bool active)
        {
            // count the number of items to activate.
            List <GroupItem> itemsToActivate = new List <GroupItem>();

            lock (Lock)
            {
                for (int ii = 0; ii < m_items.Count; ii++)
                {
                    if (m_items[ii].ActiveChanged && m_items[ii].Active == active && m_items[ii].Created)
                    {
                        itemsToActivate.Add(m_items[ii]);
                    }
                }
            }

            // check if nothing to do.
            if (itemsToActivate.Count == 0)
            {
                return;
            }

            // build list of items to remove.
            int count = itemsToActivate.Count;

            int[] serverHandles = new int[count];

            for (int ii = 0; ii < itemsToActivate.Count; ii++)
            {
                serverHandles[ii] = itemsToActivate[ii].ServerHandle;
            }

            // initialize output parameters.
            IntPtr pErrors = IntPtr.Zero;

            string methodName = "IOPCItemMgt.SetActiveState";

            try
            {
                IOPCItemMgt server = BeginComCall <IOPCItemMgt>(methodName, true);

                server.SetActiveState(
                    count,
                    serverHandles,
                    (active) ? 1 : 0,
                    out pErrors);
            }
            catch (Exception e)
            {
                ComUtils.TraceComError(e, methodName);

                for (int ii = 0; ii < itemsToActivate.Count; ii++)
                {
                    itemsToActivate[ii].ActiveChanged = false;
                    itemsToActivate[ii].ErrorId       = Marshal.GetHRForException(e);
                }
            }
            finally
            {
                EndComCall(methodName);
            }

            // free returned error array.
            int[] errors = ComUtils.GetInt32s(ref pErrors, count, true);

            // save error codes.
            for (int ii = 0; ii < count; ii++)
            {
                itemsToActivate[ii].ActiveChanged = false;
                itemsToActivate[ii].ErrorId       = errors[ii];
            }

            /*
             * Utils.Trace(
             *  "Group {0} ActivateItems({4}/{5}) {1}/{2}ms {3}%",
             *  m_clientHandle,
             *  m_samplingInterval,
             *  m_actualSamplingInterval,
             *  m_deadband,
             *  active,
             *  itemsToActivate.Count);
             */
        }