public virtual BrowseElement[] BrowseNext(ref Opc.Da.BrowsePosition position) { lock (this) { if (m_server == null) { throw new NotConnectedException(); } if (position == null || (object)position.GetType() != typeof(BrowsePosition)) { throw new BrowseCannotContinueException(); } BrowsePosition browsePosition = (BrowsePosition)position; if (browsePosition == null || browsePosition.ContinuationPoint == null || browsePosition.ContinuationPoint == "") { throw new BrowseCannotContinueException(); } int pdwCount = 0; int pbMoreElements = 0; ItemIdentifier itemID = ((BrowsePosition)position).ItemID; BrowseFilters filters = ((BrowsePosition)position).Filters; IntPtr pszContinuationPoint = Marshal.StringToCoTaskMemUni(browsePosition.ContinuationPoint); IntPtr ppBrowseElements = IntPtr.Zero; try { ((IOPCBrowse)m_server).Browse((itemID != null && itemID.ItemName != null) ? itemID.ItemName : "", ref pszContinuationPoint, filters.MaxElementsReturned, Interop.GetBrowseFilter(filters.BrowseFilter), (filters.ElementNameFilter != null) ? filters.ElementNameFilter : "", (filters.VendorFilter != null) ? filters.VendorFilter : "", filters.ReturnAllProperties ? 1 : 0, filters.ReturnPropertyValues ? 1 : 0, (filters.PropertyIDs != null) ? filters.PropertyIDs.Length : 0, Interop.GetPropertyIDs(filters.PropertyIDs), out pbMoreElements, out pdwCount, out ppBrowseElements); } catch (Exception e) { throw OpcCom.Interop.CreateException("IOPCBrowse.BrowseNext", e); } BrowseElement[] browseElements = Interop.GetBrowseElements(ref ppBrowseElements, pdwCount, deallocate: true); browsePosition.ContinuationPoint = Marshal.PtrToStringUni(pszContinuationPoint); Marshal.FreeCoTaskMem(pszContinuationPoint); if (pbMoreElements == 0 && (browsePosition.ContinuationPoint == null || browsePosition.ContinuationPoint == "")) { position = null; } ProcessResults(browseElements, filters.PropertyIDs); return(browseElements); } }
public virtual BrowseElement[] Browse(ItemIdentifier itemID, BrowseFilters filters, out Opc.Da.BrowsePosition position) { if (filters == null) { throw new ArgumentNullException("filters"); } lock (this) { if (m_server == null) { throw new NotConnectedException(); } position = null; int pdwCount = 0; int pbMoreElements = 0; IntPtr pszContinuationPoint = IntPtr.Zero; IntPtr ppBrowseElements = IntPtr.Zero; try { ((IOPCBrowse)m_server).Browse((itemID != null && itemID.ItemName != null) ? itemID.ItemName : "", ref pszContinuationPoint, filters.MaxElementsReturned, Interop.GetBrowseFilter(filters.BrowseFilter), (filters.ElementNameFilter != null) ? filters.ElementNameFilter : "", (filters.VendorFilter != null) ? filters.VendorFilter : "", filters.ReturnAllProperties ? 1 : 0, filters.ReturnPropertyValues ? 1 : 0, (filters.PropertyIDs != null) ? filters.PropertyIDs.Length : 0, Interop.GetPropertyIDs(filters.PropertyIDs), out pbMoreElements, out pdwCount, out ppBrowseElements); } catch (Exception e) { throw OpcCom.Interop.CreateException("IOPCBrowse.Browse", e); } BrowseElement[] browseElements = Interop.GetBrowseElements(ref ppBrowseElements, pdwCount, deallocate: true); string text = Marshal.PtrToStringUni(pszContinuationPoint); Marshal.FreeCoTaskMem(pszContinuationPoint); if (pbMoreElements != 0 || (text != null && text != "")) { position = new BrowsePosition(itemID, filters, text); } ProcessResults(browseElements, filters.PropertyIDs); return(browseElements); } }