Page tree
Skip to end of metadata
Go to start of metadata

Overview

AWRDE supports API access through the COM automation API. While AWRDE is typically controlled via the Sax VB scripting engine incorporated into the design environment, it is sometimes desirable to control the environment from external programs created in a variety of languages.

One of the problems of using external programs is having the program connect to the desired instance of AWRDE when multiple instances are running. This application note describes a mechanism for handling this problem.

This is an example how to write a compiled application (VB.NET in this example), run that app from MWO, and have the app connect to and control MWO.

Example in Action

Let's start by running an example that actually solves the problem to get an understand of how this solution works in practice. Do this by:

  1. Unzip My_Mwo_vb_app.zip

  2. Start Microwave Office

  3. Open the project My_Mwo_vb_app\Testing\Mwo_dotNet_App_test.emp

  4. From the menu, choose Scripts -> Project Scripts -> Run_My_App(Main) . The following dialog should appear:

This window is created by My_Mwo_vb_app.exe , which is in the same folder as the project file. This program was launched by MWO and then connected to MWO via the API and iterated through the schematic in the project, writing them to the dialog.

Digging In

Open the scripting IDE ( Tools -> Scripting Editor ) and open the project script called Run_My_App:

Option Explicit
        Sub Main
         Debug.Clear
         Dim cmdLine As String
         cmdLine = Project.Path & "My_Mwo_vb_app.exe -mwoclsid {" & MWO.InstanceCLSID & "}"
         Debug.Print cmdLine
         Shell( cmdLine, vbNormalFocus)
        End Sub

You can see we're using the Shell() function to run the .exe. We also pass a command line argument, which is the Instance Class ID (MWO.InstanceCLSID). The debug window shows what this looks like:

 
        C:\dev\My_Mwo_vb_app\Testing\My_Mwo_vb_app.exe -mwoclsid
            {982F4F38-A474-43B4-897F-CD242C565460}

The value in the curly brackets { } will be different each time you start a new instance of MWO. This value is used by the external exe to connect to the COM interface of this specific instance of MWO.exe.

Let's open the VB.NET app to see how this works.

In the archive is a Visual Studio 2012 solution (My_Mwo_vb_app.sln) with a VB.NET project called "My_Mwo_vb_app". Double-click the .sln to start Visual Studio.

In the project settings, under References, note we've added AWR Design Environment 11.

The project has a single form, "Form1". Bring up the code window for the form:

Imports MWO
        Public Class Form1
            Private m_iMwo As IMWO
            Private Sub Form1_Load(sender As Object , e As EventArgs ) Handles MyBase.Load
               m_iMwo = Get_IMWO_Interface()
               If m_iMwo Is Nothing Then
                  Dim dlgRes As DialogResult = MessageBox .Show( "Start a new instance?" , _"Error connecting to MWO" , _MessageBoxButtons .YesNo, MessageBoxIcon .Exclamation, _MessageBoxDefaultButton .Button1)
                  If dlgRes = DialogResult.Yes Then
                     m_iMwo = Create_New_MWO_Instance()
                  Else
                     Me .Close()
                     Exit Sub
                  End If
               End If
        
               RichTextBox1.AppendText(m_iMwo.Caption & vbLf)
               Dim proj As Project = m_iMwo.Project
        
               RichTextBox1.AppendText( "---Schematics---" & vbLf)
               Dim s As Schematic
               For Each s In proj.Schematics
                  RichTextBox1.AppendText(vbTab & s.Name & vbLf)
               Next s
            End Sub
        
            Private Sub BtnOk_Click(sender As Object , e As EventArgs ) Handles BtnOk.Click
               Me .Close()
            End Sub
        End Class

In the function Form1_Load(), we call the function Get_IMWO_Interface(). This function is in the file Connect_To_MWO.vb , which you can copy in to any new vb apps (or refer to it from a common location.)

This function parses the command line arguments, gets the Instance CLSID, and uses it to query the OS for an IMWO interface. This interface is the same one you can get from the SAX VB scripting environment by typing "MWO" or "Project.Application".

If the function could not connect to the MWO CLSID from the command line (eg, no command line was passed), it will return Nothing . In that case it will ask the user if he wants to start a new instance or MWO (actually it will start a new instance if none exists, or connect to an existing instance.) The function Create_New_MWO_Instance() is also in Connect_To_MWO.vb .

After we have an IMWO instance, we can use it to get the Project, and from there get Schematics, Graphs, and anything else in the component API. In this example we use it to print the main window caption, and list the schematics from the project.

If you are writing the app to be part of a process library, you can add it to the PDK scripts folder. Then when launching the app from a script, you can use

 Project.ProcessLibraries(myLibName).IniFilePath

To get the path to the PDK's ini file. From there you can strip the .ini file name off the path, add "Scripts" and you have the path to the .exe.

  • No labels