- 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.
Display all the traffic going through a Can chanel, App Designer.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Luc
el 30 de Mayo de 2024
Comentada: Luc
el 13 de Jun. de 2024
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...
0 comentarios
Respuesta aceptada
Ayush Singh
el 10 de Jun. de 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:
% 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!
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!