Support Note |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ProblemHow do I convert from CAPL-scripts to USR-scripts?
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SolutionHow to convert a CAPL-script to USR-scriptThis document is under constant development, but if will take care of most
CAPL-scripts "out there"... Please observe the following before you start to convert your CAPL-code to USR-code:
EASY "SEARCH AND REPLACE" OPERATIONS.CAN messages
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
CAPL |
mstimer [timer]; | Millisecond timer in CAPL. |
| USR
|
timer [variable];
|
In USR the corresponding data type is called just
"timer". In USR a timer is *always* a millisecond resolution
timer.
"Just search and replace should be enough". |
| Example |
CAPL-example variables { mstimer t5; } |
USR-example variables { timer t5; } |
|
CAPL |
float [variable]; | Data type "float" is supported in CAPL. |
| USR
|
double [variable];
|
In USR the corresponding data type is called double.
"Just search and replace should be enough". |
| Example |
CAPL-example variables { float Control_Min=0.0; } |
USR-example variables { double Control_Min=0.0; } |
|
CAPL |
dword [variable]; | Data type "float" is supported in CAPL. |
| USR
|
int [variable];
|
In USR the corresponding data type is called int.
"Just search and replace should be enough". |
| Example |
CAPL-example variables { dword Control_Min = 122; } |
USR-example variables { int Control_Min = 122; } |
|
CAPL |
word [variable]; | Data type "word" is supported in CAPL. |
| USR
|
int [variable];
|
In USR the corresponding data type is called int.
"Just search and replace should be enough". |
| Example |
CAPL-example variables { word Control_Temp=13; } |
USR-example variables { int Control_Temp=13; } |
|
CAPL |
on message [message_name_in_CAPL] { /* bla blu blah */ } |
To trigger some action when a message has been received is
done with the function "on message". |
| USR |
on CanMessage [message_name_in_USR] { /* bla blu blah */ } |
Corresponding function is called "on
CanMessage". |
| Example
|
CAPL-example on message * { /* bla bla bla */ } on message AlphaFrame |
USR-example on CanMessage * { /* bla bla bla */ } on CanMessage AlphaFrame |
|
CAPL |
output([message_name_in_CAPL]); | To send a CAN-message from CAPL is done with the function "output". |
| USR | canSendMessage([message_name_in_USR]) | Corresponding function is called "on CanMessage". |
| Example |
CAPL-example output(this); output( DeltaFrame ); |
USR-example canSendMessage(this); canSendMessage( DeltaFrame ); |
|
CAPL |
write("[the text %x, %d, %f]", [comma sep. variables] ); | This is how you write something on the screen in CAPL. |
| USR | printf("[the text %x, %d, %f]", [comma sep. variables] ); | This is how you write something on the screen in USR. (Just like "C"). |
| Example |
CAPL-example write("Let's swap to Navigator"); write("the price is only %d !!!", (price-discount)); |
USR-example printf("Let's swap to Navigator"); printf("\n...the price is only %d !!!", (price-discount)); |
|
CAPL |
cancelTimer( [timer] ); |
[timer]: A timer declared in the variables
section. Most likely millesecond timers. |
| USR |
timerCancel( [timer] ); |
[timer]: A timer declared in the variables section. Always a millisecond timer. |
| Example
|
CAPL-example cancelTimer( aTimer ) |
USR-example timerCancel( aTimer ); |
CHANGES THAT REQUIRES SOME HANDS ON WORK.
|
CAPL |
msg.byte(x) | This is how a specific byte of a message is accessed in CAPL-script.. |
| USR | msg.data[x] | This is how a specific byte of a message is accessed in USR-script. |
| Example |
CAPL-example if (this.byte(2) == temperature) { /* bla bla bla */ } |
USR-example if (this.data[2] == temperature) { /* bla bla bla */ } |
|
CAPL |
SetTimer( [timer], [timeout value] ); |
[timer]: A timer declared in the variables section. Most
likely millesecond timers. [timeout value]: Depending of the type of timer the timeout for this timer will be a multipple of "timeout value". |
| USR |
timerSetTimeout([timer], [timeout value]); timerStart([timer]); |
[timer]: A timer declared in the variables section. Always
a millisecond timer. [timeout value]: Depending of the type of timer that was orginally in the CAPL-script you have to recalculate the timeout value. If the orignal CAPL-script timer was millisec-timer then nothing have to be recalculated. Note that you have to add a "timerStart([timer])" since the CAPL's "SetTimer" both initiates the timer and starts the timing. |
| Example
|
CAPL-example SetTimer( aTimer_6, 250 ); |
USR-example timerSetTimeout( aTimer_6, 250 ); timerStart( aTimer_6 ); |
|
CAPL |
[message_name_in_CAPL].[signal_in_db] = [value]; |
[message_name_in_CAPL]: The, in the variables list
declared meassage. [signal_in_db]: A signal in the specific CAN-message. [value]: The value to assign to the variable. |
| USR |
[message_name_in_USR].[signal_in_db].Raw = [value]; |
[message_name_in_USR]: The, in the variables list declared
meassage. [signal_in_db]: A signal in the specific CAN-message. [value]: The value to assign to the variable. The difference is that, in CAPL, the values are by default in Raw-mode. |
| Example |
CAPL-example BetaFrame.BetaFrameTemp = 0x10; |
USR-example BetaFrame.BetaFrameTemp.Raw = 0x10; |
|
CAPL |
on key [key-combination]{ /* bla bla bla */ } |
[key-combination]: The key/keys that are supposed to be
pressed to trigger a event. |
| USR |
on key [key-combination]{ /* bla bla bla */ } |
[key-combination]: The key/keys that are supposed to be
pressed to trigger a event. |
| Example |
CAPL-example The "Control"-key: cntrlF1
|
USR-example The "Control"-key: CTRL+F1 (Navigator understands both but it looks much better as Navigator prefers) KEY_PGUP (Navigator understands both but it looks much better
as |
|
CAPL |
[datatype] [function name]([comma sep. variables]) { /* bla bla bla */ } |
Note that a function that doesn't return a value doesn't
have to be declared as void in CAPL (no datatype is specified). |
| USR |
[datatype] [function name]([comma sep. variables]) { /* bla bla bla */ } |
If [datatype] is not given in the CAPL script you may set
the data type to void in the USR-script. All other datatypes should work just fine! |
| Example |
CAPL-example A_nice_function() { /* bla bla bla */ } |
USR-example void A_nice_function() { /* bla bla bla */ } |
|
CAPL |
myFunctionA{ int variable_1; /* bla bla bla */ } myFunctionB{ |
In CAPL, a locally defined variable is static. Not so in USR. Watch out for
local variables that are initialized. |
| USR |
myFunctionA{ int variable_1; /* bla bla bla */ } myFunctionB{ |
There will be a conflict between the two variables
variable_1 and variable_1 since they have the same name! |
|
CAPL |
variables { message kvaser_rulesA; message kvaser_rulesB; message kvaser_rulesC; message kvaser_rulesD; } on message kvaser_rules |
In CAPL you can to like this... |
| USR |
variables { CanMessage kvaser_rulesA; CanMessage kvaser_rulesB; CanMessage kvaser_rulesC; CanMessage kvaser_rulesD; } on message kvaser_rules |
... and in USR like this! |
|
CAPL |
if ([logical experssion]){ /* bla bla bla */ } |
Sometimes you have a logical expression to
test... |
| USR |
if ([logical experssion]){ /* bla bla bla */ } |
... and in USR like this! |
| Example | CAPL if ( A & B == C & D || E & F == G & H ) USR if ( ( ( A & B ) == ( C & D ) ) || ( ( E & F ) == ( G & H) ) ) |
Don't leave it like this! In USR you have the
same system as the "C" language! CAPL uses something
strange... For readability, use a lot of ( )! That's our advice! |
This is the old version of this document...
Change "msTimer" to "timer" in the declaration of a timer. All timers have millisecond resolution in USR.
If you have CAPL timers that are not millisecond-resolution timers, be sure to check all calls to setTimer(). to ensure the timeout is appropriately changed.
Note: don't call timerStart() on a timer that is already running in Navigator 1.7 or earlier.
Message declarations are different in USR. Change "message" to CanMessage in the declaration of the message. So this CAPL declaration:
message msg-definition msg;
is in USR
CanMessage_msg-definition msg;
Note the underscore between CanMessage and the name of the message definition!
CAPL: msg.byte(x) -> USR: msg.data[x];
CAPL: msg.word(x) doesn't exist in USR
CanMessage <file>::<message> msg qqq
msg1.SIMULATED and a few other special fields are not supported in USR.
In CAPL, a signal value is "raw" (i.e. not scaled) by default. This CAPL code
msg.signal = 34;
must be written like this in USR:
msg.signal.Raw = 34;
If you don't append the string ".Raw" you will see error E258 or
E271 in Navigator.
"on CanMessage <iface>.<message>" - not in USR
Declaration "CanMessage CAN1.* msg" not in USR
(If this occurs because you want to transmit on a specific CAN interface,
it's not needed in USR. Use canSendMessage() or canChannelSendMessage())
In USR, when a struct or array is passed to a function it is always passed by reference. So the following CAPL code
CheckSnapshot( message * msg )
{
// bla bla
}
is expressed like this in USR:
void CheckSnapshot( CanMessage msg )
{
// bla bla
}