Using DDE in APG for Windows

By Bob Moyer
Autotest Company, San Antonio, TX

Find out how to use DDE for making custom Data Sheets printed from Word for Windows, or how to retrieve data from an Excel spread sheet for an APG for Windows test program.


Dynamic Data Exchange (DDE) permits one Windows application to share data with another Windows application. The following is a list of the applications this note will discuss:

DDE deals with the exchange of individual data elements. The data elements are uniquely identified by a multi-level name scheme. The hierarchy of this scheme is shown below:

NAME            ALSO CALLED            EXAMPLES

Application    Channel Number         WinWord
Name            or Service Name        Excel
                                       Chklim
                                       Parser

File Name       Topic Name             c:\winword\document.doc
                or Item                c:\excel\spreadst.xls	
                                       Result
                                       Globaldata

Item Name       Data Location          bookmark
                or Data cell           address
                                       Link Name
                                       APG for WindowsVariable

Data                                   Contents of
                                       Item above or
                                       APG for Windows Variables
                                       or literal text

DDE Commands in APG for Windows™

APG for Windows uses the following commands for DDE. Any of the location names can be variablized to aid in program execution. The term "Variable Name" can represent the actual data or a variable in APG for Windows that contains the data.

Poke DDE Data(Application Name,File Name,Item Name,Variable Name)
Puts data from APG for Windows (Variable Name) into another application (Application Name) file (File Name) at location (Item Name)
Request DDE Data(Application Name,File Name,Item Name,Variable Name)
Gets data at location (Item Name) in application (Application Name) file (File Name) and puts it into APG for Windows (Variable Name)
Start DDE Advise(Application Name,File Name,Item Name,Variable Name,Pointer)
Automatically updates APG for Windows (Variable Name) with changing data at location (Item Name) in another application (Application Name) file (File Name). This particular link between APG for Windows and the other application is identified in APG by the variable (Pointer)
Stop DDE Advise(Item Name,Pointer)
Close the open dialog to changing data (Item Name) in another application identified in APG as (Pointer)
Execute DDE Cmd(Application Name,File Name,Command String)
Issue command (Command String) to be executed in another application (Application) Name) file (File Name)

Starting Other Applications from APG for Windows

It is required that both applications involved in a DDE be open and running in Windows. The following command in APG for Windows allows another application to be opened:

Run An Application(Application Name,Pointer,Mode)
Calls another application (Application Name) to run in the windows environment. The pointer identifies the open application in APG. The mode sets how the application will open in Windows (Normal, Minimized, Maximized). If the application supports it, the File Name can be appended to the Application Name with the appropriate switch (i.e., c:\winword\winword.exe /r c:\winword\filename.doc). In this case the /r means open the file for read only.

Hint:
This command should be used in a conditional statement context to prevent re-opening the same application each time the next serial number is entered. In the following example the undeclared variable FirstTime is checked for definition. If this code sequence has been run before, the conditional fails and the Run an Application function is by-passed.


     If IsVar(FirstTime)
       Define Variable(FirstTime)
       Run an Application
     EndIf
 

Passing APG Data to Other Applications

Data to be passed to other applications from APG for Windows can come from direct calculation or function evaluation. For example, an operators response to a message box can be saved as "PASS" or "FAIL" in a string variable which in turn can be passed to another application in a DDE poke.

     Message Box(is the LED lit?,LED Visual Check,2,4)
     If(_MBRET==_YES)
       Format String(<string variable>,PASS)
     else
       Format String(<string variable>,FAIL)
     EndIf
     Poke DDE Data(application name,file name,item name,%<string variable>%)

Another example would be taking the result of the system function LineV, formatting it to have 1 decimal place, converting it into a string and passing it to another application by DDE poke.


     Format String(<string variable>,%1(LineV)%)
     Poke DDE Data (application name,file name,%<string variable>%)

Data acquired and stored by test procedures using the function Check Test Limits (within APG for Windows test programs) is available under the DDE application name CHKLIM. The data location information is outlined in the table below. For data logged by test procedures, the link name entered in the test is used as the Item Name.

Application Name    Topic Name    Item Name    Variable Name (type)

