- 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.
- The receive method returns CAN Messages as can.Message objects. You must use a variable to store the return value.
Using extractAll command
7 views (last 30 days)
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);
msg_num = 100;
message.id = 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
Shankar Subramanian on 22 Jul 2011
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.
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.