MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB技术文章 (https://www.labfans.com/bbs/forumdisplay.php?f=25)
-   -   Deploying a Measurement Application with the MATLAB Compiler (https://www.labfans.com/bbs/showthread.php?t=1107)

TechnicalArticles 2008-01-06 16:32

Deploying a Measurement Application with the MATLAB Compiler
 
[B]Deploying a Measurement Application with the
MATLAB Compiler[URL="http://www.mathworks.com/programs/digest_offer/sept04/measureapp.html"][IMG]http://www.mathworks.com/company/newsletters/digest/images/download_scripts.gif[/IMG][/URL][/B]


[B]by [EMAIL="[email protected]"]Rob Purser[/EMAIL][/B]
An important new feature of the [URL="http://www.mathworks.com/products/compiler/"]MATLAB Compiler 4[/URL] is the capability to deploy applications that use [URL="http://www.mathworks.com/products/matlab/"]MATLAB[/URL] objects, such as those provided by the [URL="http://www.mathworks.com/products/daq/"]Data Acquisition Toolbox[/URL]. 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.
[B]The Scenario[/B]

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.
[B]Cable Tester Hardware[/B]

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.
[IMG]http://www.mathworks.com/company/newsletters/digest/sept04/images/connector_ports.jpg[/IMG]
[I]Figure 1. The connector ports on the cable tester box are marked green and yellow.[/I]

[B]Signal Quality[/B]

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).
[B]Data Acquisition Hardware[/B]

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).
[URL="http://www.mathworks.com/company/newsletters/digest/sept04/images/device_board_wl.jpg"][IMG]http://www.mathworks.com/company/newsletters/digest/sept04/images/device_board_w.jpg[/IMG][/URL]
[I]Figure 2. Measurement Computing PMD-1024FS device (left), with the circuit board integrated into the cable test box (right). Click on image to see enlarged view.[/I]

[B]Build the GUI[/B]

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).
[URL="http://www.mathworks.com/company/newsletters/digest/sept04/images/schematic_wl.jpg"][IMG]http://www.mathworks.com/company/newsletters/digest/sept04/images/schematic_w.gif[/IMG][/URL]
[I]Figure 3. Cable tester schematic (left) and graphical interface (right). Click on image to see enlarged view.[/I]

[B]The Data Acquisition Toolbox[/B]

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);


addchannel(ai,0);


set(ai,'SampleRate',1000);


set(ai,'SamplesPerTrigger',1000);


start(ai);

waittilstop(ai,1);


results = getdata(ai); % Device ID 1 is for PMD-1208FS
% assigned by Measurement Computing

% Add channel 0 to the analog input
% object (ai)

% Set the sample rate to 1000
% samples/second

% Set number of samples to acquire
% to 1000

% Start the acquisition

% Wait for up to 1 second for
% acquisition to complete

% Retrieve the data into ‘results’
% variable For more information about the Data Acquisition Toolbox, see the [URL="http://www.mathworks.com/access/helpdesk/help/toolbox/daq/daq.html"]Data Acquisition Toolbox documentation[/URL].
[B]Run the Cable Tester[/B]

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:[LIST=1][*] 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.[/LIST]Once everything is working in MATLAB, we are ready to deploy the application to the test lab.
[B]Create the Standalone Executable[/B]

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:[LIST=1][*] 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.[/LIST]When you start your application on the target machine, it expands the archive file and starts the MCR to run your deployed application.
[B]Deploy to the Test Lab[/B]

In order to deploy an application developed in MATLAB, you need to do three things:[LIST=1][*]Compile your application[*]Deploy the application and the MCR to the target machine[*]Run your application on the target machine[/LIST][B]Compile the application[/B]

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 [URL="http://www.mathworks.com/access/helpdesk/help/toolbox/compiler/mcc.html"]MCC documentation[/URL].
[B]Deploy to the Target Machine[/B]

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.
[B]Run the Application on the Target Machine[/B]

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.)
[B]Importance of Deployment[/B]

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.
[URL="http://www.mathworks.com/programs/digest_offer/sept04/measureapp.html"][IMG]http://www.mathworks.com/company/newsletters/digest/images/download_scripts.gif[/IMG][/URL] [I]Download the code described in this article.[/I]

[URL="http://www.mathworks.com/company/newsletters/digest/sept04/measureapp.html"]更多...[/URL]


所有时间均为北京时间。现在的时间是 19:48

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.