/// <summary> /// Initializes object with the specified Item object. /// </summary> public OpcItem(OpcItem item) : base(item) { if (item != null) { ReqType = item.ReqType; MaxAge = item.MaxAge; MaxAgeSpecified = item.MaxAgeSpecified; Active = item.Active; ActiveSpecified = item.ActiveSpecified; Deadband = item.Deadband; DeadbandSpecified = item.DeadbandSpecified; SamplingRate = item.SamplingRate; SamplingRateSpecified = item.SamplingRateSpecified; EnableBuffering = item.EnableBuffering; EnableBufferingSpecified = item.EnableBufferingSpecified; } }
public ItemResult[] AddItems(string[] itemIds, Guid[] ClientHandles = null) { int count = itemIds.Count(); bool handleFlag = ClientHandles != null && ClientHandles.Length == itemIds.Length; if (count <= 0) { return(new ItemResult[0]); } // construct OpcItems //OpcRcw.Da.OPCITEMDEF[] output = null; OpcItem[] items = new OpcItem[count]; for (int ii = 0; ii < count; ii++) { items[ii] = new OpcItem(); items[ii].ItemName = itemIds[ii]; items[ii].ClientHandle = handleFlag ? ClientHandles[ii] : Guid.NewGuid(); m_itemIds.Add(itemIds[ii]); } // get opc item def OpcRcw.Da.OPCITEMDEF[] definitions = GetOPCITEMDEFs(items); // initialize output parameters. IntPtr pResults = IntPtr.Zero; IntPtr pErrors = IntPtr.Zero; try { ((IOPCItemMgt)m_group).AddItems( count, definitions, out pResults, out pErrors); } catch (Exception e) { throw HD.OPC.Client.Core.Com.Interop.CreateException("IOPCItemMgt.AddItems", e); } // unmarshal output parameters. int[] serverHandles = this.GetItemResults(ref pResults, count, true); int[] errors = HD.OPC.Client.Core.Com.Interop.GetInt32s(ref pErrors, count, true); // construct result list. ItemResult[] results = new ItemResult[count]; for (int ii = 0; ii < count; ii++) { // create a new ResultIDs. results[ii] = new ItemResult(items[ii]); // save server handles. results[ii].ServerHandle = serverHandles[ii]; //results[ii].ClientHandle = definitions[ii].hClient; // items created active by default. if (!results[ii].ActiveSpecified) { results[ii].Active = true; results[ii].ActiveSpecified = true; } // update result id. results[ii].ResultID = HD.OPC.Client.Core.Com.Interop.GetResultID(errors[ii]); results[ii].DiagnosticInfo = null; // save client handle. results[ii].ClientHandle = items[ii].ClientHandle; // add new item table. if (results[ii].ResultID.Succeeded()) { lock (m_items) { m_items[items[ii].ClientHandle.GetHashCode()] = new ItemIdentifier(results[ii]); } // restore internal handle. // results[ii].ClientHandle = definitions[ii].hClient; } } // return results. lock (m_items) { return((ItemResult[])m_items.ApplyFilters(m_filters, results)); } }