3

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);
    }
}
Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
Luca
  • 39
  • 1
  • 6

1 Answers1

3

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)
Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
  • Thank you for your time and sorry for the late response. In the meantime i found the answer but i will try what you suggested also. What i did was to add the "output" syntax to each part where i was writing the signals so this becomes something like on enVar ev_signalY { MessageX.SignalY = (getValue(this)) output(messageX) } – Luca Jan 16 '21 at 12:07
  • @Luca Which is perfectly fine and not much different from the solution I am proposing. The button updates the envvar and you output it, instead of using a sysvar. Please note that since version 11.0+ CANoe is starting to mark the envvars as to be removed in a future release and be replaced by sysvars only. Still, if you think this can be accepted as answer, please [do so](https://stackoverflow.com/help/someone-answers), or post your method as answer instead – Daemon Painter Jan 18 '21 at 07:51