创建两个ECU节点,一个用来发送CAN消息,一个用来接收CAN消息。
/* ecu1.can */
/*@!Encoding:936*/
includes
{
}
variables
{
}
on preStart
{
write("Hello ECU1!\n");
}
on start
{
message 0x01 msg;
msg.can = 1;
msg.dlc = 8;
msg.byte(0) = 0x11;
msg.byte(1) = 0x22;
msg.byte(2) = 0x33;
msg.byte(3) = 0x44;
msg.byte(4) = 0x55;
msg.byte(5) = 0x66;
msg.byte(6) = 0x77;
msg.byte(7) = 0x88;
output(msg);
}
/* ecu2.can */
/*@!Encoding:936*/
includes
{
}
variables
{
}
on preStart
{
write("Hello ECU2!\n");
}
on message 0x01
{
write("ECU2: this.id = %x",this.id);//获取报文ID
write("ECU2: this.name = %s",this.name);//获取报文名字
write("ECU2: this.can = %d",this.can);//获取当前报文在哪路can上
write("ECU2: this.dir = %d",this.dir);//获取当前报文是TX还是RX
write("ECU2: this.dlc = %d",this.dlc);//获取当前报文的报文长度
write("ECU2: this.byte(6) = %x",this.byte(0));
write("ECU2: this.byte(7) = %x",this.byte(1));
write("ECU2: this.byte(6) = %x",this.byte(2));
write("ECU2: this.byte(7) = %x",this.byte(3));
write("ECU2: this.byte(6) = %x",this.byte(4));
write("ECU2: this.byte(7) = %x",this.byte(5));
write("ECU2: this.byte(6) = %x",this.byte(6));
write("ECU2: this.byte(7) = %x",this.byte(7));
}