Xpc Target API Ugref Oct2002

  • View
    41

  • Download
    5

Embed Size (px)

Text of Xpc Target API Ugref Oct2002

xPC TargetFor Use with Real-Time Workshop

API Users and Reference GuideVersion 2

How to Contact The MathWorks:www.mathworks.com comp.soft-sys.matlab support@mathworks.com suggest@mathworks.com bugs@mathworks.com doc@mathworks.com service@mathworks.com info@mathworks.com

Web Newsgroup Technical support Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information Phone Fax Mail

508-647-7000 508-647-7001 The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098

For contact information about worldwide offices, see the MathWorks Web site. xPC Target API Users and Reference Guide COPYRIGHT 2002 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. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by or for the federal government of the United States. By accepting delivery of the Program, the government hereby agrees that this software qualifies as "commercial" computer software within the meaning of FAR Part 12.212, DFARS Part 227.7202-1, DFARS Part 227.7202-3, DFARS Part 252.227-7013, and DFARS Part 252.227-7014. The terms and conditions of The MathWorks, Inc. Software License Agreement shall pertain to the governments use and disclosure of the Program and Documentation, and shall supersede any conflicting contractual terms or conditions. If this license fails to meet the governments minimum needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to MathWorks. MATLAB, Simulink, Stateflow, Handle Graphics, and Real-Time Workshop are registered trademarks, and Target Language Compiler is a trademark of The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective holders.

Printing History: July 2002 October 2002

Online only Online only

New for Version 2 (Release 13) Updated for Version 2 (Release 13)

ContentsPreface

Required Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi Using This Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . viii

Introduction

1xPC Target API versus xPC Target COM API . . . . . . . . . . . . 1-2 What Is xPC Target API? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 What Is xPC Target COM API? . . . . . . . . . . . . . . . . . . . . . . . . . 1-6

xPC Target API

2Before You Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Important Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Visual C Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Directories and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Building the xPC Target Application . . . . . . . . . . . . . . . . . . . . . 2-6 Creating a Visual C Application . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Building a Visual C Application . . . . . . . . . . . . . . . . . . . . . . . . 2-10 Running a Visual C xPC Target API Application . . . . . . . . . . 2-11

i

Using the xPC Target API C Application . . . . . . . . . . . . . . . . . 2-11 C Code for sf_car_xpc.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17

xPC Target COM API

3Before You Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Example Visual Basic GUI Using COM Objects . . . . . . . . . . . 3-3 Description of Simulink Water Tank Model . . . . . . . . . . . . . . . . 3-4 Creating a Simulink Target Model . . . . . . . . . . . . . . . . . . . . . . . 3-6 Tagging Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Tagging Block Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10 Creating the Target Application and Model-Specific COM Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14 Model-Specific COM Interface Library (model_nameCOMiface.dll) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17 Creating a New Visual Basic Project . . . . . . . . . . . . . . . . . . . . 3-19 Referencing the xPC Target COM API and Model-Specific COM Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20 Creating the Graphical Interface . . . . . . . . . . . . . . . . . . . . . . . 3-24 Setting Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27 Writing Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29 Creating the General Declarations . . . . . . . . . . . . . . . . . . . . . . 3-30 Creating the Load Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . 3-31 Creating Event Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32 Referencing Parameters and Signals Without Using Tags . . . 3-39 Building the Visual Basic Application . . . . . . . . . . . . . . . . . . . 3-43 Deploying the API Application . . . . . . . . . . . . . . . . . . . . . . . . . 3-43

xPC Target API Function Reference

4Alphabetical Listing of Functions and Structures . . . . . . . . 4-2

ii

Contents

Categorical Listing of Functions and Structures . . . . . . . . . 4-9 Logging and Scope Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9 Communications Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10 Target Application Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11 Data Logging Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12 Scope Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13 Target Scope Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15 Monitoring/Tuning Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15 Miscellaneous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16 xPC Target API Error Messages . . . . . . . . . . . . . . . . . . . . . . . 4-17

iii

iv

Contents

.

PrefaceThe xPC Target API and xPC Target COM API libraries enable you to write custom applications to control real-time MATLAB Simulink applications running on a target PC. This chapter includes the following sections: Required Products (p. vi) Using This Guide (p. vii) Products from The MathWorks and third-party products you need to use with xPC Target Suggestions for learning about xPC Target, description of the chapters in this guide, and terms that may have various meanings Text formats in this guide

Typographical Conventions (p. viii)

Preface

Required ProductsRefer to the preface of the xPC Target Getting Started Guide for a list of the required xPC Target products. In addition, you need the following products: Third-Party Compiler Use a third-party compiler to build a custom application that calls functions from the xPC API library. Although the xPC API library is written in C, you can write the application that calls these functions in another high-level language, such as C++. You can use any compiler that can generate code for Win32 systems. To write a non-C application that calls functions in the xPC Target API library, refer to the compiler documentation for a description of how to access functions from a library DLL. You must follow these directions to access the xPC Target API DLL. Third-Party Graphical Development Environment Use a third-party graphical development environment to build a custom application that references interfaces in the xPC COM API library. Layered on top of the xPC API library, the xPC COM API library enables you to write custom applications using a component object model library. You can use any compiler that can work with component object model (COM) objects.

vi

Using This Guide

Using This GuideTo help you read and use this guide effectively, this section provides a brief description of the chapters. The following table lists the organization of this xPC Target Users and Reference Guide.Chapter Description

Chapter 1, Introduction

This chapter is an overview of the xPC Target API and xPC Target COM API libraries. This chapter describes how to use the xPC Target API library, including how to create, build, and run such an application. This chapter describes how to use the xPC Target COM API library, including how to create, build, and run such an application. This chapter describes the xPC Target API library, including function synopses and error returns.

Chapter 2, xPC Target API Chapter 3, xPC Target COM API Chapter 4, xPC Target API Function Reference

vii

Preface

Typographical ConventionsThis manual uses some or all of these conventions.Item Convention Monospace font Example

Example code

To assign the value 5 to A, enterA = 5

Function names, syntax, filenames, directory/folder names, and user input

Monospace font

The cos function finds the cosine of each array element. Syntax line example isMLGetVar ML_var_name

Buttons and keys Literal strings (in syntax descriptions in reference chapters) Mathematical expressions MATLAB output

Boldface with book title capsMonospace bold for literals

Press the Enter key.f = freqspace(n,'whole')

Italics for