//====================================================================== // Write /// <summary> /// Writes the value, quality and timestamp for a set of items. /// </summary> /// <param name="items">The set of item values to write.</param> /// <returns>The results of the write operation for each item.</returns> public IdentifiedResult[] Write(ItemValue[] items) { if (items == null) { throw new ArgumentNullException("items"); } if (items.Length == 0) { return(new Opc.IdentifiedResult[0]); } lock (this) { if (m_proxy == null) { throw new NotConnectedException(); } ItemValueList list = new ItemValueList(); list.AddRange(items); OpcXml.Da10.RequestOptions options = OpcXml.Da10.Request.GetRequestOptions(m_options.Locale, m_options.Filters); OpcXml.Da10.WriteRequestItemList requestList = OpcXml.Da10.Request.GetItemValueList(list); OpcXml.Da10.ReplyItemList replyList = null; OpcXml.Da10.OPCError[] errors = null; OpcXml.Da10.ReplyBase reply = m_proxy.Write( options, requestList, false, out replyList, out errors); CacheResponse(m_options.Locale, reply, errors); ItemValueResultList valueList = OpcXml.Da10.Request.GetResultList(replyList); if (valueList == null) { throw new InvalidResponseException(); } IdentifiedResult[] results = new IdentifiedResult[valueList.Count]; for (int ii = 0; ii < valueList.Count; ii++) { ItemValueResult valueResult = valueList[ii]; results[ii] = new IdentifiedResult(valueResult); results[ii].ResultID = valueResult.ResultID; results[ii].DiagnosticInfo = valueResult.DiagnosticInfo; } return(results); } }
//====================================================================== // 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))); } }