Search code examples
caplcanoe

CAPL Code to send signal value from a button


I am using CANoe 11.0 to send a signal value from a button.

I have a message from a CAN db with 6 signals, 8 bits for each signal. The message is cyclic but with a cycle time of 0ms, so, in order to send it, I figured out I need a button. But everything I tried so far doesn't work.

eg:

on message X
{
    if (getValue(ev_button) == 1)
    {
        X.signalname = (getValue(ev_signalvariable));
    }
}

or I tried working on the signal itself:

on signal Y
{
    if (getValue(ev_button) == 1)
    {
        putValue(ev_signalY,this);
    }
}

Solution

  • The issue you are having is due to the callback. Both on message and on signal callbacks happen when that message or signal is updated on the bus.

    In your code, you expect to update a signal, if you pressed a button, but only if you detect that signal was updated in the first place. Do you see the loophole?

    To fix this, you may create a system variable, associate that with the button (so that it is 0 = not pressed and 1 = pressed), then use the on sysvar callback:

    on sysvar buttonPressed
    {
        // prepare message
        // send message
    }
    

    I assume you already have something like message yourMessage somewhere, and that you know the name of the signal from the DBC and that the DBC is linked to your configuration. So you'll need to:

    // prepare message
    yourMessage.yourValue1 = <some value>
    yourMessage.yourValue2 = <some other value>
    // ...
    // repeat for all relevant signals
    

    and then

    // send message
    send(yourMessage)