Connecting to Simulator Automation Server
Once the Type Library or COM functions have been included in your programming environment, the Simulator Automation Server can be handled as any other object in your code. The method for assigning and connecting to the Simulator Automation Server can vary depending on the programming environment used, but the idea is basically the same. You define a variable in your program to point to the server object, which is called SimulatorAuto. If the Type Library was imported properly, you should have full access to the SimulatorAuto object and its defined functions. Again, the procedure for creating the object and connecting to SimulatorAuto may vary for different programming languages. Check the help for your programming environment on connecting to COM or Automation servers.
Examples
The following examples are just a few specific examples for certain programming media. The procedure may be different for other programming media not listed. In addition, a procedure given for a certain type of programming media may be one variation from several possible procedures for accomplishing the same task.
Borland Delphi 5
- Add pwrworld_TLB to the uses section of your unit.
- Declare a variable globally or as part of another object: A : ISimulatorAuto
- Initialize the variable: A := nil
- To connect to the Simulator Automation Server, create the connection: A := CoSimulatorAuto.create
- Perform function calls to the Simulator Automation Server: Output := A.SomeFunction(parameters)
- To close the connection to the Simulator Automation Server, remove the reference by again setting: A := nil
Microsoft Visual Basic for Applications
Early Binding:
- To connect to the Simulator Automation Server, create the connection initializing the variable:
Dim A as New pwrworld.SimulatorAuto
Late Binding:
- Declare a variable globally or as part of another object or function: Dim A As Object
- To connect to the Simulator Automation Server, create the connection:
Set A = CreateObject("pwrworld.SimulatorAuto")
Both Early and Late Binding:
- Perform function calls to the Simulator Automation Server: Output = A.SomeFunction parameters
- To close the connection to the Simulator Automation Server, remove the reference: Set A = Nothing
- If Type Library was imported, connection can also be achieved as in version 9 (See Connecting to Simulator Automation Server in version 9).
Microsoft .NET
- Connect to the Simulator Automation Server in one of the manners given above
- Perform function calls as given above
- The .NET environment does not release all resources immediately, but when the opportunity arises. Using the method described above, i.e. Set A = Nothing, may not release the Simulator Automation Server instance. To force the Simulator Automation Server to close, use the following code snippet:
Marshal.FinalReleaseComObject(A)
Set A = Nothing
- To learn more about this function, go to the Microsoft MSDN documentation at: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.finalreleasecomobject.aspx
Microsoft Visual C++
- Declare a variable globally or as part of another object or function: IsimulatorAutoPtr *A
- Declare a variable globally or as part of another object or function: CLSID clsid
- Declare a variable globally or as part of another object or function: HRESULT hr
- Obtain the class identifier (clsid) with the following command:
hr = CLSIDFromProgID(L"pwrworld.SimulatorAuto", &clsid)
- Initialize variable A: A = new IsimulatorAutoPtr
- To connect to the Simulator Automation Server, create the connection:
hr = A>CreateInstance(clsid, NULL, CLSCTX_SERVER)
- Perform function calls to the Simulator Automation Server: Output = A.SomeFunction(parameters)
- To close the connection to the Simulator Automation Server, release the reference:
hr = A>Release()
Python
- COM connections require pyWin32 extensions
- The following will establish a connection:
import win32com.client
object = win32com.client.Dispatch("pwrworld.SimulatorAuto")
- The following will close the connection:
del object
object = None
Matlab v.6.5 r.13
- To connect to the Simulator Automation Server, create the connection:
A = actxserver(‘pwrworld.SimulatorAuto’)
- Perform function calls to the Simulator Automation Server: Output = A.SomeFunction(parameters)
- To close the connection to the Simulator Automation Server, delete the connection: delete(A)