Azzera filtri
Azzera filtri

Display all the traffic going through a Can chanel, App Designer.

10 visualizzazioni (ultimi 30 giorni)
Hi,
I'm building an app with Matlab App Designer and i would like to display on a panel (I use a TextAera for now) all the traffic going through a Can chanel.
I did achieve to display the received ones (using receive() and canSignalTimetable()), but I can't manage to do the same with the transmited ones.
Is there a way to do it ? Maybe easier than keeping in memory all the transmited messages and updating a timer while checking errors in the canChannel, knowing that if there's error in transmitted messages, it seems that you can't know wich message wasn't sent successfully...

Risposta accettata

Ayush Singh
Ayush Singh il 10 Giu 2024
Hello Luc
As I can interpret, you want to display all the traffic going through on CAN channel on TextArea in your case.
As far as I know, since the MATLAB CAN interface does not automatically log transmitted messages in the same way it does for received messages, you will need to implement a mechanism to log them manually.
Here is one approach to achieve this:
  1. Before sending messages, initialize a structure or table to store information about each transmitted message. This structure should be accessible in the scope where you're sending messages and where you want to display them.
% Example structure for logging messages
app.transmittedMessages = struct('ID', {}, 'Data', {}, 'Timestamp', {});
% Based on the message strucure, modify the above struct according to your needs
2. Every time you transmit a message, add its details to your logging structure or table. You can capture the timestamp at this point as well.
function transmitCANMessage(app, message)
% Transmit the message
transmit(app.canChannel, message);
% Log the message details which are actually the message properties
newEntry.ID = message.ID;
newEntry.Data = message.Data;
newEntry.Timestamp = datetime('now');
app.transmittedMessages(end+1) = newEntry;
% Update your UI here or call another function to do so
updateUITransmittedMessages(app);
end
3. After logging a transmitted message, update the TextArea to display the latest message or refresh the list of messages.
function updateUITransmittedMessages(app)
% Convert the structure of messages to a string representation
% Below is a simple example, you might need to format it more nicely
messagesString = '';
for i = 1:length(app.transmittedMessages)
msg = app.transmittedMessages(i);
messagesString = sprintf('ID: %d, Data: %s, Timestamp: %s\n', ...
msg.ID, mat2str(msg.Data), msg.Timestamp);
messagesStr = [messagesStr, messagesString];
end
% Update the TextArea with the messages string
app.TextArea.Value = messagesStr;
end
I think you should be able to see the message content on the TextArea now!
  1 Commento
Luc
Luc il 13 Giu 2024
Hello Ayush,
It was very helpfull as it answers the question of doing it simply with a built-in matlab function and how to do it in the case this function doesn't exist with a proper working method.
Thank you very much.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by