文章目录
- 1. 简述
- 2. ECU1
- 3. ECU2
- 4. 测试
1. 简述
创建两个ECU节点,一个用来发送CAN消息,一个用来接收CAN消息。
2. ECU1
/* 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);
}
3. ECU2
/* ecu2.can */
/*@!Encoding:936*/
includes
{}variables
{}on preStart
{write("Hello ECU2!\n");
}on message 0x01
{write("ECU2: this.id = %x",this.id);//获取报文IDwrite("ECU2: this.name = %s",this.name);//获取报文名字write("ECU2: this.can = %d",this.can);//获取当前报文在哪路can上write("ECU2: this.dir = %d",this.dir);//获取当前报文是TX还是RXwrite("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));
}