canoe 官方出品的capl教程。
Preface..............................................................................................................................................................................IX
About This Book ............................................................................................................................................................IX
Organization ..................................................................................................................................................................IX
Acknowledgments .........................................................................................................................................................IX
Tell Us What You Think!.................................................................................................................................................X
1 Introduction to CAPL...................................................................................................................................................1
1.1 Evaluation Capability...........................................................................................................................................1
1.2 Simulation Capability...........................................................................................................................................1
1.3 Prerequisites for Using CAPL..............................................................................................................................2
1.4 Learning Steps ....................................................................................................................................................2
1.5 CAPL – Event-Driven Software ...........................................................................................................................3
1.6 CAPL Program Organization...............................................................................................................................3
1.7 Using the CAPL Browser for Program Development ..........................................................................................3
1.8 Program Development Uses the Database Tool – CANdb++.............................................................................3
1.9 CAPL Programming Knowledge..........................................................................................................................4
1.10 CAN Communication Knowledge ....................................................................................................................4
1.11 THE WARNING – Welcome to the Jungle.......................................................................................................4
1.12 Responsibility...................................................................................................................................................5
2 CANalyzer and CANoe...............................................................................................................................................6
2.1 One Key Difference – Level of Node Control ......................................................................................................6
2.2 Graphic Panels – The Other Major Difference ....................................................................................................7
3 A Brief Introduction to CANalyzer...............................................................................................................................9
3.1 Value of the Downloadable Demo.......................................................................................................................9
3.2 First-Time Considerations ...................................................................................................................................9
3.3 How to Start and Stop CANalyzer .....................................................................................................................10
3.4 The Architecture of CANalyzer..........................................................................................................................10
3.5 Measurement Setup Window ............................................................................................................................12
3.5.1 Trace Window ............................................................................................................................................12
3.5.2 Statistics Window .......................................................................................................................................12
3.5.3 Bus Statistics Window................................................................................................................................13
3.5.4 Data Window..............................................................................................................................................13
3.5.5 Graphics Window .......................................................................................................................................13
3.5.6 Write Window .............................................................................................................................................13
3.6 Duplicating Analysis Blocks...............................................................................................................................13
3.7 Controlling Data Flow ........................................................................................................................................13
3.8 Function Blocks .................................................................................................................................................13
3.8.1 Filtering Blocks...........................................................................................................................................14
3.8.2 Message Blocks .........................................................................................................................................15
3.9 Using CAPL Program Blocks in CANalyzer ......................................................................................................17
3.9.1 CANalyzer Program Blocks for Transmission............................................................................................18
3.9.2 Program Blocks for Analysis ......................................................................................................................19
3.10 CANalyzer – CAPL Programming Environment ............................................................................................20
4 A Brief Introduction to CANoe ..................................................................................................................................21
4.1 Value of the Downloadable Demo.....................................................................................................................21
4.2 First-Time Considerations .................................................................................................................................21
4.3 Learning from the Demo....................................................................................................................................22
4.4 Tool Architecture of CANoe...............................................................................................................................23
4.5 Using CAPL Program Blocks in CANoe............................................................................................................24
4.5.1 CANoe Program Blocks for Simulation ......................................................................................................24
4.5.2 CANoe Program Blocks for Analysis..........................................................................................................25
4.6 CANoe – CAPL Programming Environment .....................................................................................................25
5 Using Databases with CAPL ....................................................................................................................................26
5.1 Why Use a Database with CAPL?.....................................................................................................................26
5.1.1 Additional Uses of the Database................................................................................................................26
5.2 Database Association with CAPL......................................................................................................................26
5.3 Database Objects Accessible by CAPL ............................................................................................................27
5.3.1 Attributes ....................................................................................................................................................28
5.3.2 Value Tables ..............................................................................................................................................28
5.3.3 Network Nodes...........................................................................................................................................28
5.3.4 Messages...................................................................................................................................................28
5.3.5 Signals........................................................................................................................................................28
5.3.6 Environment Variables ...............................................................................................................................28
6 Using Panels with CAPL (CANoe only) ....................................................................................................................29
7 The CAPL Browser ...................................................................................................................................................30
7.1 Starting the CAPL Browser................................................................................................................................30
7.2 Browser Organization ........................................................................................................................................31
7.3 Using the Right Mouse Button...........................................................................................................................32
7.4 The Events Window...........................................................................................................................................32
7.4.1 Creating an Event Procedure .....................................................................................................................32
7.5 The Global Variables Window ...........................................................................................................................32
7.6 The Event Procedure Window...........................................................................................................................33
7.7 Colorized CAPL Syntax .....................................................................................................................................33
7.8 Compiling Code .................................................................................................................................................33
7.9 Fixing Compilation Errors ..................................................................................................................................34
7.10 Debugging Run-Time Errors ..........................................................................................................................34
7.11 Using Other Text Editors................................................................................................................................35
7.12 CAPL Source File Format ..............................................................................................................................35
8 CAPL Syntax and Semantics....................................................................................................................................37
8.1 Major CAPL Differences from C ........................................................................................................................37
8.2 CAPL Equivalents to C Functions .....................................................................................................................38
8.3 Notation .............................................................................................................................................................38
8.4 Comments .........................................................................................................................................................38
8.5 Naming Conventions .........................................................................................................................................39
8.6 CAPL is Case Sensitive.....................................................................................................................................39
8.7 CAPL Keywords.................................................................................................................................................39
8.8 Data Types ........................................................................................................................................................40
8.9 Declarations.......................................................................................................................................................41
8.9.1 Local Variables are Static...........................................................................................................................41
8.9.2 Initialization.................................................................................................................................................42
8.10 Type Casting ..................................................................................................................................................42
8.11 Arrays.............................................................................................................................................................42
8.12 Constants .......................................................................................................................................................43
8.12.1 Integer Constants .......................................................................................................................................43
8.12.2 Floating Point Constants ............................................................................................................................44
8.12.3 Character Constants...................................................................................................................................44
8.12.4 String Constants .........................................................................................................................................45
8.12.5 Symbolic Constants....................................................................................................................................45
8.13 Operators .......................................................................................................................................................46
8.13.1 Arithmetic Operators...................................................................................................................................46
8.13.2 Assignment Operators................................................................................................................................47
8.13.3 Boolean Operators .....................................................................................................................................48
8.13.4 Relational Operators ..................................................................................................................................49
8.13.5 Bitwise Operators .......................................................................................................................................50
8.13.6 Miscellaneous Operators............................................................................................................................50
8.13.7 Unsupported Operators..............................................................................................................................51
8.14 Control Statements ........................................................................................................................................51
8.14.1 Branching Statements ................................................................................................................................51
8.14.2 If Statement ................................................................................................................................................52
8.14.3 If-Else Statement........................................................................................................................................52
8.14.4 Switch Statement........................................................................................................................................53
8.15 Loops .............................................................................................................................................................54
8.15.1 While Statement .........................................................................................................................................54
8.15.2 Do–While Statement ..................................................................................................................................55
8.15.3 For Statement.............................................................................................................................................55
8.15.4 Unconditional Branching ............................................................................................................................56
8.15.5 Return Statement .......................................................................................................................................57
8.16 The “this” Keyword.........................................................................................................................................57
9 CAPL Functions ........................................................................................................................................................59
9.1 User-defined Functions......................................................................................................................................59
9.2 Function Overloading is Allowed .......................................................................................................................59
9.3 Function Naming Conventions ..........................................................................................................................60
9.4 CAPL Function Categories................................................................................................................................60
9.4.1 Mathematical Functions .............................................................................................................................60
9.4.2 User Interface Functions ............................................................................................................................61
9.4.3 Time Functions...........................................................................................................................................62
9.4.4 Message Handling Functions.....................................................................................................................63
9.4.5 Database Functions ...................................................................................................................................64
9.4.6 Byte Ordering Functions ............................................................................................................................64
9.4.7 Logging Functions......................................................................................................................................65
9.4.8 String Handling Functions ..........................................................................................................................66
9.4.9 Measurement Control Functions ................................................................................................................66
9.4.10 Statistics Functions ....................................................................................................................................67
9.4.11 CAN Protocol Functions.............................................................................................................................68
9.4.12 Port Functions ............................................................................................................................................69
9.4.13 Replay Block Functions..............................................................................................................................69
9.4.14 Environment Variable and Panel Functions (CANoe only) ........................................................................70
9.4.15 Miscellaneous Functions............................................................................................................................71
9.5 CAPL Function Compatibilities..........................................................................................................................72
10 CAPL Events and Event Procedures....................................................................................................................73
10.1 Creating an Event Procedure ........................................................................................................................74
10.2 Event Procedure Requirements.....................................................................................................................74
10.3 Some Event Procedures Use the Keyword “this” ..........................................................................................75
10.4 The * symbol..................................................................................................................................................75
10.5 Event Priority..................................................................................................................................................76
11 Using Messages....................................................................................................................................................78
11.1 Messages in CAPL ........................................................................................................................................78
11.1.1 Declaring Messages in CAPL with a Database .........................................................................................78
11.1.2 Declaring Messages in CAPL Without a Database....................................................................................79
11.1.3 Message Selectors.....................................................................................................................................79
11.2 Accessing Data ..............................................................................................................................................81
11.2.1 Using Signals (Only Available with a Database)........................................................................................82
11.2.2 Physical Values and the “phys” Attribute ...................................................................................................82
11.2.3 Round-Off Error in Symbolic Signal Access ..............................................................................................83
11.3 Message Transmission..................................................................................................................................83
11.4 Message Reception .......................................................................................................................................83
11.5 Error Frames..................................................................................................................................................86
11.5.1 Error Frame Event......................................................................................................................................86
12 Using Keyboard Events.........................................................................................................................................87
12.1 Keyboard Events and Procedures.................................................................................................................87
12.2 Using the Keyword “this” with the Wildcard Symbol “*” .................................................................................87
13 Using System Events ............................................................................................................................................89
13.1 Types of System Events ................................................................................................................................89
13.2 What Happens When a System Event Occurs?............................................................................................89
14 Using Timers .........................................................................................................................................................91
14.1 Declaring a Timer...........................................................................................................................................91
14.2 Starting a Timer .............................................................................................................................................91
14.3 Expiration of a Timer......................................................................................................................................91
14.4 Resetting a Timer...........................................................................................................................................92
14.5 Periodic Clock ................................................................................................................................................92
14.6 Stopping a Timer Before It Expires................................................................................................................92
14.7 Common Timer Mistake.................................................................................................................................92
15 Using CAN Protocol Controller Events .................................................................................................................94
15.1 CAN Controller States....................................................................................................................................94
15.2 CAN Controller Events...................................................................................................................................95
16 Using Environment Variables................................................................................................................................96
16.1 Environment Variable Types..........................................................................................................................97
16.2 Environment Variable Initialization.................................................................................................................97
16.3 Declaring an Environment Variable Event.....................................................................................................97
16.4 Event Execution .............................................................................................................................................98
16.5 The putValue() and getValue() Functions......................................................................................................98
16.6 The “this” Keyword.........................................................................................................................................98
17 Using File Input/Output Functions.......................................................................................................................100
17.1 File Input/Output Functions..........................................................................................................................100
17.1.1 Set-Up for File Input/Output Functions.....................................................................................................100
17.1.2 Set-Up for Sequential File Access Functions...........................................................................................101
18 Using the Serial and Parellel Port .......................................................................................................................103
18.1 Installation of RS232VC DLL .......................................................................................................................103
18.2 RS232 CAPL Functions ...............................................................................................................................103
18.2.1 RS232SetCommState ..............................................................................................................................103
18.2.2 RS232ByteCallback..................................................................................................................................104
18.2.3 RS232WriteByte.......................................................................................................................................104
18.2.4 RS232WriteBlock .....................................................................................................................................104
18.2.5 RS232EscapeCommFunc........................................................................................................................105
18.2.6 RS232CloseHandle..................................................................................................................................105
19 Constructing CAPL Programs .............................................................................................................................106
19.1 CAPL Program Organization .......................................................................................................................106
19.1.1 Creating Network Nodes ..........................................................................................................................106
19.1.2 P Block Placement and Message Pass-Through.....................................................................................107
20 CAPL Program Examples ...................................................................................................................................108
20.1 The Write() Function ....................................................................................................................................108
20.2 Sending a Periodic Message .......................................................................................................................108
20.3 Sending a Conditionally Periodic Message..................................................................................................110
20.4 Reading Data in a Received Message.........................................................................................................111
20.5 Responding to a Message After a Delay .....................................................................................................112
20.6 Sending an Error Frame ..............................................................................................................................113
20.7 Using Panels ................................................................................................................................................113
20.8 Bus Off Condition .........................................................................................................................................114
20.9 Using a CAPL Program to Control Logging .................................................................................................115
20.10 Data Files and CAPL....................................................................................................................................116
20.10.1 Set 1: File I/O Functions .......................................................................................................................117
20.10.2 Set 2: ProFile Functions .......................................................................................................................119
21 Basic Steps in Creating Your First CANoe Application.......................................................................................121
21.1 CANoe Development - Five Step Process...................................................................................................121
21.1.1 Create a New Directory ............................................................................................................................122
21.1.2 Creating a New CANoe Configuration......................................................................................................122
21.1.3 Bus Parameters........................................................................................................................................123
21.1.4 Set Up Analysis Functions .......................................................................................................................124
21.1.5 Working with the Analysis Windows.........................................................................................................125
22 Using CANdb++ to Create a Database...............................................................................................................126
22.1 CANdb++ Database Development...............................................................................................................126
22.2 Starting the CANdb++ Program ...................................................................................................................127
22.3 Defining Attributes........................................................................................................................................127
22.4 Defining Value Tables..................................................................................................................................128
22.5 Defining Nodes.............................................................................................................................................128
22.6 Defining Messages.......................................................................................................................................128
22.7 Defining Signals ...........................................................................................................................................129
22.8 Establishing Object Associations .................................................................................................................130
22.9 Defining Environment Variables...................................................................................................................130
22.10 Saving the Database....................................................................................................................................131
22.11 Associating a Database ...............................................................................................................................131
23 Using the Panel Editor to Create Panels.............................................................................................................132
23.1 What are Panels?.........................................................................................................................................132
23.2 Advantages of Using Panels........................................................................................................................133
23.3 Requirements...............................................................................................................................................133
23.3.1 Database Association...............................................................................................................................133
23.3.2 Environment Variables .............................................................................................................................133
23.4 Creating a New Panel ..................................................................................................................................134
23.4.1 Properties of the Panel.............................................................................................................................134
23.4.2 Using Elements ........................................................................................................................................135
23.5 Configuring Elements...................................................................................................................................135
23.5.1 Associating Elements...............................................................................................................................135
23.5.2 Alarms ......................................................................................................................................................136
23.6 Using Bitmaps..............................................................................................................................................138
23.6.1 Creating a Dynamic Bitmap .....................................................................................................................138
23.7 Associating Panels to CANoe......................................................................................................................139
24 Introduction To CAPL DLLs ................................................................................................................................140
24.1 DLL – Dynamic Link Library.........................................................................................................................140
24.2 CAPL DLLs ..................................................................................................................................................140
24.3 Performance ................................................................................................................................................140
24.3.1 Using Microsoft Visual C++ to Implement a CAPL DLL...........................................................................141
24.4 CAPL Export Table ......................................................................................................................................142
24.5 Project Configuration ...................................................................................................................................143
24.5.1 Compiling the DLL....................................................................................................................................143
24.6 Linking the CAPL DLL .................................................................................................................................143
24.6.1 CAN.ini File ..............................................................................................................................................144
24.6.2 DLL Search Sequence .............................................................................................................................144
24.6.3 Demo DLL and Source Code...................................................................................................................145
24.6.4 C++ Code.................................................................................................................................................146
24.6.5 Troubleshooting CAPL DLL Errors in the CAPL Browser........................................................................150
24.6.6 CAPL DLL Questions and Answers .........................................................................................................150
25 Introduction to COM............................................................................................................................................151
25.1 COM – Component Object Model................................................................................................................151
25.2 CANoe/CANalyzer as a COM server...........................................................................................................151
25.3 COM Server Registration.............................................................................................................................151
25.4 Using Microsoft Visual Basic to Access the COM server ............................................................................151
25.4.1 Project Configuration................................................................................................................................152
25.5 Controlling a Measurement..........................................................................................................................153
25.6 Accessing Communication Data..................................................................................................................153
25.7 Accessing Environment Variables (CANoe only) ........................................................................................155
25.8 Reacting to CANoe/CANalyzer events ........................................................................................................156
25.9 Calling CAPL Functions...............................................................................................................................157
25.10 Transmitting CAN Messages .......................................................................................................................159
25.11 COM Server Example in Microsoft Visual Basic..........................................................................................160
25.11.1 VB Source Code...................................................................................................................................161
26 Appendix A: Introduction to CAN Communications ............................................................................................166
26.1 The Distributed Application..........................................................................................................................166
26.2 Distributed Functions ...................................................................................................................................166
26.2.1 A Common Example of a Distributed Function ........................................................................................168
26.3 Partitioning Requires Addressing ................................................................................................................168
26.4 Distributed Functions Require a Transfer Dialog.........................................................................................169
26.5 A Distributed Function May Require File Transfer Capability......................................................................170
26.6 The Distributed Application and the OSI Seven-Layer Model .....................................................................171
26.6.1 Physical Layer ..........................................................................................................................................172
26.6.2 Data Link Layer - Data Transfer Structure ...............................................................................................172
26.6.3 Network Layer - Address Structure..........................................................................................................173
26.6.4 Transport Layer - Message Transfer Structure........................................................................................173
26.6.5 Session Layer - Conversation Structure ..................................................................................................173
26.6.6 Presentation Layer - Data Structure.........................................................................................................173
26.6.7 Application Layer - Application-to-Network Interface Structure ...............................................................173
26.7 Distributed Applications Require Data Structures .......................................................................................173
26.8 Understanding the CAN Protocol.................................................................................................................174
26.8.1 Key Attributes ...........................................................................................................................................174
26.8.2 Understanding the Basic Elements of the CAN Message........................................................................177
26.8.3 The CAN Error Frame ..............................................................................................................................179
26.8.4 CAN Error Counting .................................................................................................................................179
26.8.5 The CAN Receive State Machine ............................................................................................................179
26.8.6 The CAN Transmit State Machine ...........................................................................................................180
26.8.7 CAN Implementation Ingredients – CAN Controller, Software, Physical Layer.......................................181
26.8.8 CAN Physical Layer .................................................................................................................................182
26.8.9 Physical Layer Choices............................................................................................................................182
26.8.10 Basic CAN Physical Layer Principles ...................................................................................................182
26.8.11 CAN Controller – Dominant/Recessive Logic Levels ...........................................................................183
26.8.12 Common Dominant/Recessive Logic Implementations........................................................................184
26.8.13 The Common High-Speed, Two-Wire Differential Transceiver ............................................................185
26.8.14 The Common CAN Transfer Medium - Wire ........................................................................................185
26.9 First-Time CAN Steps ..................................................................................................................................188
26.9.1 Step One – Wiring First ............................................................................................................................188
26.9.2 Step Two – Add Modules Incrementally...................................................................................................188
26.9.3 Notes on Building Your Own CAN-Based Module ...................................................................................189
27 Appendix B: Abbreviations/Acronyms .................................................................................................................190
28 Appendix C: Glossary..........................................................................................................................................191
29 Index....................................................................................................................................................................195
1