Receive and Visualize CAN Data Using CAN Explorer
This example shows how to use theCAN Explorerapp to receive and visualize CAN data. It uses MathWorks® Virtual channels which are connected in a loopback configuration.CAN Exploreris configured to receive data using MathWorks Virtual 1 Channel 1. Pre-recorded data is provided in a MAT-file and replayed onto MathWorks Virtual 1 Channel 2 to emulate CAN traffic generated from connecting to an actual vehicle system.
Open the CAN Explorer
Open theCAN Explorerapp using commandcanExplorer
. Alternatively, you can findCAN Explorerin the MATLAB®Appstab.
Select the Device Channel
当应用程序第一次打开时,它会显示所有的访问ssible CAN channels from devices connected to the system. Select MathWorks Virtual 1 Channel 1 from the available devices. Then the app finishes opening and looks like this, with the selected device highlighted in a blue outline.
Configure the Database Files
Add database files toCAN Explorerto decode incoming messages and signals.
To open the Database Configuration dialog, selectDatabasesin the toolstrip.
ClickAddto open the file selection dialog. Select the
CANExplorerDatabase.dbc
file provided with the example.ClickOKto save the database configuration and close the dialog.
Configure the Channel Bus Speed
Configure the channel bus speed if the desired network speed differs from the default value.
To open the Device Channel Configuration dialog, selectDevice Channelin the toolstrip.
This example uses the default bus speed at 500000 bits per second. Confirm the current device channel configuration and clickOK.
In the same dialog, you can configure message filters respectively for standard ID and extended ID to control which messages pass through the channel. By default, both filter options are set to allow all messages to pass, but you can also specify certain IDs to be allowed or blocked.
Configure the Signal Table
Add signals of interest to view on the Signal Table. In this example, you view all signals defined in theCANExplorerDatabase.dbc
file.
To open the Signal Table Configuration dialog, selectSignals > Configure Signal Tablein the toolstrip.
Add signals from theAvailable Signalspane to theConfigured Signalspane using the→button. You can add individual signals, add all signals in a message by adding the message, or add all signals in a database by adding the database. For this example, select
CANExplorerDatabase.dbc
in theAvailable Signalspane and click→to add all signals in the database to view.ClickOKto save the signal table configuration and close the dialog.
If you provide a search text for signals or messages and clickFind,Available Signalspane is updated to display search results that are case-insensitive partial matches to the search text.
Configure the Signal Scopes
Add signals of interest to view on the Signal Scopes.CAN Explorerprovides 3 scopes that can each be configured to visualize signals of selection. The number of scopes is fixed and cannot be customized. In this example, you view all signals fromMessage_A
in the top signal scope, all signals fromMessage_B
andMessage_C
in the middle signal scope, and all signals fromMessage_D
in the bottom signal scope.
To open the Top Signal Scope Configuration dialog, selectSignals > Configure Top Signal Scopein the toolstrip.
Select
Message_A
in theAvailable Signalspane and click→to add all signals in this message to view on the top signal scope.ClickOKto save the top signal scope configuration and close the dialog.
Using a similar approach, add signals from
Message_B
andMessage_C
to view on the middle signal scope, and add signals fromMessage_D
to view on the bottom signal scope.
Start Monitoring
开始监控CAN Explorerbefore starting the replay to avoid losing any data. ClickStartin the toolstrip.
Replay Pre-Recorded CAN Data
Data logged from a CAN network is provided in the fileCANExplorerData.mat
. The data is saved in timetable format and the time range spans about 60 seconds.
Replay the CAN data onto MathWorks Virtual 1 Channel 2 forCAN Explorerto receive on MathWorks Virtual 1 Channel 1 in the same MATLAB instance. To start the data replay, execute the scriptreplayCANData.m
. You can also execute the script sequentially multiple times to generate CAN data beyond 60 seconds for additional experiments.
Explore the Monitor and Display Options
WhileCAN Explorercontinues to receive data, you can experiment with controls in theMonitorandDisplaysections of the toolstrip.
ClickPauseto temporarily suspendCAN Explorerfrom visually updating. While pausedCAN Explorercontinues accumulating and processing data in the background.
ClickContinueto resume the visual updates inCAN Explorer.
For further exploration:
If you clickClear Data, all accumulated data is completely cleared fromCAN Explorer.
By default, the Message Table displays all CAN messages in chronological order. To view the latest instance of each unique message, toggleUnique Messages.
By default, both the Message Table and the Signal Table display time since the start of monitoring. To view the delta time since the last message or signal in each table, toggleDelta Time.
停止Monitoring
When you have completed your live acquisition activity, click停止in the toolstrip to take the device channel offline.
Clean up for the Data Replay
Clean up by executing the scriptreplayCANDataCleanup.m
, which stops the MathWorks Virtual 1 Channel 2 used for replay and clears the unneeded variables.
Export Data for Additional Use
In the toolstrip, click the top half of theExportbutton to export the received data into the MATLAB workspace in a timetable format.
If you would like to retain the exported variable for future use:
To save the variable to a MAT-file, use the
save
function.To save the variable to a BLF-file, use the
blfwrite
function.
The exported timetable of messages is also convertible into individual timetables of signal data. ThecanSignalTimetable
function returns a structure with one field for each unique message in the timetable. Each field value is a timetable of all the signals defined in that message.