Clear Filters
Clear Filters

Using extractAll command

5 views (last 30 days)
Ryan Aldrich
Ryan Aldrich on 22 Jul 2011
I am building a script that configures a CAN channel and then listens for and extracts a certain type of message from the traffic on the CAN. However, I am having problems with the extractAll command because it doesn't like the class of any of the arguements that I pass to it. I've tried sending it a double, single, char, and struct but it won't take any of them. Does anyone out there have the same problem? Here is my current script:
%% Create CAN channel, configure properties and initialize variables
canch = canChannel('Vector','CANcaseXL 1', 1);
configBusSpeed(canch, 500000);
msg_num = 100; = 415;
message.messagename = 'IC_A1';
%% Start the CAN channel and receive messages
for i = 1:msg_num
[msgOut, remainder] = extractAll(message, 415, true);
value = unpack(message, 0, 16, 'LittlegEndian', 'int16');
%% Stop the CAN channel

Accepted Answer

Shankar Subramanian
Shankar Subramanian on 22 Jul 2011
Hi Ryan,
The following link is the documentation for extractAll function. The first input to extractAll method is the CAN Message object (can.Message).
Although, I was not able to completely understand the loop, here are some of my thoughts.
  1. The line start(canch) must be outside the loop just before the for statement. Starting the same CAN channel multiple times will result in an error.
  2. The receive method returns CAN Messages as can.Message objects. You must use a variable to store the return value.
canMsgs = receive(canch, i);
3. Also, receive(canch, i) - Receiving number of messages corresponding to your loop count. It is not clear as to why you would want that given that you want to monitor all messages and extract the required ID. Receiving Inf messages might be better (receives all that are available).
canMsgs = receive(canch, Inf);
4. See if filtering might work for you instead of using extractAll method. You need to set your filter before you start your CAN channel.
5. In the event you use extractAll method, pass the output of your receive function as the input to the extractAll method along with ID and IDType.
  1 Comment
Ryan Aldrich
Ryan Aldrich on 22 Jul 2011
I got rid of the loop and decided to use the receive command with Inf. Also, I found the filterSet command to be much easier to use thank extractAll. Thanks!

Sign in to comment.

More Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!