public void QueryAvailableProperties(string itemId) { var pdwCount = 0; var ppPropertyIds = IntPtr.Zero; var ppDescriptions = IntPtr.Zero; var ppvtDataTypes = IntPtr.Zero; _server.QueryAvailableProperties(itemId, out pdwCount, out ppPropertyIds, out ppDescriptions, out ppvtDataTypes); if (pdwCount > 0) { var ids = ComUtils.GetInt32s(ref ppPropertyIds, pdwCount, true); var descs = ComUtils.GetUnicodeStrings(ref ppDescriptions, pdwCount, true); var types = ComUtils.GetInt16s(ref ppvtDataTypes, pdwCount, true); } }
/// <summary> /// Gets the event attributes. /// </summary> /// <param name="categoryId">The category id.</param> /// <param name="attributeIds">The attribute ids.</param> /// <param name="descriptions">The descriptions.</param> /// <param name="datatypes">The datatypes.</param> public bool GetEventAttributes( int categoryId, out int[] attributeIds, out string[] descriptions, out short[] datatypes) { string methodName = "IOPCEventServer.QueryEventAttributes"; int count = 0; IntPtr pAttributeIds = IntPtr.Zero; IntPtr pDescriptions = IntPtr.Zero; IntPtr pDataTypes = IntPtr.Zero; try { IOPCEventServer server = BeginComCall <IOPCEventServer>(methodName, true); server.QueryEventAttributes( categoryId, out count, out pAttributeIds, out pDescriptions, out pDataTypes); } catch (Exception e) { ComCallError(methodName, e); } finally { EndComCall(methodName); } // unmarshal results. attributeIds = ComUtils.GetInt32s(ref pAttributeIds, count, true); descriptions = ComUtils.GetUnicodeStrings(ref pDescriptions, count, true); datatypes = ComUtils.GetInt16s(ref pDataTypes, count, true); // remove the AREAS attribute which is never exposed. for (int ii = 0; ii < count; ii++) { if (String.Compare(descriptions[ii], "AREAS", StringComparison.OrdinalIgnoreCase) == 0) { int[] attributeIds2 = new int[count - 1]; string[] descriptions2 = new string[count - 1]; short[] datatypes2 = new short[count - 1]; if (ii > 0) { Array.Copy(attributeIds, attributeIds2, ii); Array.Copy(descriptions, descriptions2, ii); Array.Copy(datatypes, datatypes2, ii); } if (ii < count - 1) { Array.Copy(attributeIds, ii + 1, attributeIds2, ii, count - ii - 1); Array.Copy(descriptions, ii + 1, descriptions2, ii, count - ii - 1); Array.Copy(datatypes, ii + 1, datatypes2, ii, count - ii - 1); } attributeIds = attributeIds2; descriptions = descriptions2; datatypes = datatypes2; break; } } return(count > 0); }
/// <summary> /// Read the available non-built in properties from the server. /// </summary> /// <param name="itemId">The item id.</param> /// <param name="updateCache">if set to <c>true</c> the cache is updated.</param> /// <returns>The array of properties.</returns> public DaProperty[] ReadAvailableProperties(string itemId, bool updateCache) { string methodName = "IOPCItemProperties.QueryAvailableProperties"; // query for available properties. int count = 0; IntPtr pPropertyIds = IntPtr.Zero; IntPtr pDescriptions = IntPtr.Zero; IntPtr pDataTypes = IntPtr.Zero; try { IOPCItemProperties server = BeginComCall <IOPCItemProperties>(methodName, true); server.QueryAvailableProperties( itemId, out count, out pPropertyIds, out pDescriptions, out pDataTypes); } catch (Exception e) { if (ComUtils.IsUnknownError(e, ResultIds.E_FAIL, ResultIds.E_UNKNOWNITEMID, ResultIds.E_INVALIDITEMID)) { ComUtils.TraceComError(e, methodName); } return(null); } finally { EndComCall(methodName); } // unmarshal results. int[] propertyIds = ComUtils.GetInt32s(ref pPropertyIds, count, true); string[] descriptions = ComUtils.GetUnicodeStrings(ref pDescriptions, count, true); short[] datatype = ComUtils.GetInt16s(ref pDataTypes, count, true); List <DaProperty> properties = new List <DaProperty>(); for (int ii = 0; ii < count; ii++) { // do not return any of the built in properties. if (propertyIds[ii] <= PropertyIds.TimeZone) { continue; } DaProperty property = new DaProperty(); property.PropertyId = propertyIds[ii]; property.Name = descriptions[ii]; property.DataType = datatype[ii]; properties.Add(property); } // fetch the item ids. if (properties.Count > 0) { DaProperty[] array = properties.ToArray(); GetPropertyItemIds(itemId, array); // update the cache. if (updateCache) { lock (m_cache) { DaElement element = null; if (m_cache.TryGetValue(itemId, out element)) { element.Properties = array; } } } return(array); } return(null); }