This example shows you how to use Vehicle Network Toolbox™ to transmit and receive CAN messages and visualize CAN message data using a GUIDE GUI. This example uses Vehicle CAN Bus Monitor to display generated messages. It uses Vector Virtual CAN channels connected in a loopback configuration.
|On this page…|
Open Vehicle CAN Bus Monitor.
To attach the database file, in the Vehicle CAN Bus Monitor window:
Select "Configure" > "Database...".
Browse to your MATLAB installation folder and go to toolbox\vnt\vntdemos.
Verify that Vehicle CAN Bus Monitor is using the channel: "Vector - Virtual 1 - Channel 1":
Select "Configure" > "Channel".
Select "Vector - Virtual 1 - Channel 1".
Vehicle CAN Bus Monitor is now configured. Click "Start" on the toolbar to set it online. To view CAN signal data as decoded with the database while Vehicle CAN Bus Monitor is running, enable the "Show Unique Messages" option via the toolbar. Now you can expand each row in the message table to view the live signal values.
Open the GUI used in this example.
Click Send Messages to transmit a single instance of each CAN message. The GUI sends information from two CAN messages:
"VehicleData" contains accelerator pedal position and engine speed signals.
"WheelSpeeds" contains wheel speed signals.
Click Repeat Messages to send both messages at a fixed periodic rate. Click it again to stop the transmission. Experiment with each button and watch the values displayed on the GUI. You can also see the messages in Vehicle CAN Bus Monitor as the occur.
The GUI receives the messages as they are transmitted. It uses the database definitions to decode signal data from both messages and displays the values in engineering units. The display updates at a fixed periodic rate. Each time the update occurs, the GUI receives all of the CAN message traffic since the last update and displays the most recently available data values. If no new values are available for a given signal, the last displayed value remains on the GUI.
The GUI in this example is built using the standard GUIDE editor. The MATLAB code that drives the GUI is generated from GUIDE and then updated with the CAN message handling code. Review this GUIDE code to see how the CAN messaging is implemented.