Deploying a Measurement Application with the MATLAB Compiler
By Rob Purser, MathWorks
An important new feature of the MATLAB Compiler 4 is the capability to deploy applications that use MATLAB objects, such as those provided by the Data Acquisition Toolbox. As a result, you can deploy any MATLAB program you write as a standalone application to your coworkers and customers. This example demonstrates how to use MATLAB and the MATLAB Compiler to create a cable-testing application and deploy it to a target machine.
The Scenario
Cable testing is a chore, and cabling errors are one of the most difficult problems to diagnose when you are building a system. Connections can be broken, shorted to a different pin, or even wired to the wrong pin. Worse, certain problems appear only intermittently. To assist technicians in this repetitive task, we use MATLAB and the Data Acquisition Toolbox to create a graphical cable testing application that we deploy to the test lab.
Using a cable tester box, with a cable as our Device Under Test (DUT), we excite each pin on one end of the cable, and monitor all the pins at the other end. Typically, the person conducting the test manually wiggles the cable during the test in order to reveal any intermittent failures. In addition, we conduct additional tests to ensure that a particular set of frequencies can be correctly transmitted over the cable. Once the application is deployed to the target machine, a technician can run the application without ever using MATLAB.
Cable Tester Hardware
The cable tester box has two ports into which the technician plugs each end of the cable (Figure 1). Not all cables are symmetric, so the two connectors are marked green and yellow to help ensure that the cable is connected correctly.

Signal Quality
When working with analog signals, it is important to be aware of noise creeping into your acquired analog data. The most common source of noise in measurements is from nearby AC power. One of the most effective ways to eliminate noise from your analog measurements is by using a differential measurement mode and twisted pairs of signal wires.
Synchronizing the analog input and output subsystems can lead to problems with unexpected phase and amplitude difference. To reduce errors, we measure the output signal that we apply as well as the returned signal that is transmitted through the DUT (rather than simply assuming the output signal is perfect).
Data Acquisition Hardware
We use a PMD-1208FS data acquisition device from Measurement Computing to connect to the computer. This card has 16 bits of digital I/O, 2 analog output channels, and 4 differential channels of analog input (these can also be configured as 8 single-ended channels). Because the device connects externally to the computer via the USB 2.0 port, you don’t need to open up the computer to install it, and you can run your tests from a laptop. In this case, we removed the PMD-1208FS circuit board from its case and integrated it into the cable test box, so that the technician can connect the computer to the tester with the USB cable, rather than connect all the individual wires to the cable tester (Figure 2).
Build the GUI
We develop the cable tester using the MATLAB Graphical User Interface development environment (GUIDE), which enables you to build your application by laying out the desired components and connecting them to your M-code to implement the various operations (Figure 3).
The Data Acquisition Toolbox
We use the Data Acquisition Toolbox version 2.5 to control the PMD-1208FS. The Data Acquisition Toolbox provides an easy way to get analog and digital data in and out of MATLAB. For instance, to get 1,000 points of voltage data from channel 0 on the PMD-1208FS, you would do the following:
ai = analoginput('mcc',1); % Device ID 1 is for PMD-1208FS % assigned by Measurement Computing addchannel(ai,0); % Add channel 0 to the analog input set(ai,'SampleRate',1000); % object (ai) % Set the sample rate to 1000 set(ai,'SamplesPerTrigger',1000); % samples/second % Set number of samples to acquire start(ai); % to 1000 waittilstop(ai,1); % Start the acquisition % Wait for up to 1 second for results = getdata(ai); % acquisition to complete % Retrieve the data into ‘results’ % variable
For more information about the Data Acquisition Toolbox, see the Data Acquisition Toolbox documentation.
Run the Cable Tester
Once the GUI has been designed and all the code is completed, we save it to an M-file so that we can run the application from within MATLAB.
Our cable tester runs the following tests on a 9-pin cable:
- Check that each pin is correctly and continuously connected.
- Monitor that as each pin is excited, only the correct target pin is connected.
- Repeat these tests several hundred times to verify operation while we wiggle the cable.
- Transmit sine waves at various frequencies to ensure that the cable is capable of carrying the signals accurately.
Once everything is working in MATLAB, we are ready to deploy the application to the test lab.
Create the Standalone Executable
The final step is to use the MATLAB Compiler to create a standalone application from the M-code. MATLAB Compiler 4 uses the MATLAB Component Runtime (MCR), which is a stand-alone set of shared libraries that enables the execution of M-files. In order to deploy an application, we must supply both the application itself and the MCR.
A complete deployed application has three parts:
- A small executable wrapper application for either Windows or Linux
- An archive containing all the M-files and toolbox files needed by the application
- The MATLAB Component Runtime, or MCR. Before end users can run MATLAB Compiler-generated applications on their machines, they need to install the MCR, if it is not already present.
When you start your application on the target machine, it expands the archive file and starts the MCR to run your deployed application.
Deploy to the Test Lab
In order to deploy an application developed in MATLAB, you need to do three things:
- Compile your application
- Deploy the application and the MCR to the target machine
- Run your application on the target machine
Compile the application
To deploy our M-code as a standalone Windows application, we use the mcc
command at the MATLAB command line, as follows:
mcc –m cableTest
In our case, this creates two files: CABLETEST.EXE
and CABLETEST.CTF
, which make up our application. For details on the mcc
command, see the MCC documentation.
Deploy to the Target Machine
The MCR installer is called MCRInstaller.exe
and resides in the \toolbox\compiler\deploy\win32
directory of the MATLAB installation. We copy this, the CABLETEST.EXE
, and the CABLETEST.CTF
file to the target machine. Once the MCR is installed on a target machine by executing MCRInstaller.exe
, all standalone applications created by the MATLAB Compiler will share it. For details on installing the MCR, see the MATLAB Compiler 4 documentation.
Run the Application on the Target Machine
With the MCR in place, we run CABLETEST.EXE
, which will start our application independent of MATLAB. (Note that the first time we run the application, it takes longer to start as the program unpacks all the files in the CABLETEST.CTF
file. Subsequently, this step is omitted, and the application will start faster.)
Importance of Deployment
Deployment makes it possible to distribute analysis applications developed in MATLAB to your customers and coworkers so that they can simply interact with your application, without being familiar with MATLAB. With the MATLAB Compiler 4, it is now possible to incorporate the full range of MATLAB and toolbox features into a standalone, deployable application. This can be especially useful in measurement applications where many people need to run the same test or a technician is running a repetitive test. By using MATLAB and the Data Acquisition Toolbox, a custom measurement application can be created for your customers and coworkers.
Published 2004