[英]Putting a signal value into a variable in CAPL
I am trying to pull a signal value (from a DBC file) into a variable but I get the message "Must be constant expression" .我正在尝试将信号值(从 DBC 文件)提取到变量中,但收到消息“必须是常量表达式” 。 If I try adding a filter like
.DefaultValue
, it works but that isn't the value I want.如果我尝试添加像
.DefaultValue
这样的过滤器,它会起作用,但这不是我想要的值。 I want the value of the signal at the time of me calling this CAPL function.我想要调用这个CAPL函数时的信号值。 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
?是否有过滤器来拉取信号
Mc00_UCell0
的当前值?
In CAPL to get integer of float signal value you should write在 CAPL 中获得浮点信号值的整数,你应该写
float Cell_Voltage = $Mc00_UCell00;
It is called "Direct access to signal values"它被称为“直接访问信号值”
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.请注意,在 C 和许多其他语言中,点表示从结构中访问成员。 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.这意味着在工作示例中,您访问一个成员并将其分配给
Cell_Voltage
而在不工作的示例中,您希望将整个结构分配给一个简单的变量,这确实不起作用。
Decide which member of the structure you need, and address that with the dot notation.决定您需要结构的哪个成员,并用点表示法解决它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.