Detailed instructions for use are in the User's Guide.
[. . . ] xPC TargetTM 4 User's Guide
How to Contact The MathWorks
Web Newsgroup www. mathworks. com/contact_TS. html Technical Support
www. mathworks. com comp. soft-sys. matlab suggest@mathworks. com bugs@mathworks. com doc@mathworks. com service@mathworks. com info@mathworks. com
Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information
508-647-7000 (Phone) 508-647-7001 (Fax) The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site. xPC TargetTM User's Guide © COPYRIGHT 19992010 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. [. . . ] Do not overwrite the template file.
16 Copy the file sfun_atmos. c into your Fortran working folder, for example,
xpc_fortran_test.
Your next task is to compile and link the wrapper S-function. See "Compiling and Linking the Wrapper S-Function" on page 13-12.
Compiling and Linking the Wrapper S-Function
This topic describes how to create (compile and link) a C-MEX S-function from the sfun_atmos. c file. Before you start, ensure that the following files are in the working folder, xpc_fortran_test. You should have copied these files when you performed the steps in "Compiling Fortran Files" on page 13-7.
13-12
Step-by-Step Example of Fortran and xPC TargetTM
· libifcore. lib · libifcoremd. lib · ifconsol. lib · libifportmd. lib · libifport. lib · libmmd. lib · libm. lib · libirc. lib · libmmt. lib · libifcoremt. lib · svml_disp. lib Use the mex command with a C/C++ compiler such as Microsoft Visual C/C++ Version 6. 0. Invoking the mex command requires you to compile the wrapper C file sfun_atmos. c. Be sure to link in the following: · Compiled Fortran code: sfun_atmos_sub. obj · Necessary Fortran run-time libraries to resolve external function references and the Fortran run-time environment When you are ready, mex the code. For example
mex -v LINKFLAGS="$LINKFLAGS /NODEFAULTLIB:libcmt. lib libifcoremd. lib ifconsol. lib libifportmd. lib libmmd. lib libirc. lib svml_disp. lib" sfun_atmos. c sfun_atmos_sub. obj
Ensure that this whole command is all on one line. It creates the sfun_atmos. mex file in the same folder.
13-13
13
Incorporating Fortran Code into the xPC TargetTM Environment
Your next task is to validate the Fortran code and wrapper S-function. See "Validating the Fortran Code and Wrapper S-Function" on page 13-14.
Validating the Fortran Code and Wrapper S-Function
Validate the generated C-MEX S-function, sfun_atmos. mex. Bind the C-MEX S-function to an S-function block found in the Simulink block library. You can mask the S-function block like any other S-function block to give it a specific dialog box. This topic assumes that you have compiled and linked a wrapper S-function. See "Compiling and Linking the Wrapper S-Function" on page 13-12. The Atmosphere model example has a Simulink model associated with it.
1 In the MATLAB window, type
fortran_atmos_xpc
This opens the Simulink model associated with the Atmosphere model. This model includes the correct S-function block that is bound to
sfun_atmos. mex.
2 Select the Simulation menu Start option to simulate the model. 3 Examine the behavior of the Atmosphere model by looking at the signals
traced by the Scope block. Your next task is to prepare the model to build an xPC Target application. See "Preparing the Model for the xPC Target Application Build" on page 13-14.
Preparing the Model for the xPC Target Application Build
Before you build the Atmosphere model for xPC Target, define the following build dependencies: · The build procedure has access to sfun_atmos. sub. obj for the link stage.
13-14
Step-by-Step Example of Fortran and xPC TargetTM
· The build procedure has access to the Fortran run-time libraries (see "Compiling and Linking the Wrapper S-Function" on page 13-12) for the link stage. This topic assumes that you have validated the Fortran code and wrapper S-function (see "Validating the Fortran Code and Wrapper S-Function" on page 13-14).
1 In the MATLAB window, type
fortran_atmos_xpc
This opens the Simulink model associated with the Atmosphere model.
2 In the Simulink model, from the Simulation menu, click Configuration
Parameters. The Configuration Parameters dialog box appears.
3 In the left pane, click the Real-Time Workshop node.
The Real-Time Workshop pane opens.
4 In the Target selection section, click the Browse button at the System
target file list.
5 Click xpctarget. tlc. 6 In the Make command field, replace make_rtw with one for the Fortran
compiler.
make_rtw S_FUNCTIONS_LIB=". . \sfun_atmos_sub. obj . . \libifcoremt. lib . . \libmmt. lib . . \ifconsol. lib . . \libifport. lib . . \libirc. lib . . \svml_disp. lib"
Ensure that the whole command is all on one line.
7 Click Apply. 9 From the File menu, click Save.
13-15
13
Incorporating Fortran Code into the xPC TargetTM Environment
This command requires that the application build folder be the current folder (one level below the working folder, xpc_fortran_test). [. . . ] If mode is 'RS232', enter the baud rate for the connection between the host and target PC.
target_object_name Target object name as specified in the xPC
Target Explorer
18-164
xpctarget. xpc
Description
Constructor of a target object. You make changes to the target application by changing the target object using methods and properties. If you have one target PC, or if you designate a target PC as the default one in your system, use the syntax
target_object=xpctarget. xpc
If you have multiple target PCs in your system, use the following syntax to create the additional target objects.
target_object=xpctarget. xpc('mode', 'arg1', 'arg2')
If you have a target PC object in the xPC Target Explorer, you can use the following syntax to construct a corresponding target object from the MATLAB Command Window.
target_object=xpctarget. xpc('target_object_name')
Examples
Before you build a target application, you can check the connection between your host and target computers by creating a target object, then using the targetping method to check the connection.
tg = xpctarget. xpc xPC Object Connected Application tg. targetping ans = success
= Yes = loader
If you have a second target computer for which you want to check the connection, create a second target object. In the following example, the connection with the second target computer is an RS-232 connection.
18-165
xpctarget. xpc
tg1=xpctarget. xpc('RS232', 'COM1', '115200') xPC Object Connected Application
= Yes = loader
If you have an xPC Target Explorer target object, and you want to construct a corresponding target object in the MATLAB Command Window, use a command like the following:
target_object=xpctarget. xpc('TargetPC1')
See Also
xPC Target methods get (target application object), set (target application object), delete, and targetping.
18-166
xpctargetping
Purpose Syntax
Test communication between host and target PCs MATLAB command line
xpctargetping xpctargetping('mode', 'arg1', 'arg2')
Arguments
mode
Optionally, enter the communication mode:
TCPIP RS232
Enable TCP/IP connection with target PC. [. . . ]