Transcription of Programming with CAPL - can-newsletter.org
1 The art of engineeringProgramming with CAPLCAN alyzerCANoe Programming With CAPL December 14, 2004 First printing Vector CANtech, Inc. Suite 550 39500 Orchard Hill Place Novi, MI 48375 USA II 2004, 2005 Vector CANtech, Inc Novi, Michigan 48375 USA The authors and publishers have used their best efforts in preparing this book. These efforts include development, research, and testing of the theories, principles, and Programming sample code so as to determine their effectiveness. The authors and/or publishers make no warranty, expressed or implied, with regard to the sample code or to any other documentation contained in this book.
2 The authors and/or publishers shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of the sample code or any of the contents of this book. All rights reserved. No part of this book may be reproduced, in any form or by any means, without express permission in writing from Vector CANtech, Inc. Table of Contents About This Book ..IX Organization ..IX Acknowledgments ..IX Tell Us What You Think!..X 1 Introduction to 1 Evaluation Capability .. 1 Simulation Capability .. 1 Prerequisites for Using 2 Learning Steps.
3 2 CAPL Event-Driven Software .. 3 CAPL Program Organization .. 3 Using the CAPL Browser for Program Development .. 3 Program Development Uses the Database Tool CANdb++.. 3 CAPL Programming 4 CAN Communication Knowledge .. 4 THE WARNING Welcome to the 4 5 2 CANalyzer and CANoe .. 6 One Key Difference Level of Node Control .. 6 Graphic Panels The Other Major Difference .. 7 3 A Brief Introduction to CANalyzer .. 9 Value of the Downloadable 9 First-Time Considerations .. 9 How to Start and Stop CANalyzer .. 10 The Architecture of 10 Measurement Setup Window.
4 12 Trace Window .. 12 Statistics Window .. 12 Bus Statistics Window .. 13 Data Window .. 13 Graphics Window .. 13 Write Window .. 13 Duplicating Analysis 13 Controlling Data Flow .. 13 Function Blocks .. 13 Filtering Blocks .. 14 Message Blocks .. 15 Using CAPL Program Blocks in CANalyzer .. 17 CANalyzer Program Blocks for Transmission .. 18 Program Blocks for Analysis .. 19 CANalyzer CAPL Programming Environment .. 20 4 A Brief Introduction to CANoe .. 21 Value of the Downloadable 21 First-Time Considerations .. 21 Learning from the 22 Tool Architecture of 23 Using CAPL Program Blocks in CANoe.
5 24 CANoe Program Blocks for Simulation .. 24 CANoe Program Blocks for 25 CANoe CAPL Programming Environment .. 25 5 Using Databases with CAPL .. 26 Why Use a Database with CAPL?.. 26 Additional Uses of the 26 Database Association with 26 Database Objects Accessible by CAPL .. 27 Attributes .. 28 Value Tables .. 28 Network 28 Messages .. 28 IV Signals ..28 Environment Variables ..28 6 Using Panels with CAPL (CANoe only) ..29 7 The CAPL Browser ..30 Starting the CAPL Browser Organization ..31 Using the Right Mouse Button ..32 The Events Creating an Event Procedure.
6 32 The Global Variables Window ..32 The Event Procedure Colorized CAPL Syntax ..33 Compiling Code ..33 Fixing Compilation Errors ..34 Debugging Run-Time Errors ..34 Using Other Text CAPL Source File Format ..35 8 CAPL Syntax and Major CAPL Differences from C ..37 CAPL Equivalents to C Functions ..38 Notation ..38 Comments ..38 Naming Conventions ..39 CAPL is Case CAPL Data Types ..40 Declarations ..41 Local Variables are Type Casting ..42 Arrays ..42 Constants ..43 Integer Constants ..43 Floating Point Constants ..44 Character String Constants.
7 45 Symbolic Operators ..46 Arithmetic Assignment Boolean Operators ..48 Relational Operators ..49 Bitwise Operators ..50 Miscellaneous Unsupported Operators ..51 Control Statements ..51 Branching Statements ..51 If Statement ..52 If-Else Statement ..52 Switch Loops ..54 While Statement ..54 Do While Statement ..55 For Unconditional Branching ..56 Return Statement ..57 The this Keyword ..57 9 CAPL Functions ..59 User-defined Function Overloading is Allowed ..59 Table of Contents Function Naming Conventions .. 60 CAPL Function Categories.
8 60 Mathematical Functions .. 60 User Interface Functions .. 61 Time 62 Message Handling 63 Database Functions .. 64 Byte Ordering Functions .. 64 Logging Functions .. 65 String Handling Functions .. 66 Measurement Control Functions .. 66 Statistics Functions .. 67 CAN Protocol Functions .. 68 Port Functions .. 69 Replay Block 69 Environment Variable and Panel Functions (CANoe only) .. 70 Miscellaneous Functions .. 71 CAPL Function 72 10 CAPL Events and Event Procedures .. 73 Creating an Event Procedure .. 74 Event Procedure 74 Some Event Procedures Use the Keyword this.
9 75 The * symbol .. 75 Event 76 11 Using 78 Messages in CAPL .. 78 Declaring Messages in CAPL with a Database .. 78 Declaring Messages in CAPL Without a 79 Message 79 Accessing Data .. 81 Using Signals (Only Available with a Database).. 82 Physical Values and the phys Attribute .. 82 Round-Off Error in Symbolic Signal Access .. 83 Message Transmission .. 83 Message Reception .. 83 Error 86 Error Frame 86 12 Using Keyboard 87 Keyboard Events and Procedures .. 87 Using the Keyword this with the Wildcard Symbol * .. 87 13 Using System Events .. 89 Types of System Events.
10 89 What Happens When a System Event Occurs?.. 89 14 Using Timers .. 91 Declaring a 91 Starting a Timer .. 91 Expiration of a 91 Resetting a 92 Periodic Clock .. 92 Stopping a Timer Before It 92 Common Timer 92 15 Using CAN Protocol Controller Events .. 94 CAN Controller 94 CAN Controller 95 16 Using Environment 96 Environment Variable 97 Environment Variable 97 Declaring an Environment Variable Event .. 97 Event Execution .. 98 The putValue() and getValue() 98 VI The this Keyword ..98 17 Using File Input/Output Functions ..100 File Input/Output Functions.