Products & Services Solutions Academia Support User Community Company

Learn more about xPC Target   

Working with Target Objects

Accessing Help for Target Objects

See Function Reference and Functions for a reference of the target object functions.

The target application object methods allow you to control a target application on the target PC from the host PC. You enter target application object methods in the MATLAB window on the host PC or use M-file scripts. To access the M-file help for these methods, use the syntax

help xpctarget.xpc/method_name

If you want to control the target application from the target PC, use target PC commands. See Using the Target PC Command-Line Interface.

Creating Target Objects

To create a target object, perform the following

  1. Build a target application. the xPC Target software creates a target object during the build process.

  2. To create a single target object, or to create multiple target objects in your system, use the target object constructor function xpc (see xpctarget.xpc) as follows. For example, the following creates a target object connected to the host through an RS-232 connection. In the MATLAB Command Window, type

    tg = xpctarget.xpc('rs232', 'COM1', '115200')

    The resulting target object is tg.

  3. To check a connection between a host and a target, use the target function targetping. For example,

    tg.targetping

      Note   To ensure that you always know which target PC is associated with your target object, you should always use this method to create target objects.

  4. To create a single target object, or to create the first of many targets in your system, use the target object constructor function xpctarget.xpc as follows. In the MATLAB Command Window, type

    tg = xpctarget.xpc

    The resulting target object is tg.

Deleting Target Objects

To delete a target object, use the target object destructor function delete . In the MATLAB window, type

tg.delete

If there are any scopes, file system, or FTP objects still associated with the target, this function removes all those scope objects as well.

Displaying Target Object Properties

You might want to list the target object properties to monitor a target application. The properties include the execution time and the average task execution time.

After you build a target application and target object from a Simulink model, you can list the target object properties. This procedure uses the default target object name tg as an example.

  1. In the MATLAB window, type

    tg

    The current target application properties are uploaded to the host PC, and MATLAB displays a list of the target object properties with the updated values.

    Note that the target object properties for TimeLog, StateLog, OutputLog, and TETLog are not updated at this time.

  2. Type

    +tg

    The Status property changes from stopped to running, and the log properties change to Acquiring.

For a list of target object properties with a description, see the target object function get (target application object).

Setting Target Object Properties from the Host PC

You can change a target object property by using the xPC Target software set method or the dot notation on the host PC. (See User Interaction in the xPC Target Getting Started Guide guide for limitations on target property changes to sample times.)

With the xPC Target software you can use either a function syntax or an object property syntax to change the target object properties. The syntax set(target_object, property_name,new_property_value) can be replaced by

target_object.property_name = new_property_value 

For example, to change the stop time mode for the target object tg,

When you change a target object property, the new property value is downloaded to the target PC. The xPC Target kernel then receives the information and changes the behavior of the target application.

To get a list of the writable properties, type set(target_object). The build process assigns the default name of the target object to tg.

Getting the Value of a Target Object Property

You can list a property value in the MATLAB window or assign that value to a MATLAB variable. With the xPC Target software you can use either a function syntax or an object property syntax.

The syntax get(target_object, property_name) can be replaced by

target_object.property_name

For example, to access the stop time,

To get a list of readable properties, type target_object. Without assignment to a variable, the property values are listed in the MATLAB window.

Signals are not target object properties. To get the value of the Integrator1 signal from the model xpcosc,

Using the Method Syntax with Target Objects

Use the method syntax to run a target object method. The syntax method_name(target_object, argument_list) can be replaced with

target_object.method_name(argument_list)

Unlike properties, for which partial but unambiguous names are permitted, you must enter method names in full, and in lowercase. For example, to add a scope of type target with a scope index of 1,

  


Related Products & Applications

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