public void Next(int celt, out IntPtr ppItemArray, out int pceltFetched) { EnumOPCItemAttributes attributes2; Monitor.Enter(attributes2 = this); try { pceltFetched = 0; ppItemArray = IntPtr.Zero; if (this.m_index < this.m_items.Count) { pceltFetched = this.m_items.Count - this.m_index; if (pceltFetched > celt) { pceltFetched = celt; } ppItemArray = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(OPCITEMATTRIBUTES)) * pceltFetched); IntPtr ptr = ppItemArray; for (int i = 0; i < pceltFetched; i++) { ItemAttributes attributes = (ItemAttributes)this.m_items[this.m_index + i]; OPCITEMATTRIBUTES structure = new OPCITEMATTRIBUTES { szItemID = attributes.ItemID, szAccessPath = attributes.AccessPath, hClient = attributes.ClientHandle, hServer = attributes.ServerHandle, bActive = attributes.Active ? 1 : 0, vtCanonicalDataType = (short)OpcCom.Interop.GetType(attributes.CanonicalDataType), vtRequestedDataType = (short)OpcCom.Interop.GetType(attributes.RequestedDataType), dwAccessRights = (int)OpcCom.Da.Interop.MarshalPropertyValue(Property.ACCESSRIGHTS, attributes.AccessRights), dwBlobSize = 0, pBlob = IntPtr.Zero, dwEUType = (OPCEUTYPE)OpcCom.Da.Interop.MarshalPropertyValue(Property.EUTYPE, attributes.EuType), vEUInfo = null }; switch (attributes.EuType) { case euType.analog: structure.vEUInfo = new double[] { attributes.MinValue, attributes.MaxValue }; break; case euType.enumerated: structure.vEUInfo = attributes.EuInfo; break; } Marshal.StructureToPtr(structure, ptr, false); ptr = (IntPtr)(ptr.ToInt32() + Marshal.SizeOf(typeof(OPCITEMATTRIBUTES))); } this.m_index += pceltFetched; } } catch (Exception exception) { throw OpcCom.Da.Wrapper.Server.CreateException(exception); } finally { Monitor.Exit(attributes2); } }
internal OpcDaItemAttributes(OPCITEMATTRIBUTES itemAttributes) { AccessPath = itemAttributes.szAccessPath; ItemID = itemAttributes.szItemID; IsActive = itemAttributes.bActive; ClientHandle = itemAttributes.hClient; ServerHandle = itemAttributes.hServer; AccessRights = (OpcDaAccessRights)itemAttributes.dwAccessRights; Blob = new byte[itemAttributes.dwBlobSize]; Marshal.Copy(itemAttributes.pBlob, Blob, 0, Blob.Length); RequestedDataType = TypeConverter.FromVarEnum((VarEnum)itemAttributes.vtRequestedDataType); CanonicalDataType = TypeConverter.FromVarEnum((VarEnum)itemAttributes.vtCanonicalDataType); EUType = (OpcDaEUType)itemAttributes.dwEUType; EUInfo = itemAttributes.vEUInfo; }
internal OpcDaItem(OPCITEMATTRIBUTES opcItemDefinition, OpcDaGroup @group) { Group = @group; ClientHandle = opcItemDefinition.hClient; ServerHandle = opcItemDefinition.hServer; ItemId = opcItemDefinition.szItemID; RequestedDataType = TypeConverter.FromVarEnum((VarEnum)opcItemDefinition.vtRequestedDataType); CanonicalDataType = TypeConverter.FromVarEnum((VarEnum)opcItemDefinition.vtCanonicalDataType); AccessPath = opcItemDefinition.szAccessPath; IsActive = opcItemDefinition.bActive; AccessRights = (OpcDaAccessRights)opcItemDefinition.dwAccessRights; if (opcItemDefinition.pBlob != IntPtr.Zero) { Blob = new byte[opcItemDefinition.dwBlobSize]; Marshal.Copy(opcItemDefinition.pBlob, Blob, 0, Blob.Length); } }
/// <remarks/> public void Next(int celt, out System.IntPtr ppItemArray, out int pceltFetched) { lock (m_lock) { try { pceltFetched = 0; ppItemArray = IntPtr.Zero; if (m_index >= m_items.Count) { return; } // determine how many items to return. pceltFetched = m_items.Count - m_index; if (pceltFetched > celt) { pceltFetched = celt; } // allocate return array. ppItemArray = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(OPCITEMATTRIBUTES)) * pceltFetched); // marshal items to return. IntPtr pos = ppItemArray; for (int ii = 0; ii < pceltFetched; ii++) { ItemAttributes item = (ItemAttributes)m_items[m_index + ii]; OPCITEMATTRIBUTES copy = new OPCITEMATTRIBUTES(); copy.szItemID = item.ItemID; copy.szAccessPath = item.AccessPath; copy.hClient = item.ClientHandle; copy.hServer = item.ServerHandle; copy.bActive = (item.Active)?1:0; copy.vtCanonicalDataType = (short)item.CanonicalDataType; copy.vtRequestedDataType = (short)item.RequestedDataType; copy.dwAccessRights = item.AccessRights; copy.dwBlobSize = 0; copy.pBlob = IntPtr.Zero; copy.dwEUType = item.EuType; copy.vEUInfo = null; switch (item.EuType) { case OPCEUTYPE.OPC_ANALOG: { copy.vEUInfo = new double[] { item.MinValue, item.MaxValue }; break; } case OPCEUTYPE.OPC_ENUMERATED: { copy.vEUInfo = item.EuInfo; break; } } Marshal.StructureToPtr(copy, pos, false); pos = (IntPtr)(pos.ToInt32() + Marshal.SizeOf(typeof(OpcRcw.Da.OPCITEMATTRIBUTES))); } // update index. m_index += pceltFetched; } catch (Exception e) { throw ComUtils.CreateComException(e); } } }
public void Next(int celt, out IntPtr ppItemArray, out int pceltFetched) { lock (this) { try { pceltFetched = 0; ppItemArray = IntPtr.Zero; if (m_index >= m_items.Count) { return; } pceltFetched = m_items.Count - m_index; if (pceltFetched > celt) { pceltFetched = celt; } ppItemArray = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(OPCITEMATTRIBUTES)) * pceltFetched); IntPtr ptr = ppItemArray; for (int i = 0; i < pceltFetched; i++) { ItemAttributes itemAttributes = (ItemAttributes)m_items[m_index + i]; OPCITEMATTRIBUTES oPCITEMATTRIBUTES = default(OPCITEMATTRIBUTES); oPCITEMATTRIBUTES.szItemID = itemAttributes.ItemID; oPCITEMATTRIBUTES.szAccessPath = itemAttributes.AccessPath; oPCITEMATTRIBUTES.hClient = itemAttributes.ClientHandle; oPCITEMATTRIBUTES.hServer = itemAttributes.ServerHandle; oPCITEMATTRIBUTES.bActive = (itemAttributes.Active ? 1 : 0); oPCITEMATTRIBUTES.vtCanonicalDataType = (short)OpcCom.Interop.GetType(itemAttributes.CanonicalDataType); oPCITEMATTRIBUTES.vtRequestedDataType = (short)OpcCom.Interop.GetType(itemAttributes.RequestedDataType); oPCITEMATTRIBUTES.dwAccessRights = (int)Interop.MarshalPropertyValue(Property.ACCESSRIGHTS, itemAttributes.AccessRights); oPCITEMATTRIBUTES.dwBlobSize = 0; oPCITEMATTRIBUTES.pBlob = IntPtr.Zero; oPCITEMATTRIBUTES.dwEUType = (OPCEUTYPE)Interop.MarshalPropertyValue(Property.EUTYPE, itemAttributes.EuType); oPCITEMATTRIBUTES.vEUInfo = null; switch (itemAttributes.EuType) { case euType.analog: oPCITEMATTRIBUTES.vEUInfo = new double[2] { itemAttributes.MinValue, itemAttributes.MaxValue }; break; case euType.enumerated: oPCITEMATTRIBUTES.vEUInfo = itemAttributes.EuInfo; break; } Marshal.StructureToPtr((object)oPCITEMATTRIBUTES, ptr, fDeleteOld: false); ptr = (IntPtr)(ptr.ToInt64() + Marshal.SizeOf(typeof(OPCITEMATTRIBUTES))); } m_index += pceltFetched; } catch (Exception e) { throw Server.CreateException(e); } } }