Main Content

replay

Retransmit messages from CAN bus

Description

replay(canch,msgs) retransmits the specified messages on the channel canch, based on the relative differences of their timestamps. The replay function also replays messages from MATLAB® to Simulink®.

To understand the elements of a message, refer to canMessage.

example

Examples

collapse all

Use a loopback connection between two channels, so that:

  • The first channel transmits messages 2 seconds apart.

  • The second channel receives them.

  • The replay function retransmits the messages with the original delay.

The timestamp differentials between messages in the two receive arrays, msgRx1 and msgRx2, are equal.

ch1 = canChannel('Vector','CANcaseXL 1',1);
ch2 = canChannel('Vector','CANcaseXL 1',2);
start(ch1)
start(ch2)
msgTx1 = canMessage(500,false,8);
msgTx2 = canMessage(750,false,8);

% The first channel transmits messages 2 seconds apart.
transmit(ch1,msgTx1)
pause(2)
transmit(ch1,msgTx2)
%The second channel receives them
msgRx1 = receive(ch2,Inf);

% The replay function retransmits the messages with the original delay.
replay(ch2,msgRx1)
pause(2)
msgRx2 = receive(ch1,Inf);

Input Arguments

collapse all

CAN device channel, specified as a CAN channel object, on which to retransmit.

Example: canChannel('NI','CAN1')

Messages to replay, specified as a timetable of CAN messages, a message object, or an array of message objects.

Version History

Introduced in R2009a