CHKLIM               NAME         Link Name    30 character string
                     ULIMIT       Link Name    floating point numeric
                     RESLUT       Link Name    floating point numeric
                     LLIMIT       Link Name    floating point numeric
                     PASSFAIL     Link Name    5 character string
                     UUT          Model        80 character string
                                  SERIALNUM    30 character string

To pass CHKLIM data to another application it must first be extracted from the CHKLIM application using the Request DDE Data function. The following example extracts the contents of the RESULT field from CHKLIM and stores it temporarily in <string variable> before passing it to the item name in the other application.


     Request DDE Data(CHKLIM, RESULT, %Link Name%,<string variable>)
     Poke DDE Data (application name,file name,item name,%<string variable>%)

Custom Data Sheet Using Word for Windows/APG for Windows DDE

Custom APG data sheets can best be handled through DDE with Word for Windows.

Basic Steps:

  1. Create a Word Document to Format your Custom Printout.
  2. Create the Test program in APG for Windows
  3. Extract the data elements from the Chklim DDE application.
  4. Send the data elements to the Word Bookmark locations.
  5. Send instructions to Word to initiate printing.

You can have APG for Windows open Word by using the Run An Application function and once the test is complete close Word using the Execute DDE Cmd function. However, because Word is slow to load, it is recommended that Word be opened before running APG for Windows. This can be done manually or automatically by Windows at start-up.

Data Input Using Excel/APG for Windows DDE

For a growing number of power supply manufacturers, modular supplies are becoming more common. In this arrangement various output modules may be configured in a single chassis to provide a wide variety of choices to the customer. However, the mix and match nature of these units can create a near infinite combination of modules. The cost for the test system programmer to write individual programs for each of these combinations would be very high.

The solution is to write a single program that identifies the modules and accesses the appropriate data to test that combination. The cataloging of the various modules is easily done in an Excel spreadsheet. Using string evaluation in the test program to decipher the unit configuration, DDE can then be used to extract the needed data from the spreadsheet and a variablized parameter test program can test any combination.

Specific data elements can be extracted from an Excel spreadsheet in much the same manner as the CHKLIM application.


     Request DDE Data(Excel,C;\\pathname\\filename.xls,cell name,<string variable>)

Where the contents of the cell named "cell name" are copied into the contents of the "variable string" in
APG for Windows.

The cells can be accessed either by naming them in the spread sheet or by referring to their row and column designation (i.e., R1C2). In the latter case a For/Next or nested For/Next loop could be utilized to automatically extract arrays of data from Excel. The Temp variable could alternatively be an array deep enough to store all the "xy" combinations.


     For(x=1,x<6,x++)
      For(y=1,y<6,y++)
       Request DDE Data(Excel,c:\\pathname\\filename.xls,R%x%C%y%,Temp)
      Next
     Next

Excel can be started from APG for Windows using the Run An Application function.


     Run An Application(c:\\excel\\excel.exe /r c:\\excel\\sheet\\filename.xls,v,0)

Where "/r" indicates open the file "filename.xls" read only. The "\\" is not a mistake. Because
the "\" character is reserved in APG for Windows, an additional "\" is required get the literal character.


Note:
Commands can be sent to Excel using the Execute DDE Cmd function. However, the control codes for Excel are not clearly listed anywhere in the Microsoft texts. Therefore, at this time there does not exist a proven method for sending certain commands to Excel. In particular this makes printing an Excel spreadsheet file from APG impossible. While it is possible to send data to and receive data from a spreadsheet in Excel, it is not recommended as a tool for custom data sheets. Its best use would be to analyze test results, returning the computed values to APG. Another useful task for Excel DDE is the storage of multi-model family specifications that can be used by a single multi-model test program to self-configure based on operator entry of model number.

See the attached APG for Windows program and Word Document for a working example of the Custom Data Sheet.
To obtain or download a self-extracting file containing the complete application, contact Autotest Technical Service.


Return to Top of Page

Return to Watt's News

Return to AUTOTEST Home Page


Copyright © 1995 - 2001, Autotest Company, All Rights Reserved.