| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → xPC Target |
| Contents | Index |
| Learn more about xPC Target |
| On this page… |
|---|
During the build process, the xPC Target software creates a target object that represents the target application running on the target PC. The target object is defined by a set of properties and associated methods. You control the target application and computer by setting the target object properties.
For procedures to simulate your model in nonreal time, see Simulating the Model.
This procedure assumes you have created an xPC Target boot disk and you have booted the target PC. See Booting Target PCs from Boot Floppy Disk. While the xPC Target Explorer gives you access to build and download a target application, this procedure begins with a target application already downloaded to the target PC (see xPC Target Application). For a description of how to download a prebuilt target application, see Downloading and Running Target Applications on a Target PC.
xpcexplr
The xPC Target Explorer window opens.
To connect to the target PC, right-click the target PC icon for which you have downloaded the application and select Connect.
To view the model hierarchy for the downloaded application, one of the following must be true:
You must be in the same folder in which you build the target application. Otherwise, xPC Target Explorer returns an error.

When you built the target application, you selected the Include model hierarchy on the target application check box in the xPC Target Options pane.
If you are in the appropriate folder, a node for the target application appears in the xPC Target Hierarchy under the target PC node and displays information about the previously loaded target application.

Note, if, in your current folder, you have a prebuilt target application that you want to download to the target PC, left-click and drag the desired target application to the target PC to which you want to download the target application.
If you want to rebuild the current target application, in the xPC Target Explorer window, right-click the target application node and select Go To Simulink Model.
The Simulink window opens for that model.

To rebuild the target application, in the Simulink window and from the Tools menu, select Real-Time Workshop. From the Real-Time Workshop submenu, click Build Model.
The xPC Target software recompiles, links, and downloads the target application to the target PC.
Start the target application. For example, in the xPC Target Explorer window, select the downloaded target application.
From the toolbar, click the Start
Application button
. The target application
begins running on the target PC, and stops when it reaches the stop
time.
With the target application still selected in the Target Hierarchy pane of xPC Target Explorer, enter a new value for the Stop time value for the application and click Apply. For example,
inf

Again, click the Start Application button. The target application now runs until you stop it.
See also Signal Tracing with xPC Target Explorer and Signal Logging with xPC Target Explorer in the xPC Target User's Guide.
This topic describes how to change folder to one that contains the prebuilt target applications (DLMs) you want to download to your target PCs and how to download and run a prebuilt target application. To view the model hierarchy, you must be in the same folder in which you build the target application. This topic assumes the following:
In your current working folder, you have a prebuilt target application that you want to download to a target PC.
You have installed xPC Target software and booted the target PC to which you want to download a target application.
You have a physical connection between the xPC Target Explorer host machine and the target PC to which you want to download a target application.
In the xPC Target Explorer, left-click the File menu. (Note that you can also change this folder from the MATLAB window or by right-clicking the DLM node.)
Select Change Host PC Current Working Directory.
A browser is displayed.
Browse to the folder that contains the prebuilt target applications you want.
A list of the prebuilt target applications appears, as shown.

In xPC Target Explorer, check that the DLM(s) node in the xPC Target Hierarchy has the pathname of the folder that contains the prebuilt target application you want to download to the target PC.

Right-click a target PC that you booted with xPC Target software, for example, TargetPC1.
The target PC icon changes and the red X is removed
. The target PC information
changes to reflect file system and PCI device information.
Left-click and drag the desired target application to the target PC to which you want to download the target application.
xPC Target Explorer downloads the target application to the target PC. A node for the target application appears in the xPC Target Hierarchy under the target PC node.

Alternatively, you can now drag a prebuilt target application, DLM, to a target PC icon. If a connection does not already exist, xPC Target Explorer optionally creates a connection to that target PC.
In xPC Target Explorer, right-click the downloaded target application node. For example, xpcosc.
The context menu appears and lists the operations you can perform on the target application.

xPC Target Explorer starts running the loaded target application.
Stop the target application (described here) or let the target application run to the end. To stop the target application, right-click the target application node (for example, xpcosc) and select Stop from the list.
See also Signal Tracing with xPC Target Explorer and Signal Logging with xPC Target Explorer within Signals and Parameters in the xPC Target User's Guide.
This topic describes how to manipulate target application properties. It assumes that you have already downloaded the target application xpcosc to a target PC.
In xPC Target Explorer, select the node of the loaded target application in which you are interested. For example, xpcosc.
The right pane changes to the target application properties pane for the application.
In this pane, you can change the following application properties:
Stop time
Sample time
Log mode
See User Interaction for limitations on changing sample times.
Change the Stop time parameter to 9999. Click Apply. For example,

You run your target application in real time to observe the behavior of your model with generated code.
After the xPC Target software downloads your target application to the target PC, you can run the target application. This procedure uses the Simulink model xpc_osc3.mdl as an example, and assumes you have created and downloaded the target application for that model. It also assumes that you have assigned tg to the appropriate target PC.
In the MATLAB window, type any of
+tg or tg.start or start(tg)
The target application starts running on the target PC. In the MATLAB window, the status of the target object changes from stopped to running.
xPC Object Connected = Yes Application = xpc_osc3 Mode = Real-Time Single-Tasking Status = running
On the target PC screen, the Execution line changes from stopped to running and the AverageTET line is periodically updated with a new value.

-tg or tg.stop or stop(tg)
The target application stops running.
The xPC Target software allows you to change many properties and parameters without rebuilding your target application. Two of these properties are StopTime and SampleTime.
Change the stop time. For example, to change the stop time to 1000 seconds, type either
tg.StopTime = 1000 or set(tg,'StopTime',1000)
Change the sample time. For example, to change the sample time to 0.01 seconds, type either
tg.SampleTime = 0.01 or set(tg, 'SampleTime', 0.01)
Although you can change the sample time between different runs, you can only change the sample time without rebuilding the target application under certain circumstances.
If you choose a sample time that is too small, a CPU overload can occur. If a CPU overload occurs, the target object property CPUOverload changes to detected. In that case, change the Fixed step size in the Solver node to a larger value and rebuild the model. (See User Interaction for further limitations on changing sample times.)
Control of your xPC Target application with Simulink is limited to connecting a Simulink model to a target application through external mode, and starting the target application. Using Simulink external mode is one method to tune parameters. In Simulink external mode, the model can only connect to the default target PC.
After you create and download a target application to the target PC, you can run the target application. This procedure uses the Simulink model xpc_osc2.mdl as an example (see Building and Downloading the Target Application). It assumes that you have specified the correct target PC environment on the xPC Target options node of the Real-Time Workshop parameters dialog. In particular, you must specify the target PC to which you want to connect. See the Use the default target PC check box description in xPC Target Options.
In the Simulink window, and from the Simulation menu, click External.
A check mark appears next to the menu item External, and Simulink external mode is activated. Simulink external mode connects your Simulink model to your target application as a simple graphical user interface.
In the Simulink window, and from the Simulation menu, click Connect to target.
All the current Simulink model parameters are downloaded to your target application. This downloading guarantees the consistency of the parameters between the host model and the target application.
From the Simulation menu, click Start real-time code.
The target application begins running.
tg.stop or -tg
You cannot stop the target application from the Simulink window by clicking Stop real-time code from the Simulation menu.
Note Opening a dialog box for a source block causes Simulink to pause. While Simulink is paused, you can edit the parameter values. You must close the dialog box to have the changes take effect and allow Simulink to continue. |
![]() | xPC Target Application | Menu Bar and Toolbar Contents and Shortcut Keys | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |