示例#1
0
        //======================================================================
        // Private Methods

        /// <summary>
        /// Sends data change notifications for all active items.
        /// </summary>
        private void OnDataChange(ItemValueResultList items)
        {
            lock (this)
            {
                if (m_callback != null)
                {
                    m_callback(m_state.ClientHandle, null, (ItemValueResult[])items.ToArray(typeof(ItemValueResult)));
                }
            }
        }
        //======================================================================
        // Read

        /// <summary>
        /// Reads the current values for a set of items.
        /// </summary>
        /// <param name="items">The set of items to read.</param>
        /// <returns>The results of the read operation for each item.</returns>
        public Opc.Da.ItemValueResult[] Read(Item[] items)
        {
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            if (items.Length == 0)
            {
                return(new Opc.Da.ItemValueResult[0]);
            }

            lock (this)
            {
                if (m_proxy == null)
                {
                    throw new NotConnectedException();
                }

                ItemList list = new ItemList();
                list.AddRange(items);

                OpcXml.Da10.RequestOptions      options     = OpcXml.Da10.Request.GetRequestOptions(m_options.Locale, m_options.Filters);
                OpcXml.Da10.ReadRequestItemList requestList = OpcXml.Da10.Request.GetItemList(list);
                OpcXml.Da10.ReplyItemList       replyList   = null;
                OpcXml.Da10.OPCError[]          errors      = null;

                OpcXml.Da10.ReplyBase reply = m_proxy.Read(
                    options,
                    requestList,
                    out replyList,
                    out errors);

                CacheResponse(m_options.Locale, reply, errors);

                ItemValueResultList valueList = OpcXml.Da10.Request.GetResultList(replyList);

                if (valueList == null)
                {
                    throw new InvalidResponseException();
                }

                return((ItemValueResult[])valueList.ToArray(typeof(ItemValueResult)));
            }
        }