I found a pretty helpful CAPL programming tutorial pdf on here, which has helped me get started with CAPL very quickly.
However, I'm trying to pass a message to another function as an argument, and I can't seem to get this right. I'm basically just trying to do a simple loopback from CAN1 to CAN2. Note: the commented out code in "on message CAN1.vtmCmd1" loopback code works, but I would preferably like to use functions to organize my test cases.
Here is my code.
Code:
on message CAN1.vtmCmd1
{
//Loopback for 1 second, fault for 600ms.
invalid_test_0x232(this);
/* message *gatewayMsg;
gatewayMsg = this;
gatewayMsg.CAN = 2;
output(gatewayMsg);
*/
}
Code:
void invalid_test_0x232(message vtmCmd1 tmCmd1){
int tm;
char test_state = 0;
char alive_counter;
//configure pkt to loop out to CAN2
tmCmd1.CAN = 2;
output(tmCmd1);
---------- Post added at 20:00 ---------- Previous post was at 19:56 ----------
ah, I just figured it out. Turns out you have to create a "pointer" or another instance for the gateway message inside my function: For future references, here is the code that i got it to work:
Code:
void invalid_test_0x232(message vtmCmd1 tmCmd1){
int tm;
char test_state = 0;
char alive_counter;
//configure pkt to loop out to CAN2
//tmCmd1.CAN = 2;
//output(tmCmd1);
message *gMsg;
gMsg = tmCmd1;
gMsg.CAN = 2;
output(gMsg);
/*
}
Hi there, I, too was unable to find out a way on how to return a message, but I did find a discovery that might help solve your problem.
I noticed that if you pass a specific message to a function, it seems to retrieve it as a pointer, allowing you to modify its contents without having to return it.
For example, this is a simple test I did. note that I am sending a constant value of 1 for my gear_cmd from my CAN device connected to my Cancase logger
Thank you very much! I had a though that this might be the case, but I have not yet had the possibility to try it out, but I will try to do that now. Thanks for your help!
How do you use "Value Table" parameters in CAPL scripts. For example, if I have a message signal pwr_state associated with a value table with values {ON, OFF, ERROR}
how do I do something like: message.pwr_state = ON;
enum State {isOn, isOff, isError};
enum State state;
state = (enum State) isOn;
switch (state) {
case isOn:
write("It is on.");
break;
case isOff:
write("It is off.");
break;
case isError:
write("There is an error.");
break;
}
if (state == isOn)
write("OK");
enum State {isOn, isOff, isError};
enum State state;
state = (enum State) isOn;
switch (state) {
case isOn:
write("It is on.");
break;
case isOff:
write("It is off.");
break;
case isError:
write("There is an error.");
break;
}
if (state == isOn)
write("OK");
Did that code actually work? I'll have to give it a try tomorrow. Last time I looked at the programming reference, CAPL doesn't support enums. Nevertheless, I think it is still more convenient to grab values strait from the value table into CAPL scripts
I have to say that I never tried it, but it does compile and enums are supported in CAPL according to the help file. (I'm using CANalyzer 7.2 if that matters.)