Documente Academic
Documente Profesional
Documente Cultură
Program Structure and Data Types Program Structure and Data Types - continued C-Syntax
Parts marked with *) are not available for CANalyzer. Access to struct members: Operators
gMyStruct.aLong = 22; a = 23 + b; add and assign
Including other Files textually (CAPL Include)
Includes Constants */- multiplication, division, subtraction
{ const <type> = <val>; r = 37 % 7; modulo division for integer, here: 2
#include "MySource.cin" a++; b--; increment or decrement an integer type
} Events c+=22.0; increment and assignment
CAPL is 100% event driven, event handler syntax: -= *= /= decrement, multiplication, division and assignment
Global Variables, <type> = data type on <event type> [additional parameter]
variables { a==b comparison operator „equal“
{ // variable declaration < <= > >= ! = other comparison operators
<type> myVar[=val]; // elementary // program code ! (a<7) && (b>20) logical not(!), and (&&)
<type> myArray[10]; // array } || logical or
char myString[20] [="val"]; &|~ bitwise and, or, complement
} <event type>
^ bitwise exclusive or (XOR)
<type> a) System Events a = 2<<3; bit-shift left (afterwards a is 16)
► signed int(16), long(32), int64(64) ► key 'character' or * keyboard events
► unsigned byte(8), word(16), dword(32), qword(64) ► timer <tmr> Timer expired >> bit-shift right
► Floating point float(64), double(64) ► preStart pre measurement start Please note: Don’t mix up comparison (==) and assignment (=) operator!
► character char(8) ► start after measurement start
If Decision
► Messages message <CAN-id> name ► stopMeasurement before measurement stop if (c <= 50)
message <DBC-Name> name b) Value Objects { // if c <= 50
► Other types Associative Fields Help ► signal <sig> Signal value changed *) }
Domain specific types Help ► signal_update <sig> Signal write access *) Optional branches:
Values in round brackets: Number of bits (not in the source code!). ► sysvar <sys> System variable value changed else if ((c > 50) && (c <= 70))
All types are usable as local variables. ► sysvar_update <sys> System variable write access { // if c in [50,70]
elcount(myString) returns the array size. ► envvar Value change environment variable }
…
Please note: c) Messages else
► Local variables are implicitly static. ► message <msg> CAN1.frmStatus { … } // in all other cases
► No program statements prior to variable declarations ► message <id>-<id> 0x100-999 Switch Selection
► message * any message switch (c) // integer
Comments
{
… // rest of line is comment message [*] All messages, also those that are processed by
/* all inside is comment */ case 50: // if c==50: …
another event handler in this CAPL source code. …
Ctrl-k-c: comment the selected area This break; // leave this branch
Ctrl-k-u: uncomment Event data can be accessed via this. case 100:
case 101: // cntr==100 or cntr==101
Own Types – Enums on key * this = character break;
Type definition in the variables section: on signal this[.raw] = physical [raw] value *) …
enum eMyEnumType {eMyEnum1 [=1],eMyEnum2 [=2]}; on message this.<selector> default: // in all other cases
break;
Declaration of an enum variable & initialization: ► TIME measurement time }
enum eMyEnumType gMyEnum = eMyEnum1; ► ID CAN-ID
► DLC message length (data) For Loop
Usage:
► DIR RX, TX for (initialization; condition; modification):
if (gMyEnum == eMyEnum2)
► CAN channel number int i;
Own Types – Structs ► BYTE(0…7),
for (i=0; i<10; i=i+1)
{ // statements
Type definition in the variables section: WORD(0..6), }
struct DWORD(0…4),
{ QWORD(0) raw data While Loop
int anInt; while(c<50)
► Signals
long aLong; { // statements
on message <msg>
} MyStructType; }
{
Declaration of a struct variable and initialization: this.sigTemp
struct MyStructType gMyStruct [= {20,-1}]; Raw data of the temperature signal is returned (compare to “on signal this“).
Physical values are accessed with .phys.