-2

I am trying to pull a signal value (from a DBC file) into a variable but I get the message "Must be constant expression". If I try adding a filter like .DefaultValue, it works but that isn't the value I want. I want the value of the signal at the time of me calling this CAPL function. Here is an example:

float Cell_Voltage = Mc00_UCell00; (this is where I get error of must be constant expression)

float Cell_Voltage = Mc00_UCell00.DefaultValue; (this works but I don't want the default value)

Is there a filter to pull the current value of the signal Mc00_UCell0?

dhilmathy
  • 2,800
  • 2
  • 21
  • 29
Trace Lapid
  • 1
  • 1
  • 2

2 Answers2

1

In CAPL to get integer of float signal value you should write

float Cell_Voltage = $Mc00_UCell00;

It is called "Direct access to signal values"

0

You say the following works:

float Cell_Voltage = Mc00_UCell00.DefaultValue; 

and the following doesn't work:

float Cell_Voltage = Mc00_UCell00; 

Note that in C and many other languages, a dot indicates that from a structure a member is accessed. That would mean that in the working example you access a member and assign that to Cell_Voltage and in the not-working example you want to assign a whole strucure to a simple variable, and that indeed won't work.

Decide which member of the structure you need, and address that with the dot notation.

Paul Ogilvie
  • 25,048
  • 4
  • 23
  • 41