我有一个ECU发送一个包含2个字节数据的CAN消息。我想将CAPL中的这两个数据字节放入两个环境变量中。我正在开发一个独木舟模拟,我想使用这两个环境变量在面板中显示它们的值。
我看到带有跟踪数据字节的CAN消息被正确接收,但当我尝试在CAPL中使用这些数据字节时,它们是0。
我有以下代码:
message CAN1.SWversion SWversion;
on message SWversion
{
putValue(ev_MainSW, SWversion.MainSW);
putValue(ev_SecSW, SWversion.SecSW);
}
SWversion.MainSW是字节(0),SWversion.SecSW是字节(1)。我在trace上看到了它们的值,但在CAPL中它们是0。
有任何关于原因的提示吗?
Here's my trace window with the data bytes
发布于 2021-07-20 15:49:16
我想通了:
message CAN1.SWversion SWversion;
on message SWversion
{
putValue(ev_MainSW, SWversion.MainSW);
putValue(ev_SecSW, SWversion.SecSW);
}
需要更改为
message CAN1.SWversion SWversion;
on message SWversion
{
putValue(ev_MainSW, this.byte(0));
putValue(ev_SecSW, this.byte(1);
}
显然,您不能在CAPL中使用预定义信号来访问CAN消息中的数据。
发布于 2021-07-20 16:05:40
在您的事件处理程序中,您似乎应该访问接收到的消息,而不是全局(显然未初始化)变量:
on message CAN1.SWversion
{
putValue(ev_MainSW, this.MainSW);
putValue(ev_SecSW, this.SecSW);
}
https://stackoverflow.com/questions/68441352
复制相似问题