Using MATLAB from ATEasy

Knowledge Base Article # Q200235

Read Prior Article Read Next Article
Summary This article provides an example project and an explanation of how to use MATLAB from ATEasy.
Login to rate article
Installing MathWorks MATLAB® will also install an ActiveX control “Matlab Application Type Library” that can be used to write and retrieve variables from environments other than the MATLAB command window, such as ATEasy.  An ATEasy driver (MATLAB.drv) has been created as a wrapper for this interoperability tool to perform the majority of the overhead of starting and communicating with the MATLAB utility.  This allows you to reuse existing test application code in ATEasy projects with only a few lines of code.

Manipulating the MATLAB Command Window

Upon launching the ATEasy, the MATLAB driver will open a MATLAB command window that will open and run in the background until the termination of the ATEasy Application.  If your project requires direct interaction with the command window, there are two ATEasy commands for command window manipulation:
MATLAB Window Maximize(): Maximizes command window and brings it to the front.
MATLAB Window Minimize(): Minimizes the command window.

Send Instructions to the MATLAB Command Window

Text-based instructions can be sent to the MATLAB window from ATEasy using the Execute command.  
MATLAB Execute (sCommand, psResponse)

Where sCommand is the string sent to the MATLAB window and psResponse is MATLAB’s response.
For instance, the following code in MATLAB:
>> a=1

a =

>> b=3*a

b =

Can be executed in ATEasy with the following commands:
MATLAB Execute(“a=1”, sResponse1)
MATLAB Execute(“b=3*a”, sResponse2)

Example Code

The following code with pass the integers 3 and 5 to the ExpTwo function in ExpTwo.m and return back the value to the TestResult variable.
dwLength : DWord ! The length of the directory string name
sCommand : String ! The command that is sent to the command window
s : String ! The response from the command window

dwLength=GetShortPathNameA(GetDir(0), NULL, 0)
dwLength=GetShortPathNameA(GetDir(0), sCommand, dwLength)   ! HPVEE requires  short file names 8.3 use Windows API to retrieve it
sCommand="cd "+sCommand
MATLAB Execute(sCommand, s)
MATLAB Execute(sCommand, s)
MATLAB Get Variable("result", TestResult)

ATEasy Project and Example

DownloadATEasy and MATLAB Example
Article Date 1/16/2013 , 4/16/2014
Keywords ATEasy, MATLAB, Mathworks, ActiveX, Automation, Interoperability

Login to rate article

Read Prior Article Read Next Article