//- #endregion #region //Constructor //-------------------- /// <summary> /// Initializes a new instance of <see cref="Softing.OPCToolbox.Client.ServerBrowserData"> ServerBrowserData </see> class. /// </summary> /// <include /// file='TBNC.doc.xml' /// path='//class[@name="ServerBrowserData"]/constructor[@name="ServerBrowserData"]/doc/*' /// /> public ServerBrowserData() { m_clsId = null; m_progId = null; m_description = null; m_progIdVersionIndependent = null; m_opcSpecification = 0; m_url = null; }
private void CreateBrowseTree(string ipAddress, EnumOPCSpecification specification, TreeNode parent) { try { parent.Nodes.Clear(); Softing.OPCToolbox.Client.ServerBrowser serverBrowser = new ServerBrowser(ipAddress); ServerBrowserData[] serverData = null; if (ResultCode.SUCCEEDED(serverBrowser.Browse( specification, EnumServerBrowserData.ALL, out serverData, m_executionOptions))) { for (int i = 0; i < serverData.Length; i++) { TreeNode aNode = null; if (serverData[i].Description != String.Empty) { aNode = new TreeNode(serverData[i].Description, 7, 7); aNode.Tag = serverData[i].Url; parent.Nodes.Add(aNode); } if (serverData[i].ClsId != String.Empty) { TreeNode clsID = new TreeNode(serverData[i].ClsId, 5, 5); clsID.Tag = serverData[i].Url; aNode.Nodes.Add(clsID); } if (serverData[i].ProgId != String.Empty) { TreeNode progID = new TreeNode(serverData[i].ProgId, 5, 5); progID.Tag = serverData[i].Url; aNode.Nodes.Add(progID); } if (serverData[i].ProgIdVersionIndependent != String.Empty) { TreeNode vprogID = new TreeNode(serverData[i].ProgIdVersionIndependent, 5, 5); vprogID.Tag = serverData[i].Url; aNode.Nodes.Add(vprogID); } } //for } //if else { } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Initializes a new instance of <see cref="Softing.OPCToolbox.Client.ServerBrowserData"> ServerBrowserData </see> class /// with the value indicated by a class identifier, /// a program identifier of the server, a description of the server,a version independent /// program identifier, an OPC specification and a server url. /// </summary> /// <param name="clsId">A server's CLSID. <para>The CLSID is a 128-bit value which uniquely identifies the server.</para></param> /// <param name="progId">A server's ProgID.<para>The ProgID contains a readable string that describes the component.The structure /// of the string is predifined: [Manufacturer.Server_name].</para> </param> /// <param name="description">A description for the server.</param> /// <param name="progIdVersionIndependent">A server's version independent program ID.</param> /// <param name="opcSpecification">An OPC Specification.</param> /// <param name="url">An url.</param> internal ServerBrowserData(string clsId, string progId, string description, string progIdVersionIndependent, EnumOPCSpecification opcSpecification, string url) { m_clsId = clsId; m_progId = progId; m_description = description; m_progIdVersionIndependent = progIdVersionIndependent; m_opcSpecification = opcSpecification; m_url = url; }
//- #endregion /// <summary> /// Browses all the servers that support a specified interface specification. /// The server information to be returned after browsing is specified using the <see cref="EnumServerBrowserData"/> object. /// After browsing, a list of <see cref="ServerBrowserData"/> objects that contain the requested information will be returned. /// </summary> /// <param name="whatOPCspecification">An OPC specification.</param> /// <param name="whatServerData">Indicates what information about the server to be returned.</param> /// <param name="serverData">A list with requested information about the available servers on the computer.</param> /// <param name="someExecutionOptions">Specifies the modality of execution for browsing servers on the computer.</param> /// <returns>The result of browsing servers on the computer. /// </returns> /// <include /// file='TBNC.doc.xml' /// path='//class[@name="ServerBrowser"]/method[@name="Browse"]/doc/*' /// /> public virtual int Browse( EnumOPCSpecification whatOPCspecification, EnumServerBrowserData whatServerData, out ServerBrowserData[] serverData, ExecutionOptions someExecutionOptions) { int res = (int)EnumResultCode.E_FAIL; serverData = null; try { byte whatSpecification = (byte)whatOPCspecification; byte whatData = (byte)whatServerData; uint serverDataCount = 0; IntPtr pServerData = new IntPtr(); OTCExecutionOptions options = new OTCExecutionOptions(); if (someExecutionOptions != null) { options.m_executionType = (byte)someExecutionOptions.ExecutionType; options.m_executionContext = (uint)someExecutionOptions.ExecutionContext; } else { options.m_executionType = (byte)EnumExecutionType.SYNCHRONOUS; options.m_executionContext = 0; } res = OTBFunctions.OTCBrowseServer( m_ipAddress, whatSpecification, whatData, ref serverDataCount, out pServerData, ref options); if (someExecutionOptions.ExecutionType == EnumExecutionType.SYNCHRONOUS) { if (ResultCode.SUCCEEDED(res)) { uint dataCount = serverDataCount; serverData = new ServerBrowserData[dataCount]; OTCServerData[] serverDataOTC = new OTCServerData[dataCount]; OTCServerData typeOfServerData = new OTCServerData(); for (int i = 0; i < dataCount; i++) { int structSize = Marshal.SizeOf(typeOfServerData); OTCServerData myData = (OTCServerData) Marshal.PtrToStructure(OTBFunctions.GetIntPtrOffset(pServerData, structSize * i), typeof(OTCServerData)); serverData[i] = new ServerBrowserData( Marshal.PtrToStringUni(myData.m_clsid), Marshal.PtrToStringUni(myData.m_progId), Marshal.PtrToStringUni(myData.m_description), Marshal.PtrToStringUni(myData.m_vProgId), (EnumOPCSpecification)myData.m_opcSpecification, Marshal.PtrToStringUni(myData.m_url)); OTBFunctions.OTFreeMemory(myData.m_clsid); OTBFunctions.OTFreeMemory(myData.m_progId); OTBFunctions.OTFreeMemory(myData.m_description); OTBFunctions.OTFreeMemory(myData.m_vProgId); OTBFunctions.OTFreeMemory(myData.m_url); } // end for OTBFunctions.OTFreeMemory(pServerData); } // end if } // end if } catch (Exception exc) { Application.Instance.Trace( EnumTraceLevel.ERR, EnumTraceGroup.CLIENT, "ServerBrowser.Browse", exc.ToString()); } return(res); }