Vehicle Network Toolbox™ User's Guide PDF
Vehicle Network Toolbox™ User's Guide PDF
User’s Guide
R2014a
How to Contact MathWorks
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
508-647-7000 (Phone)
508-647-7001 (Fax)
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
March 2009 Online only New for Version 1.0 (Release 2009a)
September 2009 Online only Revised for Version 1.1 (Release 2009b)
March 2010 Online only Revised for Version 1.2 (Release 2010a)
September 2010 Online only Revised for Version 1.3 (Release 2010b)
April 2011 Online only Revised for Version 1.4 (Release 2011a)
September 2011 Online only Revised for Version 1.5 (Release 2011b)
March 2012 Online only Revised for Version 1.6 (Release 2012a)
September 2012 Online only Revised for Version 1.7 (Release 2012b)
March 2013 Online only Revised for Version 2.0 (Release 2013a)
September 2013 Online only Revised for Version 2.1 (Release 2013b)
March 2014 Online only Revised for Version 2.2 (Release 2014a)
Contents
Getting Started
1
Vehicle Network Toolbox Product Description . . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
v
Configure Silent Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32
Disconnect Channels and Clean Up . . . . . . . . . . . . . . . . . . . 1-33
vi Contents
Using a CAN Database
3
Vector CAN Database Support . . . . . . . . . . . . . . . . . . . . . . 3-2
vii
A2L File
5
A2L File Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
viii Contents
CAN Communication in Simulink . . . . . . . . . . . . . . . . . . . 7-3
Message Transmission Workflow . . . . . . . . . . . . . . . . . . . . . 7-4
Message Reception Workflow . . . . . . . . . . . . . . . . . . . . . . . . 7-5
ix
Functions — Alphabetical List
9
Block Reference
11
x Contents
1
Getting Started
From MATLAB or Simulink, you can monitor, filter, and analyze live CAN
bus data or log and record CAN messages for later analysis and replay. You
also can simulate message traffic on a virtual CAN bus or connect Simulink
models to a live network or ECU. Vehicle Network Toolbox supports CAN
interface devices from Vector, Kvaser, and National Instruments®.
Key Features
• MATLAB functions for transmitting and receiving CAN and XCP messages
• Simulink CAN and XCP blocks for connecting a model to a CAN bus or ECU
• Vector CAN database (.dbc) file and A2L description file support
• Signal packing and unpacking functions and blocks for simplified encoding
and decoding of CAN messages
• Message filtering, logging, and replay functions
• Vehicle CAN Bus Monitor app to configure devices and visualize live CAN
network traffic
• Support for Vector, Kvaser, and National Instruments CAN interface
devices
1-2
Product Capabilities
Product Capabilities
In this section...
“Vehicle Network Toolbox Characteristics” on page 1-3
“Interaction Between the Toolbox and Its Components” on page 1-4
“Expected Background ” on page 1-6
“Related Products” on page 1-6
For example, in a common design when you press a button to lock the doors
in your car, a control unit in the door reads that input and transmits lock
commands to control units in the other doors. These commands exist as data
in CAN messages, which the control units in the other doors receive and act
on by triggering their individual locks in response.
1-3
1 Getting Started
1-4
Product Capabilities
In this illustration:
1-5
1 Getting Started
Using Vehicle Network Toolbox from MATLAB, you can configure a channel
on the CAN device to:
Expected Background
This document assumes that you are familiar with these products:
• MATLAB — To write scripts and functions, and to use functions with the
command-line interface.
• Simulink — To create simple models to connect to a CAN bus or to simulate
those models.
• Vector CANdb — To understand CAN databases and message and signal
definitions.
Related Products
MathWorks provides several products that are relevant to the kinds of tasks
you can perform with Vehicle Network Toolbox software and that extend the
1-6
Product Capabilities
1-7
1 Getting Started
Required Components
To communicate on CAN networks from the MATLAB workspace and using
Simulink models, install these components:
Note To use the Vehicle Network Toolbox block library, install the current
Simulink version.
1-8
Install Required Components
These drivers are available for download from the Vector Web site at:
http://vector.com/vi_downloadcenter_en.html
Drivers for 32-bit and 64-bit Windows are available in separate packages.
Download and install the latest version and select the appropriate check box
during installation for the hardware you want to use. Virtual channels are
also installed with the hardware drivers.
XL Driver Library. Download and install the latest version of the XL Driver
Library from the Vector Web site. A single package contains the driver library
for 32-bit and 64-bit Windows. After installing the library:
• If you have a 32-bit system, copy the file vxlapi.dll from the installation
folder to the windows root\system32 folder.
• If you have a 64-bit system, copy the file vxlapi64.dll from the
installation folder to the windows root\system32 folder.
• If you have a 64-bit system and need to run the 32-bit version of Vehicle
Network Toolbox software, copy the file vxlapi.dll from the installation
folder to the windows root\syswow64 folder.
Drivers for your Kvaser devices are available on the Kvaser Web site at:
http://www.kvaser.com/download/main.php
Drivers for 32-bit and 64-bit Windows are available in the same package.
Virtual channels are also installed with the hardware drivers.
1-9
1 Getting Started
If you are using an NI-CAN device, install the NI-CAN programming library
from the National Instruments Web site. This installs both the drivers and
the driver libraries.
If you are using an NI-XNET device, install the latest NI-XNET drivers from
the National Instruments Web site. This installs both the drivers and the
driver libraries.
Drivers for 32-bit and 64-bit Windows are available in the same package.
Virtual channels for NI-CAN devices are also installed with the hardware
drivers.
If you are using National Instruments CompactDAQ devices, you might need
to install additional drivers. Check your device documentation for more
information.
Tip To use NI-CAN and NI-XNET on the same system together, assign
unique names to the device channels in NI-MAX before you create channels in
the toolbox.
1-10
Install Required Components
Driver Library. A single package contains the driver and interface library
for 32-bit and 64-bit Windows. After installing the library:
• If you have a 32-bit system, copy the file PCANBasic.dll from the
download folder \\Disk\PCAN-Basic API\Win32 location to the windows
root\system32 folder.
• If you have a 64-bit system, copy the file PCANBasic.dll from the
download folder \\Disk\PCAN-Basic API\Win64 location to the windows
root\system32 folder.
• If you have a 64-bit system and need to run the 32-bit version of Vehicle
Network Toolbox software, copy the file PCANBasic.dll from the
download folder \\Disk\PCAN-Basic API\Win64 location to the windows
root\syswow64 folder.
ver
The Command Window displays information about the MATLAB version you
are running, including a list of installed add-on products and their version
numbers. Check the list to see if the Vehicle Network Toolbox name appears.
http://www.mathworks.com/support
Supported Hardware
Vehicle Network Toolbox supports Vector, Kvaser, National Instruments, and
PEAK-System CAN devices.
1-11
1 Getting Started
• CANcaseXL
• CANcaseXLe
• CANboardXL
• CANboardXL pxi
• CANboardXL PCIe
• CANcardXL
• CANcardX
You can also use the toolbox with virtual CAN channels available with Vector
hardware drivers.
• WLAN
• PCMCIA
• Leaf
• Memorator
• PCI
• USB
You can also use the toolbox with virtual CAN channels available with Kvaser
hardware drivers.
1-12
Install Required Components
For a complete list of supported NI-CAN devices, see the Supported Hardware
page.
• NI 9861, USB-986
• NI 9862, USB-9862
• NI PXI-8513/2, PXI-8513
• NI PXI-8512/2, PXI-8512
• NI PXI-8511/2, PXI-8511
• NI PCI-8513/2, PCI-8513
• NI PCI-8512/2, PCI-8512
• NI PCI-8511/2, PCI-8511
• PCAN-USB
• PCAN-USB Pro
• PCAN-USB Hub
• PCAN-PC Card
• PCAN-ExpressCard
• PCAN-PCI
• PCAN-PCI Express
• PCAN-cPCI
• PCAN-miniPCI
• PCAN-minPCIe
1-13
1 Getting Started
1-14
Vehicle Network Communication in MATLAB®
Transmit Workflow
1-15
1 Getting Started
Receive Workflow
1-16
Vehicle Network Communication Examples
Prerequisites
Examples follow a sequential workflow for configuring CAN communications.
Use these examples sequentially MATLAB Command Window.
In the example, create two CAN channels using canChannel, and canHWInfo
to obtain information about the devices installed on your system. Edit the
properties of the first channel and create a message using canMessage.
Transmit the message from the first channel using transmit, and receive it
on the other using receive .
1-17
1 Getting Started
• Complete your toolbox installation before you try out the examples.
• Connect the two channels in your CAN device with a loopback connector.
The following examples use the Vector CANcaseXL hardware. You can
substitute it with any other supported hardware.
info = canHWInfo
info.VendorInfo(1).ChannelInfo(1)
can.vector.ChannelInfo handle
Package: can.vector
1-18
Vehicle Network Communication Examples
Properties:
Device: 'CANcaseXL 1'
DeviceChannelIndex: 1
DeviceSerialNumber: 24365
ObjectConstructor: 'canChannel('Vector','CANcaseXL 1',1)'
Note This example assumes that you have a loopback connection between
the two channels on your CAN device.
Notes You cannot use the same variable to create multiple channels
sequentially. Clear any channel in use before using the same variable
to construct a new CAN Channel.
You cannot create arrays of CAN channel objects. Each object you create
must exist as its own individual variable.
2 Press Enter after you create the connection. MATLAB displays a summary
of the channel properties:
1-19
1 Getting Started
Filter History: Standard ID Filter: Allow All | Extended ID Filter: Allow All.
You used the canChannel function to connect to the CAN device. To identify
installed devices, use the canHWInfo function.
Configure Properties
You can set the behavior of your CAN channel by configuring its property
values. For this exercise, change the bus speed of channel 1 to 250000 using
the configBusSpeed function.
get(canch1)
General Settings:
BusStatus = 'N/A'
Database = []
InitializationAccess = 1
MessageReceivedFcn = []
MessageReceivedFcnCount = 1
MessagesAvailable = 0
MessagesReceived = 0
MessagesTransmitted = 0
ReceiveErrorCount = 0
Running = 0
SilentMode = 0
1-20
Vehicle Network Communication Examples
TransmitErrorCount = 0
Device Settings:
Device = 'CANcaseXL 1'
DeviceChannelIndex = 1
DeviceSerialNumber = 24811
DeviceVendor = 'Vector'
Transceiver Settings:
TransceiverName = 'CANpiggy 251mag (Highspeed)'
TransceiverState = 16
configBusSpeed(canch1, 250000)
get(canch1)
.
.
.
BusSpeed = 250000
4 Change the bus speed of the second channel (canch2) by repeating steps
2 and 3.
1-21
1 Getting Started
start(canch1)
start(canch2)
3 To check that the channel is online, type the channel name in the Command
Window. The Status section indicates that the channel is now online, as
in this example:
>> canch1
.
.
.
Status: Online.
0 messages available to RECEIVE.
0 messages transmitted since last start.
0 messages received since last start.
Filter History: Standard ID Filter: Allow All | Extended ID Filter: Allow All.
Create a Message
After you set all the property values as desired and your channels are online,
you are ready to transmit and receive messages on the CAN bus. For this
exercise, transmit a message using canch and receive it using canch1. To
transmit a message, create a message object and pack the message with the
required data.
messageout =
can.Message handle
1-22
Vehicle Network Communication Examples
Package: can
Properties:
ID: 500
Extended: 0
Name: ''
Database: []
Error: 0
Remote: 0
Timestamp: 0
Data: [0 0 0 0 0 0 0 0]
Signals: []
You can also use a database to create a CAN message. Refer to “Message
Database” for more information.
Pack a Message
After you define the message, pack it with the required data.
1 Use the pack function to pack your message with these input parameters:
Here you are specifying the data value to be 25, the start bit to be 0, the
signal size to be 16, and the byte order to be little-endian format.
1-23
1 Getting Started
messageout
messageout =
can.Message handle
Package: can
Properties:
ID: 500
Extended: 0
Name: ''
Database: []
Error: 0
Remote: 0
Timestamp: 0
Data: [25 0 0 0 0 0 0 0]
Signals: []
The only field that changes after you specify the data is Data. Refer to the
pack function to understand more about the input arguments.
Transmit a Message
After you define the message and pack it with the required data, you are
ready to transmit the message. For this example, use canch to transmit the
message.
1 Use the transmit function to transmit the message, supplying the channel
and the message as input arguments:
transmit(canch1, messageout)
canch1
1-24
Vehicle Network Communication Examples
Status: Online.
1 messages available to RECEIVE.
1 messages transmitted since last start.
0 messages received since last start.
Filter History: Standard ID Filter: Allow All | Extended ID Filter: Allow All.
Receive a Message
After your channel is online, use the receive function to receive available
messages. For this example, receive the message on the second configured
channel object, canch2.
canch2
.
.
.
Status: Online.
1 messages available to RECEIVE.
1-25
1 Getting Started
messagein = receive(canch2, 1)
messagein =
can.Message handle
Package: can
Properties:
ID: 500
Extended: 0
Name: ''
Database: []
Error: 0
Remote: 0
Timestamp: 709.0403
Data: [25 0 0 0 0 0 0 0]
Signals: []
canch2
MATLAB returns the channel properties, and the status indicates that
the channel received one message:
.
.
.
Status: Online.
0 messages available to RECEIVE.
0 messages transmitted since last start.
1 messages received since last start.
1-26
Vehicle Network Communication Examples
Refer to the receive function to understand more about its input arguments.
Unpack a Message
After your channel receives a message, specify how to unpack the message
and interpret the data in the message. Use unpack to specify the parameters
for unpacking a message:
value =
25
Refer to the unpack function to understand more about its input arguments.
load mycanch.mat
The loaded CAN channel object reconnects to the specified hardware and
reconfigures itself to the specifications when the channel was saved.
1-27
1 Getting Started
Filter Messages
You can set up filters on your channel to accept messages based on the filtering
parameters you specify. Set up your filters before putting your channel online.
For more information on message filtering, see these functions:
• filterAllowAll
• filterBlockAll
• filterAllowOnly
To specify message names you want to filter, create a CAN channel and attach
a database to the channel:
canch1=canChannel('Vector','CANcaseXL 1',1);
canch1.Database=canDatabase('demoVNT_CANdbFiles.dbc');
Set a filter for the message EngineMsg and display the channel:
filterAllowOnly(canch1, 'EngineMsg');
canch1
Summary of CAN Channel using 'Vector' 'CANcaseXL 1' Channel 1.
Filter History: Standard ID Filter: Allow Only | Extended ID Filter: Allow All
If you start the channel and receive messages, you should now only see the
EngineMsg pass through the filter.
1-28
Vehicle Network Communication Examples
Multiplex Signals
Use multiplexing to represent multiple signals in one signal’s location in a
CAN message’s data. A multiplexed message can have three types of signals:
Standard signal
This signal is always active. You can create one or more standard
signals.
Multiplexor signal
Also called the mode signal, it is always active and its value determines
which multiplexed signal is currently active in the message data. You
can create only one multiplexor signal per message.
Multiplexed signal
This signal is active when its multiplex value matches the value of the
multiplexor signal. You can create one or more multiplexed signals in
a message.
Multiplexing works only with a CAN database with message definitions that
already contain multiplex signal information. This example shows you how to
access the different multiplex signals using a database constructed specifically
for this purpose. This database has one message with these signals:
d = canDatabase('Mux.dbc')
m = canMessage(d, 'Msg')
1-29
1 Getting Started
m =
can.Message handle
Package: can
Properties:
ID: 250
Extended: 0
Name: 'Msg'
Database: [1x1 can.Database]
Error: 0
Remote: 0
Timestamp: 0
Data: [0 0 0 0 0 0 0 0]
Signals: [1x1 struct]
m.Signals
ans =
SigB: 0
SigA: 0
MuxSig: 0
4 If you want to make SigB active, change the value of the MuxSig to 1:
m.Signals.MuxSig = 1
1-30
Vehicle Network Communication Examples
m.Signals
ans =
SigB: 0
SigA: 0
MuxSig: 1
SigB is now active because its multiplex value of 1 matches the current
value of MuxSig (which is 1).
m.Signals.MuxSig = 2
Here, neither of the multiplexed signals are active because the current
value of MuxSig does not match the multiplex value of either SigA or SigB.
m.Signals
ans =
SigB: 0
SigA: 0
MuxSig: 2
Always check the value of the multiplexor signal before using a multiplexed
signal value.
if (m.Signals.MuxSig == 0)
% Feel free to use the value of SigA however is required.
end
This ensures that you are not using an invalid value because the toolbox
does not prevent or protect reading or writing inactive multiplexed signals.
Note You can access both active and inactive multiplexed signals regardless
of the value of the multiplexor signal.
1-31
1 Getting Started
get(canch1)
General Settings:
BusStatus = 'N/A'
Database = []
InitializationAccess = 1
MessageReceivedFcn = []
MessageReceivedFcnCount = 1
MessagesAvailable = 0
MessagesReceived = 0
MessagesTransmitted = 0
ReceiveErrorCount = 0
Running = 0
SilentMode = 0
TransmitErrorCount = 0
Device Settings:
Device = 'CANcaseXL 1'
DeviceChannelIndex = 1
DeviceSerialNumber = 24811
DeviceVendor = 'Vector'
Transceiver Settings:
TransceiverName = 'CANpiggy 251mag (Highspeed)'
TransceiverState = 16
1-32
Vehicle Network Communication Examples
BusSpeed = 500000
SJW = 1
TSEG1 = 4
TSEG2 = 3
NumOfSamples = 1
canch1.SilentMode = true
get(canch1)
.
.
.
SilentMode = 1
.
.
.
stop(canch1)
1-33
1 Getting Started
canch1
.
.
.
Status: Offline - Waiting for START.
1 messages available to RECEIVE.
1 messages transmitted since last start.
0 messages received since last start.
stop(canch2)
canch2
clear canch1
clear canch2
1-34
Vehicle Network Communication Examples
clear('messageout', 'messagein')
clear value
1-35
1 Getting Started
help vnt
Get Help
The toolbox functions are grouped by usage. Click a specific function for more
information.
To access the online documentation for the Vehicle Network Toolbox, type:
doc vnt
doc function_name
View Examples
To follow examples in this guide use the Vector CANcaseXL device, with the
Vector XL Driver Library version 6.4 or later. The Examples index in the
Help browser lists these examples.
1-36
2
Note You can use this support package only on a host computer running
32-bit or 64-bit Windows.
1 Open MATLAB.
4 The Support Package Installer opens with Install from Internet selected.
At Support package to install, select Vector CAN Devices.
2-2
Install Vector CAN Device Support
5 Follow the support package installer prompts. When prompted, log into
your MathWorks® account.
2-3
2 Hardware Support Package Installation
At any time during this process, you can click Help for more information
about downloading support packages.
2-4
Install National Instruments® NI-CAN Device Support
Note You can use this support package only on a host computer running
32-bit Windows.
1 Open MATLAB.
4 The Support Package Installer opens with Install from Internet selected.
At Support package to install, select NI-CAN.
2-5
2 Hardware Support Package Installation
5 Follow the support package installer prompts. When prompted, log into
your MathWorks account.
2-6
Install National Instruments® NI-CAN Device Support
At any time during this process, you can click Help for more information
about downloading support packages.
2-7
2 Hardware Support Package Installation
Note You can use this support package only on a host computer running
32-bit Windows.
1 Open MATLAB.
4 The Support Package Installer opens with Install from Internet selected.
At Support package to install, select NI-XNET.
2-8
Install National Instruments® NI-XNET Device Support
5 Follow the support package installer prompts. When prompted, log into
your MathWorks account.
2-9
2 Hardware Support Package Installation
At any time during this process, you can click Help for more information
about downloading support packages.
2-10
Install Kvaser CAN Device Support
Note You can use this support package only on a host computer running
32-bit or 64-bit Windows.
1 Open MATLAB.
4 The Support Package Installer opens with Install from Internet selected.
At Support package to install, select Kvaser CAN Devices.
2-11
2 Hardware Support Package Installation
5 Follow the support package installer prompts. When prompted, log into
your MathWorks account.
2-12
Install Kvaser CAN Device Support
At any time during this process, you can click Help for more information
about downloading support packages.
2-13
2 Hardware Support Package Installation
Note You can use this support package only on a host computer running
32-bit or 64-bit Windows.
1 Open MATLAB.
2-14
Install PEAK-System CAN Device Support
4 The Support Package Installer opens with Install from Internet selected.
At Support package to install, select PEAK-System CAN Devices.
2-15
2 Hardware Support Package Installation
5 Follow the support package installer prompts. When prompted, log into
your MathWorks account.
At any time during this process, you can click Help for more information
about downloading support packages.
2-16
Support Packages and Support Package Installer
A support package file has a *.zip extension. This type of file contains
MATLAB files, MEX files, and other supporting files required to install the
support package. Use Support Package Installer to install these support
package files.
2-17
2 Hardware Support Package Installation
You can start Support Package Installer in one of the following ways:
2-18
Install This Support Package on Other Computers
Before starting, select a computer to use for downloading. This computer must
have the same base product license and platform as the computers upon which
you are installing the support package. For example, suppose you want to
install a Simulink support package on a group of computers that are running
64-bit Windows. To do so, you must first download the support package using
a computer that has a Simulink license and is running 64-bit Windows.
This action creates a subfolder within the Download folder that contains
the files required for each support package.
5 Make the new folder available to for installation on other computers. For
example, you can share the folder on the network, or copy the folder to
portable media, such as a USB flash drive.
2-19
2 Hardware Support Package Installation
3 Click Browse to specify the location of the support package folder on the
network or portable media.
2-20
Open Examples for This Support Package
2-21
2 Hardware Support Package Installation
2-22
Open Examples for This Support Package
Note For other types of examples, open the Help browser and search for your
product name followed by “examples”.
2-23
2 Hardware Support Package Installation
2-24
3
Look up message and signal information and build messages using the
information defined in the database file.
3-2
Load .dbc Files and Create Messages
db = canDatabase('filename.dbc')
Here db is a variable you chose for your database handle and filename.dbc is
the actual file name of your CAN database. If your CAN database is not in the
current working directory, type the path to the database:
db = canDatabase('path\filename.dbc')
This command returns a database object that you can use to create and
interpret CAN messages using information stored in the database. Refer to
the canDatabase function for more information.
3-3
3 Using a CAN Database
d = canDatabase('demoVNT_CANdbFiles.dbc')
sig = (message.Signals)
sig =
VehicleSpeed: 0
EngineRPM: 250
message.Signals.EngineRPM = 300
sig
sig =
VehicleSpeed: 0
3-4
Load .dbc Files and Create Messages
EngineRPM: 300
canch.Database = canDatabase('Mux.dbc')
1 Reload the database file into your MATLAB session using the canDatabase
function.
Open the database file and examine the Messages property to see the names
of all message defined in this database.
db = canDatabase('demoVNT_CANdbFiles.dbc')
db.Messages
db =
can.Database handle
Package: can
Properties:
Name: 'demoVNT_CANdbFiles'
3-5
3 Using a CAN Database
ans =
'DoorControlMsg'
'EngineMsg'
'SunroofControlMsg'
'TransmissionMsg'
'WindowControlMsg'
messageInfo(db, 'EngineMsg')
ans =
Name: 'EngineMsg'
Comment: ''
ID: 100
Extended: 0
Length: 8
Signals: {2x1 cell}
messageInfo(db)
ans =
3-6
Load .dbc Files and Create Messages
ans =
Name: 'EngineRPM'
StartBit: 0
SignalSize: 32
ByteOrder: 'LittleEndian'
Signed: 0
ValueType: 'Integer'
Class: 'uint32'
Factor: 0.1000
Offset: 250
Minimum: 250
Maximum: 9500
Units: 'rpm'
Comment: ''
Multiplexor: 0
Multiplexed: 0
MultiplexMode: 0
You can also query for information on all signals in the message at once.
signalInfo(db, 'EngineMsg')
3-7
3 Using a CAN Database
ans =
Specify the name of the message when you create a new message to have the
database definition applied. CAN signals in this messages are represented in
engineering units in addition to the raw data bytes.
msgEngineInfo =
can.Message handle
Package: can
Properties:
ID: 100
Extended: 0
3-8
Load .dbc Files and Create Messages
Name: 'EngineMsg'
Database: [1x1 can.Database]
Error: 0
Remote: 0
Timestamp: 0
Data: [0 0 0 0 0 0 0 0]
Signals: [1x1 struct]
UserData: []
Use the Signals property to see signal values for this message. You can
directly write to and read from these signals to pack or unpack data from
the message.
msgEngineInfo.Signals
ans =
VehicleSpeed: 0
EngineRPM: 250
Write directly to the signal to change a value and read its current value back.
msgEngineInfo.Signals.EngineRPM = 5500.25
msgEngineInfo.Signals
msgEngineInfo =
can.Message handle
Package: can
Properties:
3-9
3 Using a CAN Database
ID: 100
Extended: 0
Name: 'EngineMsg'
Database: [1x1 can.Database]
Error: 0
Remote: 0
Timestamp: 0
Data: [23 205 0 0 0 0 0 0]
Signals: [1x1 struct]
UserData: []
ans =
VehicleSpeed: 0
EngineRPM: 5.5003e+03
When you write directly to the signal, the value is translated, scaled, and
packed into the message data using the database definition.
msgEngineInfo.Signals.VehicleSpeed = 70.81
msgEngineInfo.Signals
msgEngineInfo =
can.Message handle
Package: can
Properties:
ID: 100
Extended: 0
Name: 'EngineMsg'
Database: [1x1 can.Database]
Error: 0
Remote: 0
Timestamp: 0
Data: [23 205 0 0 71 0 0 0]
3-10
Load .dbc Files and Create Messages
ans =
VehicleSpeed: 71
EngineRPM: 5.5003e+03
rxCh =
3-11
3 Using a CAN Database
Receive Messages
Start the channel, generate some message traffic and receive messages with
physical message decoding.
start(rxCh);
generateMsgsDb();
rxMsg = receive(rxCh, Inf)
rxMsg =
Properties:
ID
Extended
Name
Database
Error
Remote
Timestamp
Data
Signals
UserData
stop(rxCh);
clear rxCh
rxMsg(10)
rxMsg(10).Signals
3-12
Load .dbc Files and Create Messages
ans =
can.Message handle
Package: can
Properties:
ID: 100
Extended: 0
Name: 'EngineMsg'
Database: [1x1 can.Database]
Error: 0
Remote: 0
Timestamp: 0.1746
Data: [88 134 0 0 52 0 0 0]
Signals: [1x1 struct]
UserData: []
ans =
VehicleSpeed: 52
EngineRPM: 3.6892e+03
Use extractRecent and specify a message name to extract the most recent
occurrence of a message.
msgRecentWindows =
can.Message handle
Package: can
3-13
3 Using a CAN Database
Properties:
ID: 600
Extended: 0
Name: 'WindowControlMsg'
Database: [1x1 can.Database]
Error: 0
Remote: 0
Timestamp: 5.5749
Data: [64 62 0 0]
Signals: [1x1 struct]
UserData: []
allMsgEngine =
Properties:
ID
Extended
Name
Database
Error
Remote
Timestamp
Data
Signals
UserData
3-14
Load .dbc Files and Create Messages
Plot the values of database decoded signals over time. Reference the message
timestamps and the signal values in variables.
signals = [allMsgEngine.Signals]
plot([allMsgEngine.Timestamp], [signals.VehicleSpeed])
title('Vehicle Speed from EngineMsg', 'FontWeight', 'bold')
xlabel('Timestamp')
ylabel('Vehicle Speed')
axis([0 6 0 75])
signals =
3-15
3 Using a CAN Database
msgInfo =
msgInfo =
3-16
Other Uses of the CAN Database
Name: 'EngineMsg'
Comment: ''
ID: 100
Extended: 0
Length: 8
Signals: {2x1 cell}
Here the function returns information about message with name EngineMsg
in the database db. You can also use the message ID to get information
about a message. For example, to view the example message given here by
inputting the message ID, type:
This command provides the database name, the message ID, and a Boolean
value for the extended value of the ID.
To learn how to use it and work with the database, see the messageInfo
function.
You can also get information about a specific signal by providing the signal
name:
To learn how to use this property and work with the database, see the
signalInfo function.
You can also access the Signals property of the message to view physical
signal information. When you create physical signals using database
information, you can directly write to and read from these signals to pack or
unpack data from the message. When you write directly to the signal name,
the value is translated, scaled, and packed into the message data.
3-17
3 Using a CAN Database
Note If your message is an array, all messages in the array are associated
with the database that you attach.
You can also dissociate a message from a database so that you can view the
message in its raw form. To clear the attached database from a message, type:
Note The database gets attached even if the database does not find the
specified message. Even though the database is still attached to the message,
the message is displayed in its raw mode.
3-18
4
4-2
Vehicle CAN Bus Monitor
File Menu
4-3
4 Monitoring Vehicle CAN Bus
Configure Menu
• Message Filters — Opens the Set Message Filters dialog box. Select an
option in the dialog box to configure hardware filters to block or allow
messages.
4-4
Vehicle CAN Bus Monitor
Run Menu
4-5
4 Monitoring Vehicle CAN Bus
View Menu
Help Menu
• canTool Help — Select this option to see the online help for Vehicle CAN
Bus Monitor.
• About Vehicle Network Toolbox — Select this option to view the toolbox
version and release information.
4-6
Vehicle CAN Bus Monitor
Buttons
Start
Displays message activity on the selected channel.
Pause
Pauses the display of message activity on the selected channel.
Stop
Stops displaying messages on the selected channel.
Save messages
Click this button to save the current message list on the selected
channel to a file.
Clear messages
Click this button to clear messages in the Vehicle CAN Bus Monitor
window.
Docking
Click this button to dock the Vehicle CAN Bus Monitor to the MATLAB
desktop. To undock, click this button .
Undocking
Click this button to undock the Vehicle CAN Bus Monitor from the
MATLAB desktop. To dock, click this button.
4-7
4 Monitoring Vehicle CAN Bus
Message Table
Timestamp
Displays the time, relative to the start time, that the device receives the
message. The start time begins at 0 when you click Start.
ID
Displays the message ID. This field displays a number in hexadecimal
format for the ID and:
• Displays numbers only for standard IDs.
• Appends an x for an extended ID.
• Displays an r for a remote frame.
• Displays error for messages with error frames.
If you are using a database, click the + sign to see signal information. The tool
displays the signal name and the physical value of the message, as defined in
the attached database.
4-8
Using the Vehicle CAN Bus Monitor
2 The Vehicle CAN Bus Monitor defaults to the bus speed set in the device
driver. You can also configure a new bus speed. See Configuring the
Channel Bus Speed
4-9
4 Monitoring Vehicle CAN Bus
2 Type the desired value in the Specify bus speed dialog box.
3 Click OK.
The value you set takes effect once you start the CAN channel. If an error
occurs when applying the new bus speed, the value reverts to the default
value specified in the hardware.
To set up filters:
a Allow All to set the hardware filter to allow all messages with standard
IDs.
b Block All to set the hardware filter to block all messages with standard
IDs.
c Allow Only to set up custom filters. Type the standard IDs of the
message you want to filter. You can type a range or single IDs. The
default is 0:2047.
a Allow All to set the hardware filter to allow all messages extended IDs.
b Block All to set the hardware filter to block all messages extended IDs.
c Allow Only to set up custom filters. Type the extended IDs of the
message you want to filter. You can type a range or single IDs. The
default is 0:536870911.
4-10
Using the Vehicle CAN Bus Monitor
Note If you are using a custom filter, change the default range to the
desired range. The default range allows all messages and you should
select Allow All to allow all incoming messages with extended IDs.
4 Click OK.
Attach a Database
Attach a database to the Vehicle CAN Bus Monitor to see signal information
of the displayed messages.
1 Select Run > Stop to stop the message display in the Vehicle CAN Bus
Monitor.
3 Select the database to attach and start the message display again.
When the tool displays the messages, it shows the message name in the
Message table.
4-11
4 Monitoring Vehicle CAN Bus
4 Click the plus (+) sign to see the details of the message.
4-12
Using the Vehicle CAN Bus Monitor
The tool displays the signal name as defined in the attached database and
the signal’s physical value.
2 In the Specify maximum message count dialog box, type the number of
messages you want displayed at one time.
3 Click OK.
4-13
4 Monitoring Vehicle CAN Bus
Use this feature to get a snapshot of message IDs that the selected channel
receives. Use this information to analyze specific messages.
When you select Show Unique Messages, the tool continues to receive
message actively. This simplified view allows you to focus on specific
messages and analyze them.
To save a log file of the messages currently displayed in the window, select
File > Save Messages or click .
The tool saves the messages in a MATLAB file in your current working folder
by default. You can change the location by browsing to a different folder in
the Save dialog box.
Each time you save the message log to a file, the Vehicle CAN Bus Monitor
saves them as VNT CAN Log.mat with sequential numbering by default. You
can change the name by typing a new name in Save dialog box.
4-14
5
A2L File
5-2
Inspect the Contents of an A2L File
a2lfile = xcpA2L('filename.a2l')
Here a2lfile is a variable you chose for your A2L object and filename.a2l
is the actual file name of your A2L file. If your A2L file is not in the current
working directory, type the path to the file:
a2lfile = xcpA2L('path\filename.a2l');
This command returns a A2L object that you can use with live communication
to a slave module using XCP channels.
a2lfile = xcpA2L('XCPSIM.a2l');
5-3
5 A2L File
a2lfile
FileName: 'XCPSIM.a2l'
FilePath: 'H:\Documents\work\XCPSIM.a2l'
SlaveName: 'CPP'
ProtocolLayerInfo: [1x1 struct]
DAQInfo: [1x1 struct]
TransportLayerCANInfo: [1x1 struct]
Events: {'Key T' '10 ms' '100ms' '1ms' 'FilterBypass
Measurements: {1x38 cell}
a2lfile.Events
ans =
getEventInfo(a2lfile,'10 ms')
ans =
5-4
Inspect the Contents of an A2L File
a2lfile = xcpA2L('XCPSIM.a2l');
a2lfile
FileName: 'XCPSIM.a2l'
FilePath: 'H:\Documents\work\XCPSIM.a2l'
SlaveName: 'CPP'
ProtocolLayerInfo: [1x1 struct]
DAQInfo: [1x1 struct]
TransportLayerCANInfo: [1x1 struct]
Events: {'Key T' '10 ms' '100ms' '1ms' 'FilterBypass
Measurements: {1x38 cell}
a2lfile.Measurements
ans =
Columns 1 through 8
Columns 9 through 16
Columns 17 through 25
Columns 26 through 33
Columns 34 through 38
5-5
5 A2L File
getMeasurementInfo(a2lfile,'Triangle')
ans =
Name: 'Triangle'
LongIdentifier: 'Triangle test signal used for PWM output PWM'
DataType: 'SBYTE'
Conversion: 'BitSlice.CONVERSION'
Resolution: 0
Accuracy: 0
LowerLimit: -50
UpperLimit: 50
ECUAddress: 4951377
ECUAddressExtension: 0
ByteOrder: 'MSB_LAST'
SizeInBytes: 1
SizeInNibbles: 2
SizeInBits: 8
MATLABType: 'int8'
5-6
6
XCP Interface
XCP is a high-level protocol that allows you to acquire, stimulate and calibrate
data in electronic control units (ECU). XCP accesses ECU modules via an
interface such as CAN. The XCP master communicates with one or more slave
modules by sending commands. Using industry standard A2L files, you can
read and write to memory or perform data acquisition and stimulation.
6-2
XCP Hardware Connection
6-3
6 Universal Measurement & Calibration Protocol (XCP)
6-4
XCP Hardware Connection
In this section...
“Create XCP Channel Using `CAN Device” on page 6-5
“Configure the Channel to Unlock the Slave ” on page 6-6
a2lfile = xcpA2L('C:\work\XCPSIM.a2l')
a2lfile =
FileName: 'XCPSIM.a2l'
FilePath: 'C:\work\XCPSIM.a2l'
SlaveName: 'CPP'
ProtocolLayerInfo: [1x1 struct]
DAQInfo: [1x1 struct]
TransportLayerCANInfo: [1x1 struct]
Events: {1x6 cell}
Measurements: {1x38 cell}
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
6-5
6 Universal Measurement & Calibration Protocol (XCP)
SeedKeyDLL: []
Create your XCP channel and set the channel’s SeedKeyDLL property.
xcpch.SeedKeyDLL = ('C:\Work\SeedNKeyXcp.dll')
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyDLL: 'C:\Work\SeedNKeyXcp.dll'
Note Make sure the seed and key security access dll that you use matches
the version of your platform. You cannot use a 32-bit dll 64-bit MATLAB or
a 64-bit system.
6-6
Read a Single Value
a2lfile = xcpA2L('C:\work\XCPSIM.a2l');
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
connect(xcpch)
readSingleValue(xcpch, 'Triangle')
ans =
50
6-7
6 Universal Measurement & Calibration Protocol (XCP)
a2lfile = xcpA2L('C:\work\XCPSIM.a2l');
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
connect(xcpch)
6-8
Acquire Measurement Data via Dynamic DAQ Lists
Create an XCP channel linked to an A2L file and connect it to the slave.
a2lfile = xcpA2L('C:\work\XCPSIM.a2l');
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
connect(xcpch)
Create a DAQ list for the '10 ms' event with ,'PWMFiltered'and 'Triangle'
measurements.
startMeasurement(xcpch)
Read 10 samples of data from the configured measurement list for the
'Triangle' measurement.
18 18 18 18 18 18 18 18 18 18
6-9
6 Universal Measurement & Calibration Protocol (XCP)
a2lfile = xcpA2L('C:\work\XCPSIM.a2l');
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
connect(xcpch)
Note If your module is locked for STIM operations, configure the channel to
unlock the slave.
Create a STIM list for the '100ms' event with 'PWMFiltered'and 'Triangle'
measurements.
startMeasurement(xcpch)
6-10
7
CAN Communications in
Simulink
The Vehicle Network Toolbox block library is a tool for simulating message
traffic on a CAN network, as well for using the CAN bus to send and receive
messages. You can use blocks from the block library with blocks from other
Simulink libraries to create sophisticated models.
To use the Vehicle Network Toolbox block library, you require Simulink,
a tool for simulating dynamic systems. Simulink is a model definition
environment. Use Simulink blocks to create a block diagram that represents
the computations of your system or application. Simulink is also a model
simulation environment. Run the block diagram to see how your system
behaves. If you are new to Simulink, read “Getting Started with Simulink” to
understand its functionality better.
For more detailed information about the blocks in the Vehicle Network
Toolbox block library see “CAN Communication in Simulink”.
7-2
CAN Communication in Simulink®
7-3
7 CAN Communications in Simulink
This workflow represents the most common CAN Transmit model. Adjust
your model as needed. For more workflow examples, see “Build CAN
Communication Simulink Models” on page 7-10 and the Vehicle Network
Toolbox demos.
7-4
CAN Communication in Simulink®
• Use a Mux block to combine every message from the source if they are
transmitted at the same rate.
• Use one CAN Transmit block for each configured Mux block.
Message Filtering
Set up filters to process only relevant messages. This ensures optimal
simulation performance.
7-5
7 CAN Communications in Simulink
Downstream Processing
For any downstream processing using received messages, include blocks:
7-6
Open the Vehicle Network Toolbox Block Library
7-7
7 CAN Communications in Simulink
7-8
Open the Vehicle Network Toolbox Block Library
The Libraries pane lists all available block libraries, with the basic Simulink
library listed first, followed by other libraries listed alphabetically under it.
To open the Vehicle Network Toolbox block library, click its icon and select
CAN Communication for the CAN blocks.
7-9
7 CAN Communications in Simulink
Use this section with “Build a Message Receive Model” on page 7-16 and
“Save and Run the Model” on page 7-24 to build your complete model and
run the simulation.
7-10
Build CAN Communication Simulink® Models
simulink
in the MATLAB Command Window. The left pane in the Simulink Library
Browser lists the available block libraries. To open the Vehicle Network
Toolbox block library, click its icon. Then click CAN Communication to
open the CAN blocks. See Using the Simulink Library Browser for more
information.
For this example, create a model by clicking the New model button on the
toolbar.
7-11
7 CAN Communications in Simulink
You can also select File > New > Model from the Simulink Library Browser.
Simulink opens an empty editor. To name the new model, use the Save option.
7-12
Build CAN Communication Simulink® Models
7-13
7 CAN Communications in Simulink
holding the mouse button, drag the pointer to the input port of the CAN Pack
block. Then release the button.
In the same way, make a connection between the output port of the CAN Pack
block and the input port of the CAN Transmit block.
The CAN Configuration block does not connect to any other block. This block
configures the CAN channel used by the CAN Transmit block to transmit
the packed message.
Click OK.
Configure the CAN Pack Block. Double-click the CAN Pack block to open
its parameters dialog box. Set the:
Click OK.
7-14
Build CAN Communication Simulink® Models
Configure the Constant Block. Double-click the Constant block to open its
parameters dialog box. On the Main tab, set the:
• Constant value to [1 2 3 4 5 6 7 8]
• Sample time to 0.01 seconds
On the Signal Attributes tab, set the Output data type to uint8. Click OK.
7-15
7 CAN Communications in Simulink
Use this section with “Build a Message Transmit Model” on page 7-10 and
“Save and Run the Model” on page 7-24 to build your complete model and
run the simulation.
• “Step 7: Drag Vehicle Network Toolbox Blocks into the Model” on page 7-16
• “Step 8: Drag Other Blocks to Complete the Model” on page 7-17
• “Step 9: Connect the Blocks” on page 7-21
• “Step 10: Specify the Block Parameter Values” on page 7-22
Tip Configure a separate CAN channel for the CAN Receive and CAN
Transmit blocks.
7-16
Build CAN Communication Simulink® Models
7-17
7 CAN Communications in Simulink
7-18
Build CAN Communication Simulink® Models
3 Drop the CAN Unpack block from the Vehicle Network Toolbox block
library in this subsystem.
7-19
7 CAN Communications in Simulink
To see the results of the simulation visually, drag the Scope block from the
Simulink block library into your model.
7-20
Build CAN Communication Simulink® Models
1 Connect the CAN Msg output port on the CAN Receive block to the In1
input port on the Function–Call Subsystem block.
4 Connect the f() output port on the CAN Receive block to the function()
input port on the Function–Call Subsystem block.
5 Connect the CAN Unpack Subsystem output port to the input port on the
Scope block.
7-21
7 CAN Communications in Simulink
The CAN Configuration block does not connect to any other block. This
block configures the CAN channel used by the CAN Receive block to receive
the CAN message.
7-22
Build CAN Communication Simulink® Models
Click OK.
Configure the CAN Receive Block. Double-click the CAN Receive block to
open its Parameters dialog box. Set the:
Click OK.
Click OK.
7-23
7 CAN Communications in Simulink
7-24
Build CAN Communication Simulink® Models
When you run the simulation, the CAN Transmit block gets the message from
the CAN Pack block. It then transmits it via Virtual Channel 1. The CAN
Receive block on Virtual Channel 2 receives this message and hands it to the
CAN Unpack block to unpack the message.
While the simulation is running, the status bar at the bottom of the model
window updates the progress of the simulation.
7-25
7 CAN Communications in Simulink
7-26
Build CAN Communication Simulink® Models
If you cannot see all the data on the graph, click the Autoscale toolbar button,
which automatically scales both axes to display all stored simulation data.
In the graph, the horizontal axis represents the simulation time in seconds
and the vertical axis represents the received data value. In the Message
Transmit model, you configured blocks to pack and transmit an array of
constant values, [1 2 3 4 5 6 7 8], every 0.01 second of simulation time. In the
Message Receive model, these values are received and unpacked. The output
in the Scope window represents the received data values.
7-27
7 CAN Communications in Simulink
You can create custom Receive and Transmit blocks to use with hardware
currently not supported by the Vehicle Network Toolbox.
Vehicle Network Toolbox blocks use a custom CAN data type. To use the
blocks you create with other Vehicle Network Toolbox blocks, register this
custom CAN data type.
To use the custom data type defined in the Vehicle Network Toolbox, write a
C++ S-function.
Note You must use a C++ file type S-function (.cpp) to create custom blocks.
Using a C-file type S-function (.c) may cause linker errors.
To register and use the custom CAN data type, in your S-function:
#define IMPORT_SCANUTIL
#include "can_datatype.h"
7-28
Create Custom Blocks
mdlInitialize_CAN_datatype(S);
dataTypeID = ssGetDataTypeId(S,SL_CAN_MESSAGE_DTYPE_NAME);
7-29
7 CAN Communications in Simulink
7-30
8
XCP Communications in
Simulink
• XCP CAN Transport Layer— Transmit and Receive XCP messages over
CAN bus.
• XCP Configuration — Configure XCP settings.
• XCP Data Acquisition — Acquire XCP data.
• XCP Data Stimulation — Stimulate XCP data.
The Vehicle Network Toolbox XCP block library is a tool for simulating XCP
message traffic on a CAN network. You can use blocks from the block library
with blocks from other Simulink libraries to create sophisticated models.
To use the Vehicle Network Toolbox XCP block library, you require Simulink,
a tool for simulating dynamic systems. Simulink is a model definition
environment. Use Simulink blocks to create a block diagram that represents
the computations of your system or application. Simulink is also a model
simulation environment. Run the block diagram to see how your system
behaves. If you are new to Simulink, read “Getting Started with Simulink” to
understand its functionality better.
8-2
Open the Vehicle Network Toolbox XCP Block Library
8-3
8 XCP Communications in Simulink
The Libraries pane lists all available block libraries, with the basic Simulink
library listed first, followed by other libraries listed alphabetically under it.
To open the Vehicle Network Toolbox block library, click its icon and select
CAN Communication for the CAN blocks.
8-4
XCP Data Acquisition over CAN
For this example, you must install a third party XCP Sample implementation
from Vector. This includes a slave simulator and an A2L file. To install this
free implementation:
4 In MATLAB, navigate to where you installed the sample package, and then
go to .\Samples\XCPSim\CANape.
5 The MATLAB XCP examples will use the XCPSIM.a2l file and the
XCPsim.exe slave simulator. Run XCPsim.exe.
Create a model to set up XCP data acquisition for the measurements, Triangle
and PWM, from the slave.
• Use an XCP Configuration block and select the A2L file, XCPSim.a2l
8-5
8 XCP Communications in Simulink
• Use an XCP CAN Transport Layer block and set the Device to Vector
Virtual Channel 1. The transport layer is configured to transfer XCP
messages over CAN via the specified virtual channel.
• Use XCP Data Acquisition blocks to receive selected measurements
at specified events. For this example we have selected an XCP Data
Acquisition block for each measurement of each selected event.
Plot the results to see the measurement values for Triangle and PWM from
the slave. The X-axis corresponds to the simulation timestep.
8-6
9
Functions — Alphabetical
List
attachDatabase
Purpose Attach CAN database to messages and remove CAN database from
messages
Input message
Arguments The name of the CAN message that you want to attach the database
to or remove the database from.
database
Handle containing the database (.dbc file) that you want to attach to
the message or remove from the message.
Tips If the specified message is an array, then the database attaches itself
to each entry in the array. The database attaches itself to the message
even if the message you specified does not exist in the database. The
message then appears and operates like a raw message. To attach the
database to the CAN channel directly, edit the Database property of
the channel object.
9-2
canChannel
Tips • You cannot have more than one canChannel configured on the same
NI-CAN, NI-XNET, or PEAK-System device channel.
• Use canHWInfo to obtain a list of available devices.
Input vendor
Arguments The name of the CAN device vendor. Specify the vendor name as a
string.
device
The CAN interface that you want to connect to.
9-3
canChannel
devicechannelindex
An alpha-numeric channel on the specified device.
canch
The CAN channel object the you create.
9-4
canChannel
Notes You cannot use the same variable to create multiple channels
sequentially. Clear any channel in use before using the same variable
to construct a new CAN channel.
You cannot create arrays of CAN channel objects. Each object you
create must exist as its own individual variable.
9-5
canDatabase
Input dbfile.dbc
Arguments Database file name. You can specify just the name or the full path of
the database file.
9-6
canHWInfo
Output out
Arguments Handle that will hold the results of canHWInfo.
ans =
g = get(info)
g =
9-7
canHWInfo
9-8
canMessage
Input id
Arguments The ID of the message that you specify.
extended
Indicates whether the message ID is of standard or extended type. The
Boolean value is true if extended or false if standard.
datalength
The length of the data of the message, in bytes. Specify from 0 through
8.
database
Handle to the CAN database containing the message definition.
messagename
The name of the message definition in the database.
Output message
Arguments The message object returned from the function.
9-9
canMessage
candb = canDatabase('c:\database.dbc')
message = canMessage (candb, 'messagename')
9-10
canMessageImport
Tips • You can import message logs only in certain file formats. You can
import only ASCII files from Vector and text files from Kvaser.
• canMessageImport assumes that the information in the imported log
file is in a hexadecimal format.
• canMessageImport assumes that the timestamps in the imported log
file are absolute values.
• To import Vector log files with symbolic message names, specify an
appropriate database file in the input arguments.
Input file
Arguments Name of the CAN message log file to import.
vendor
Name of the vendor whose CAN message log file to import.
database
9-11
canMessageImport
Output message
Arguments The message object returned by the function.
database = canDatabase('myDatabase.dbc')
message = canMessageImport('MsgLog.txt', 'Kvaser', database)
9-12
canSupport
Syntax canSupport()
9-13
canTool
Syntax canTool
Description canTool starts the Vehicle CAN Bus Monitor, which displays live CAN
message traffic. Use the CAN Tool to view message traffic using a
selected CAN device and channel. You can also save messages to a
log file via this tool.
For more information about the Bus Monitor, refer to “Monitor Vehicle
CAN Bus”.
9-14
configBusSpeed
Tips • Unless you have specific timing requirements for your CAN
connection, use the direct form of configBusSpeed. Also note that
you can set the bus speed only when the CAN channel is offline. The
channel must also have initialization access to the CAN device.
• Synchronize all nodes on the network for CAN to work successfully.
However, over time, clocks on different nodes will get out of sync,
and must resynchronize. SJW specifies the maximum width (in time)
that you can add to tseg1 (in a slower transmitter), or subtract from
tseg2 (in a faster transmitter) to regain synchronization during the
receipt of a CAN message.
Input canch
Arguments The CAN channel object that you want to set the bit timing rate for.
busspeed
The user-specified bit timing rate for the specified object.
sjw
The synchronization jump width. This value is the maximum value of
time bit adjustments.
9-15
configBusSpeed
tseg1
The length of time at the start of the sample point within a bit time.
tseg2
The length of time at the end of the sample point within a bit time.
numberofsamples
The specified count of bit samples used.
Examples To configure the bus speed using baseline bit timing calculation, type:
9-16
discard
Syntax discard(canch)
Input canch
Arguments CAN channel that you want to discard the messages from.
Examples Set up a CAN channel to receive messages and discard the messages
received by the channel.
discard(rxCh);
9-17
extractAll
Input message
Arguments An array of CAN message objects that you specify to parse and find the
specified messages by name or ID.
messagename
The name of the message that you specify to extract.
id
The ID of the message that you specify to extract.
extended
Indicates whether the message ID is a standard or extended type. The
Boolean value is true if extended and false if standard.
9-18
extractAll
Output extracted
Arguments An array of CAN message objects returned with all instances of id
found in the message.
remainder
A CAN message object containing all messages in the original input
message with all instances of id removed.
9-19
extractRecent
Tips You can specify id as a vector of identifiers. For example, if you pass
id in as [250 500], extractRecent returns the latest instance of both
CAN message 250 and message 500 if it finds them in the message
array. By default, all identifiers in the vector are standard CAN
message identifiers unless extended is true. If any id in the vector is
an extended type, then extended is true and is a vector of the same
length as id.
Input message
Arguments An array of CAN message objects that you specify to parse and find the
specified messages by name or ID.
messagename
The name of the message that you specify to extract.
id
The id of the message that you specify to extract.
9-20
extractRecent
extended
Indicates whether the message ID is a standard or extended type. The
Boolean value is true if extended and false if standard.
Output extracted
Arguments An array of CAN message objects returned with the most recent
instance of id found in the message.
9-21
extractTime
Purpose Select messages occurring within specified time range from array of
messages
Tips Specify the time range in increasing order from starttime to endtime.
If you must specify the largest available time, endtime also accepts
Inf as a valid value. The earliest acceptable time you can specify for
starttime is 0.
Input message
Arguments An array of CAN message objects.
starttime
The beginning of the time range in seconds that you specify. Returns
messages with a timestamp greater than or equal to the specified start
time.
endtime
The end of the time range in seconds that you specify. Parses messages
with a timestamp up to the specified end time, including the specified
end time.
Output extracted
Arguments An array of CAN message objects returned with all messages that occur
within and including starttime and endtime.
9-22
extractTime
9-23
filterAllowAll
Syntax filterAllowAll(canch,'type')
Input canch
Arguments The CAN channel on which you want to filter messages.
type
The identifier type by which to filter. CAN messages are 'Standard'
and 'Extended'.
Examples To allow all standard and extended message typed to pass the filter,
type:
9-24
filterAllowOnly
Tips • Use Database to attach a database to your CAN channel and filter
messages using message names.
• The id value is stored as a decimal value. To convert a hexadecimal
to a decimal value, use the hex2dec function.
Input canch
Arguments The CAN channel on which you want to filter messages.
name
the name of the CAN message that you want to allow. You can specify a
single name as a string or a cell array of message names.
ids
The CAN message ID or IDs that you want to allow. You can specify:
• Single value, such as 600
• Multiple values, such as [600,610]
• Range of values, such as [600:800]
• Multiple ranges, such as [200:400, 600:800]
type
9-25
filterAllowOnly
9-26
filterBlockAll
Syntax filterBlockAll(canch,'type')
Input canch
Arguments The CAN channel on which you want to filter messages.
type
The identifier type by which to filter messages. CAN messages are
'Standard' and 'Extended'.
9-27
filterAcceptRange
Notes
• You can configure message filtering only when the CAN channel is
offline.
• CAN message filters initialize to fully open.
• filterReset makes the acceptance filters fully open.
• filterAcceptRange supports only standard (11-bit) CAN identifiers.
• You must set the values from rangestart through rangeend in
increasing order.
• filterAcceptRange and filterBlockRange work together by
allowing and blocking ranges of CAN messages within a single filter.
You can perform both operations multiple times in sequence to
custom configure the filter as desired.
9-28
filterAcceptRange
Input canch
Arguments The CAN channel that you want to set the filter for.
rangestart
The first identifier of the range of message IDs that the filter accepts.
rangeend
The last identifier of the range of message IDs that the filter accepts.
9-29
filterBlockRange
Tips • You can configure message filtering only when the CAN channel is
offline.
• CAN message filters initialize to fully open.
• filterReset makes the acceptance filters fully open.
• filterBlockRange supports only standard (11-bit) CAN identifiers.
• You must set the values from rangestart through rangeend in
increasing order.
• filterBlockRange and filterAcceptRange work together by
blocking and allowing ranges of CAN messages within a single filter.
You can perform both operations multiple times in sequence to
custom configure the filter as desired.
Input canch
Arguments The CAN channel that you want to set the filter for.
rangestart
9-30
filterBlockRange
The first identifier of the range of message IDs that the filter starts
blocking at.
rangeend
The last identifier of the range of message IDs that the filter stops
blocking at.
Examples You can set the filter to block or accept messages within a specific range.
9-31
filterReset
Syntax filterReset(canch)
Input canch
Arguments The CAN channel that you want to reset the filter for.
9-32
filterSet
Tips • You can configure message filtering only when the CAN channel is
offline.
• CAN message filters initialize to fully open.
• Use filterReset to make the acceptance filters fully open.
• filterSet supports either standard or extended CAN identifiers.
Input canch
Arguments The CAN channel that you want to set the filter for.
code
The value required for each bit position of the identifier.
9-33
filterSet
mask
The bits in the identifier that are relevant to the filter.
id
Set a filter on the CAN message with the id, range of ids, multiple
ranges of ids, or a combination of ids.
idtype
A string specifying either a standard or an extended CAN message
id type.
To let Vehicle Network Toolbox determine the best possible code and
mask option:
9-34
get
Description out = get (obj) returns the structure out, where each field name is
the name of a property of the specified object and each field contains
the value of that property.
get (canch)
get (message)
candb = canDatabase('C:\Database.dbc')
9-35
get
get (candb)
9-36
messageInfo
Input candb
Arguments The database containing the CAN messages that you want information
about.
msgName
The name of the message you want information about.
id
The numeric identifier of the specified message.
extended
Indicates whether the message ID is in standard or extended type. The
Boolean value is true if extended and false if standard.
Output msgInfo
Arguments Handle for the returned CAN messages in the specified database.
9-37
messageInfo
9-38
pack
Input message
Arguments The CAN message structure that you specify for the signal to be packed
in.
value
The value of the signal you specify to be packed in the message.
startbit
The signal’s starting bit in the data. This is the least significant bit
position in the signal data. Accepted values for startbit are from 0
through 63.
signalsize
The length of the signal in bits. Accepted values for signalsize are
from 1 through 64.
byteorder
The signal byte order format. Accepted values are 'LittleEndian'
and 'BigEndian'.
9-39
receive
Input canch
Arguments The CAN channel from which to receive the message.
messagesrequested
The maximum count of messages to receive. The specified value must
be a nonzero and positive, or Inf.
Output message
Arguments An array of CAN message objects received from the channel.
9-40
receive
message = receive(canch,Inf)
9-41
replay
Arguments
Input canch
Arguments The CAN channel that you specify to transmit the messages.
message
An array of message objects to replay.
Examples This example uses a loopback connection between two channels where:
• The first channel transmits messages 2 seconds apart.
• The second channel receives them.
• The replay function retransmits the messages with the original
delay.
ch1 = canChannel('Vector', 'CANcaseXL 1', 1)
ch2 = canChannel('Vector', 'CANcaseXL 1', 2)
start(ch1)
start(ch2)
msgTx1 = canMessage(500, false, 8)
msgTx2 = canMessage(750, false, 8)
%The first channel transmits messages 2 seconds apart
9-42
replay
transmit(ch1, msgTx1)
pause(2)
transmit(ch1, msgTx2)
%The second channel receives them
msgRx1 = receive(ch2, Inf)
%The replay function retransmits the messages with the original delay.
replay(ch2, msgRx1)
pause(2)
msgRx2 = receive(ch1, Inf)
9-43
set
candb = canDatabase('C:\Database.dbc')
message = canMessage(candb, 'Battery_Voltage')
set (message, 'BatVlt', 9.3)
9-44
signalInfo
Input candb
Arguments The database containing the signals that you want information about.
msgName
The name of the message that contains the signals that you want
information about.
id
The numeric identifier of the specified message that contains the
signals you want information about.
extended
Indicates whether the message ID is in standard or extended type. The
Boolean value is true if extended and false if standard.
signalName
9-45
signalInfo
The name of the specific signal that you want information about.
Output SigInfo
Arguments The signal information object returned from the function.
9-46
start
Syntax start(canch)
Description start(canch) starts the CAN channel canch on the CAN bus to send
and receive messages. The CAN channel remains online unless:
• You call stop on this channel.
• The channel clears from the workspace.
9-47
stop
Syntax stop(canch)
Description stop(canch) stops the CAN channel canch on the CAN bus. The CAN
channel also stops running when you clear canch from the workspace.
9-48
transmit
Description transmit(canch, message) sends the array of messages onto the bus
via the CAN channel.
To understand the elements of a message, refer to canMessage.
Tips The Transmit function ignores the Timestamp property and the Error
property.
Input canch
Arguments The CAN channel that you specify to transmit the message.
message
The message or an array of messages that you specify to transmit via
a CAN channel.
9-49
transmit
start(canch)
transmit(canch, message)
9-50
transmitConfiguration
Syntax transmitConfiguration(canch)
Input canch
Arguments Name of the CAN channel configured for periodic transmit or
event-based transmit.
transmitConfiguration(canch)
Periodic Messages
9-51
transmitConfiguration
Event Messages
9-52
transmitEvent
Input canch
Arguments The name of the CAN channel on which the specified message is
enabled for event-based transmit.
msg
The message enabled for event-based transmission on the specified
CAN channel.
’state’
Specify whether event-based transmission is enabled on the specified
message. Input On to enable event-based transmission on the specified
message, and Off for disabling it.
Enable the message for event-based transmit, start the channel, and
change some data to trigger the event-based transmit:
9-53
transmitPeriodic
Tips You can enable and disable periodic transmit even when the channel
is running. This functionality allows you to make changes to the state
of the channel without stopping the channel.
Input canch
Arguments The name of the CAN channel on which the specified message is
enabled for periodic transmit.
msg
The message enabled for periodic transmission on the specified CAN
channel.
’state’
Specify whether periodic transmission is enabled on the specified
message. Input On for enabling periodic transmission on the specified
message and Off to disable it. If you enable periodic transmission,
specify a period value.
period
Specify a period in seconds. This value is used to transmit the message
in the specified period. By default this value is 0.500 seconds.
9-54
transmitPeriodic
Enable the message for periodic transmit. Set the period value to 1
sec, start the channel, and update the data in the message you want
to send periodically:
9-55
unpack
Input message
Arguments The CAN message structure that you specify for the signal to be
unpacked from.
startbit
The signal’s starting bit in the data. This is the least significant bit
position in the signal data. Accepted values for starbit are from 0
through 63.
signalsize
The length of the signal in bits. Accepted values for signalsize are
from 1 through 64.
byteorder
The signal binary or binblock format. Accepted values are LittleEndian
and BigEndian.
datatype
The data type that you want to get the unpacked value in.
Output value
Arguments The value of the message that you specify to be unpacked.
9-56
unpack
9-57
xcpA2L
a2lfile = xcpA2L('XCPSIM.a2l')
9-58
getEventInfo
Purpose Get event information about specific event from A2L file
a2lfile = xcpA2L('C:\XCPSIM.a2l')
info = getEventInfo (a2lfile, '10 ms')
info =
9-59
getEventInfo
Direction: 'DAQ_STIM'
MaxDAQList: 255
ChannelNumber: 1
ChannelTimeCycle: 10
ChannelTimeUnit: 6
ChannelPriority: 0
ChannelTimeCycleInSeconds: 0.0100
9-60
getMeasurementInfo
a2lfile = xcpA2L('C:\XCPSIM.a2l')
info = getMeasurementInfo (a2lfile, 'PWM')
info =
9-61
getMeasurementInfo
Name: 'PWM'
LongIdentifier: 'Pulse width signal from PWM_level and Triangle'
DataType: 'UBYTE'
Conversion: 'HighLow'
Resolution: 0
Accuracy: 0
LowerLimit: 0
UpperLimit: 255
ECUAddress: 4951352
ECUAddressExtension: 0
ByteOrder: 'MSB_LAST'
SizeInBytes: 1
SizeInNibbles: 2
SizeInBits: 8
MATLABType: 'uint8'
9-62
xcpChannel
Syntax xcpch =
xcpChannel(a2lFile,transportLayer,vendor,deviceNumber)
xcpch = xcpChannel(a2lFile,transportLayer,vendor,device,
deviceChannelIndex)
Description xcpch =
xcpChannel(a2lFile,transportLayer,vendor,deviceNumber) create
a channel connected to the CAN bus via the specified transport layer,
vendor and device and a defined interface number. The XCP
channel accesses the slave module via the specified CAN bus
and parsing the attached A2L file.
Use this syntax for National Instruments CAN devices, where vendor is
the literal string 'NI' and the deviceNumber is the interface number
defined for the channel in NI Measurement & Automation Explorer.
xcpch = xcpChannel(a2lFile,transportLayer,vendor,device,
deviceChannelIndex) returns a handle for the created channel
connected to the CAN bus via the specified transport layer, vendor
and device with a channel index. The XCP channel accesses the slave
module via the specified CAN bus and parsing the attached A2L file.
Input
Arguments
a2lFile - Name of A2L file
character string
Name of the A2L file object, specified as a string, used in this connection.
Create the A2L file handle using xcpA2L.
9-63
xcpChannel
a2l = xcpA2L('XCPSIM.a2l')
9-64
xcpChannel
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyCallbackFcn: []
KeyValue: []
9-65
connect
Syntax connect(xcpch)
a2lfile = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
connect (xcpch)
isConnected(xcpch)
ans =
9-66
disconnect
Syntax disconnect(xcpch)
a2l = xcpA2L('XCPSIM.a2l')
connect(xcpch);
isConnected(xcpch)
ans =
9-67
disconnect
disconnect(xcpch)
isConnected(xcpch)
ans =
9-68
isConnected
Syntax isConnected(xcpch)
ans =
9-69
createMeasurementList
Syntax createMeasurementList(xcpch,resource,eventName,measurementName)
createMeasurementList(xcpch,resource,eventName,{measurementName,
measurementName,measurementName})
Description createMeasurementList(xcpch,resource,eventName,measurementName)
creates a data stimulation list for the XCP channel with the
specified event and measurement.
createMeasurementList(xcpch,resource,eventName,{measurementName,
measurementName,measurementName}) creates a data stimulation list
for the XCP channel with the specified event and list of measurements.
9-70
createMeasurementList
a2lfile = xcp.A2L('XCPSIM.a2l')
xcpch = xcp.Channel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1)
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyDLL: []
connect(xcpch)
Setup a data acquisition measurement list with the ‘10 ms’ event and
'Triangle' measurement.
a2l = xcp.A2L('XCPSIM.a2l')
xcpch = xcp.Channel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1)
xcpch =
Channel with properties:
9-71
createMeasurementList
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyDLL: []
connect(xcpch)
Setup a data stimulation measurement list with the ‘100ms’ event and
'PWM' and 'ShiftByte' measurements.
9-72
freeMeasurementLists
Syntax freeMeasurementLists(xcpch)
a2lfile = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
connect(xcpch)
Setup a data acquisition measurement list with the '10 ms' event and
'PMW' measurement.
9-73
freeMeasurementLists
viewMeasurementLists (xcpch)
DAQ List #1 using the "10 ms" event @ 0.010000 seconds and the following
PWM
DAQ List #2 using the "100ms" event @ 0.100000 seconds and the following
PWMFiltered
Triangle
freeMeasurementLists(xcpch)
9-74
viewMeasurementLists
Syntax viewMeasurementLists(xcpch)
a2lfile = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1)
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyCallbackFcn: []
KeyValue: []
9-75
viewMeasurementLists
connect(xcpch)
Setup a data acquisition measurement list with the '10 ms' event and
'PMW' measurement.
viewMeasurementLists (xcpch)
DAQ List #1 using the "10 ms" event @ 0.010000 seconds and the following
PMW
DAQ List #2 using the "100ms" event @ 0.100000 seconds and the following
PWMFiltered
Triangle
9-76
startMeasurement
Syntax startMeasurement(xcpch)
a2l = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1'1),
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyCallbackFcn: []
KeyValue: []
9-77
startMeasurement
connect(xcpch)
Setup a data acquisition measurement list with the ‘10 ms’ event and
'Bitslice' measurement.
startMeasurement(xcpch);
a2l = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1)
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyCallbackFcn: []
KeyValue: []
connect(xcpch)
Setup a data stimulation measurement list with the ‘100ms’ event and
'Bitslice0', 'PWMFiletered', and 'Triangle'measurements.
9-78
startMeasurement
startMeasurement(xcpch);
9-79
stopMeasurement
Syntax stopMeasurement(xcpch)
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyCallbackFcn: []
KeyValue: []
9-80
stopMeasurement
connect(xcpch)
Setup a data acquisition measurement list with the ‘10 ms’ event and
'Bitslice' measurement and start your measurement.
stopMeasurement(xcpch);
9-81
isMeasurementRunning
Syntax isMeasurementRunning(xcpch)
a2l = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
Setup a data acquisition measurement list with the ‘10 ms’ event and
'Bitslice' measurement and verify if measurement is running.
ans =
startMeasurement(xcpch);
isMeasurementRunning(xcpch)
9-82
isMeasurementRunning
ans =
9-83
readDAQListData
9-84
readDAQListData
a2lfile = xcp.A2L('XCPSIM.a2l')
xcpch = xcp.Channel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
connect (xcpch)
startMeasurement (xcpch)
value =
9-85
readDAQListData
Related • “Acquire Measurement Data via Dynamic DAQ Lists” on page 6-9
Examples
9-86
writeSTIMListData
Syntax writeSTIMListData(xcpch,measurementName,value)
a2lfile = xcp.A2L('XCPSIM.a2l')
xcpch = xcp.Channel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
9-87
writeSTIMListData
connect (xcpch)
startMeasurement (xcpch)
9-88
readSingleValue
a2lfile = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
9-89
readSingleValue
connect(xcpch)
value =
14
9-90
writeSingleValue
Syntax writeSingleValue(xcpch,measurementName,value)
a2l = xcpA2L('XCPSIM.a2l')
9-91
writeSingleValue
9-92
can.ChannelInfo
Properties Device
Name of the device.
DeviceChannelIndex
Index number of the specified device channel.
DeviceSerialNumber
Serial number of the specified device.
ObjectConstructor
Information on how to construct a CAN channel using this device.
info = canHWInfo
info =
9-93
can.ChannelInfo
g = get(info);
vendor = g.VendorInfo(1);
vendor.ChannelInfo(1)
ans =
See Also
Functions canHWInfocan.VendorInfo
9-94
can.VendorInfo
Properties VendorName
Name of the device vendor.
VendorDriverDescription
Description of the device driver installed for this vendor.
VendorDriverVersion
Version of the device driver installed for this vendor.
ChannelInfo
Information on the device channels available for this vendor.
info = canHWInfo
info =
9-95
can.VendorInfo
g = get(info);
g.VendorInfo
ans =
VendorName
VendorDriverDescription
VendorDriverVersion
ChannelInfo
See Also
Functions canHWInfo
can.ChannelInfo
9-96
10
Properties — Alphabetical
List
BusLoad property
Description The BusLoad property displays information about the load on the CAN
network for message traffic on Kvaser devices.
10-2
BusSpeed property
Description The BusSpeed property determines the bit rate at which messages are
transmitted. You can set BusSpeed to an acceptable bit rate using the
configBusSpeed function.
Values The default value is assigned by the vendor driver. To change the bus
speed of your channel, use the configBusSpeed function and pass the
channel name and the value as input parameters.
Examples To change the current BusSpeed of the CAN channel object canch to
250000, type:
configBusSpeed(canch, 250000)
Properties
NumOfSamples, SJW, TSEG1, TSEG2
10-3
BusStatus property
Description The BusStatus property displays information about the state of the
CAN bus.
Values • N/A
• BusOff
• ErrorOff
• ErrorActive
10-4
Data property
Description Use the Data property to define your message data in a CAN message.
Values The data value is a uint8 array, based on the data length you specify
in the message.
If you are using a CAN database for your message definitions, change
values of the specific signals in the message directly.
You can also use the pack function to load data into your message.
10-5
Database property
Values This property displays the database information that your CAN channel
or CAN message is attached to. This property displays an empty
structure, [ ], if your channel message is not attached to a database.
You can edit the CAN channel property, Database, but cannot edit
the CAN message property.
Examples To see information about the database attached to your CAN message,
type:
message.Database
channel.Database = canDatabase('C:\Database.dbc')
10-6
Database property
10-7
Device property
Description For National Instruments devices, the Device property displays the
device number on the hardware.
For all other devices, the Device property displays information about
the device type to which the CAN channel is connected.
Values Values are automatically defined when you configure the channel with
the canChannel function.
Properties
DeviceChannelIndex, DeviceSerialNumber, DeviceVendor
10-8
Device(NI) property
Values Values are automatically defined when you configure the channel with
the canChannel function.
Properties
DeviceChannelIndex, DeviceVendor
10-9
DeviceChannelIndex property
Values Values are automatically defined when you configure the channel with
the canChannel function.
Properties
Device, DeviceVendor
10-10
DeviceSerialNumber property
Values Values are automatically defined when you configure the channel with
the canChannel function.
Properties
Device, DeviceVendor
10-11
DeviceVendor property
Description The DeviceVendor property displays the name of the device vendor.
Values Values are automatically defined when you configure the channel with
the canChannel function.
Properties
Device, DeviceChannelIndex, DeviceSerialNumber
10-12
Error property
Description The Error property is a read-only value that identifies the specified
CAN message as an error frame. The channel sets this property to true
when it receives a CAN message as an error frame.
10-13
Extended property
Description The Extended property is the identifier type for a CAN message. It can
either be a standard identifier or an extended identifier.
Examples To set the message identifier type to extended with the ID set to 2350
and the data length to 8 bytes, type:
Properties
ID
10-14
ID property
You can also specify a hexadecimal value using the hex2dec function.
Properties
Extended
10-15
InitializationAccess property
Values • Yes — Has full control of the hardware channel and can change the
property values.
• No — Does not have full control and cannot change property values.
10-16
MessageReceivedFcn property
Values The default value is an empty string. You can specify the name of a
callback function that you want to run when the specified number of
messages are available.
You can also use the set function to set the values of this property.
Properties
MessageReceivedFcnCount, MessagesAvailable
10-17
MessageReceivedFcnCount property
Values The default value is 1. You can specify a positive integer for your
MessageReceivedFcnCount.
Examples canch.MessageReceivedFcnCount = 55
You can also use the set function to set the values of this property.
Properties
MessageReceivedFcn, MessagesAvailable
10-18
Messages property
Description The Messages property stores the names of all messages defined in
the selected CAN database.
Values The Messages property displays a cell array of strings. You cannot
edit this property.
10-19
MessagesAvailable property
Properties
MessagesReceived, MessagesTransmitted
10-20
MessagesReceived property
Values The value is 0 when no messages have been received. This number
increments based on the number of messages the channel receives.
Properties
MessagesAvailable, MessagesTransmitted
10-21
MessagesTransmitted property
Values The default is 0 when no messages have been sent. This number
increments based on the number of messages the channel transmits.
Properties
MessagesAvailable, MessagesReceived
10-22
Name (Database) property
Description The Name (Database) property displays the name of the database.
Values Name is a string value. This value is acquired from the name of the
database file. You cannot edit this property.
Properties
Extended, ID
10-23
Name (Message) property
Description The Name (Message) property displays the name of the message.
Values Name is a string value. This value is acquired from the name of the
message you defined in the database. You cannot edit this property if
you are defining raw messages.
Properties
Extended, ID
10-24
NumOfSamples property
Values The value is a positive integer based on the driver settings for the
channel.
Properties
BusSpeed, SJW, TSEG1, TSEG2
10-25
Path property
Description The Path property displays the path to the CAN database.
Values The path name is a string value, pointing to the CAN database in your
directory structure.
10-26
ReceiveErrorCount property
Properties
TransmitErrorCount
10-27
Remote property
Description Use the Remote property to specify the CAN message as a remote frame.
Examples To change the default value of Remote and make the message a remote
frame, type:
message.Remote = true
10-28
Running property
Description The Running property displays information about the state of the CAN
channel.
10-29
SilentMode property
canch.SilentMode = true
canch.SilentMode = false
You can also use the set function to set the values of this property.
10-30
Signals property
Description The Signals property allows you to view and edit signal values defined
for a CAN message. This property displays an empty structure if the
message has no defined signals or a CAN database is not attached to the
message. The input values for this property depends on the signal type.
message.Signals
ans =
VehicleSpeed: 0
EngineRPM: 250
message.Signals.EngineRPM = 300
10-31
SJW property
Description In order to adjust the on-chip bus clock, the CAN controller may shorten
or prolong the length of a bit by an integral number of time segments.
The maximum value of these bit time adjustments are termed the
synchronization jump width or SJW.
Values The value of the SJW is determined by the specified bus speed.
Properties
BusSpeed, NumOfSamples, TSEG1, TSEG2
10-32
Timestamp property
Description The Timestamp property displays the time at which the message
was received on a CAN channel. This time is based on the receiving
channel’s start time.
Values Timestamp displays a numeric value indicating the time the message
was received, based on the start time of the CAN channel
message.Timestamp = 12
10-33
TransceiverName property
Description The CAN transceiver translates the digital bit stream going to and
coming from the CAN bus into the real electrical signals present on
the bus.
Values Values are automatically defined when you configure the channel with
the canChannel function.
Properties
TransceiverState
10-34
TransceiverState property
Description If your CAN transceiver allows you to control its mode, you can use the
TransceiverState property to set the mode.
Values The values are defined by the transceiver manufacturer. Refer to your
CAN transceiver documentation for the appropriate transceiver modes.
Possible modes representing the numeric value specified are:
• high speed
• high voltage
• sleep
• wake up
Properties
TransceiverName
10-35
TransmitErrorCount property
Properties
ReceiveErrorCount
10-36
TSEG1 property
Description The TSEG1 property displays the amount in bit time segments that the
channel can lengthen the sample time to compensate for delay times
in the network.
Values The value is inherited when you configure the bus speed of your CAN
channel.
Properties
BusSpeed, NumOfSamples, SJW, TSEG2
10-37
TSEG2 property
Description The TSEG2 property displays the amount of bit time segments the
channel can shorten the sample to resynchronize.
Values The value is inherited when you configure the bus speed of your CAN
channel.
Properties
BusSpeed, NumOfSamples, SJW, TSEG1
10-38
UserData property
Description Use the UserData property to enter custom data to be stored in your
CAN channel, message, or database object. When you save an object
with UserData specified, you automatically save the custom data. When
you load an object with UserData specified, you automatically load the
custom data.
Note To avoid unexpected results when you save and load an object
with UserData, specify your custom data in simple data types and
constructs.
10-39
Events property
Description The Events property displays events available in the selected A2L
description file. This property contains a cell array of strings that
correspond to the names of events in the A2L file. To use the A2L file
events, see “Access Event Information” on page 5-3.
10-40
Measurements property
10-41
DAQInfo property
10-42
SlaveName property
Description The SlaveName property displays the name of the slave node as specified
in the A2L file. The name is specified as a string.
10-43
FileName property
Description The FileName property displays the name of the referenced A2L file
as a string.
10-44
FilePath property
Description The FileName property displays the full file path to the A2L file as a
string.
10-45
ProtocolLayerInfo property
10-46
TransportLayerCANInfo property
10-47
A2LFileName property
Description The A2LFileName property displays the name of the A2L file contains
information about the slave that an XCP channel can access.
10-48
SeedKeyDLL property
Description The SeedKeyDLL property displays the name of the dll file that contains
the seed and key security algorithm used to unlock an XCP slave
module.
10-49
TransportLayer property
Description The TransportLayer property displays the type of transport layer used
in the XCP connection.
10-50
TransportLayerDevice property
10-51
TransportLayerDevice
10-52
11
Block Reference
CAN Configuration
CAN Log
CAN Pack
CAN Receive
CAN Replay
CAN Transmit
CAN Unpack
XCP Configuration
XCP Data Acquisition
XCP Data Stimulation
XCP CAN Transport Layer
XCP CAN TL Receive
XCP CAN TL Transmit
CAN Configuration
Description
Note You need a license for both Vehicle Network Toolbox and
Simulink software to use this block.
11-2
CAN Configuration
Dialog Use the Block Parameters dialog box to select your CAN device
Box configuration.
Device
Select the CAN device and a channel on the device that you want
to use from the list. Use this device to transmit and/or receive
messages. The device driver determines the default bus speed.
Bus speed
Set the bus speed property for the selected device. The default
bus speed is the default assigned by the selected device.
Enable bit parameters manually
11-3
CAN Configuration
Tip Use the default bit parameter settings unless you have
specific timing requirements for your CAN connection.
11-4
CAN Configuration
Number of samples
Specify the total number of samples available to this channel. The
specified value must be a positive integer. If you do not specify
a value, the selected bus speed setting determines the default
value. To change this value, select the Enable bit parameters
manually check box first. Refer to the NumOfSamples property
for more information.
Verify bit parameter settings validity
If you have set the bit parameter settings manually, click this
button to see if your settings are valid. The block then runs a
check to see if the combination of your bus speed setting and the
bit parameter value forms a valid value for the CAN device. If the
new bit parameter values do not form a valid combination, the
verification fails and displays an error message.
Acknowledge mode
Specify whether the channel is in Normal or Silent mode. By
default Acknowledge mode is Normal. In this mode, the
channel both receives and transmits messages normally and
performs other tasks on the network such as acknowledging
messages and creating error frames. To observe all message
activity on the network and perform analysis, without affecting
the network state or behavior, select Silent. In Silent mode, you
can only receive messages and not transmit.
Notes
• You cannot specify the mode if you are using NI virtual
channels.
• Use Silent mode only if you want to observe and analyze your
network activity.
11-5
CAN Log
Description
The CAN Log block logs CAN messages from the CAN network or
messages sent to the blocks input port to a .mat file. You can load the
saved messages into MATLAB for further analysis or into another
Simulink model.
11-6
CAN Log
Note You need a license for both Vehicle Network Toolbox and
Simulink software to use this block.
11-7
CAN Log
In this example, gcs is the current model that you wish to build.
Building the model creates a zip file with the same name as model
name. You can move this zip file to another machine and the source
code in the zip file can be built to create an executable which can be run
independent of MATLAB and Simulink. The generated code compiles
with both C and C++ compilers. For more information on packNGo,
see packNGo.
Dialog Use the Block Parameters dialog box to configure your message logging.
Box
Tip If you are logging from the network, you need to configure your
CAN channel with a CAN Configuration block.
11-8
CAN Log
File name
Type the name and path of the file to log CAN messages to, or
click Browse to browse to a file location.
The model appends the log file name with the current date and
time in the YYYY-MMM-DD_hhmmss format. You can also open the
block mask and specify a unique name to differentiate between
your files for repeated logging.
Variable Name
Type the variable saved in the MAT-file that holds the CAN
message information.
11-9
CAN Log
11-10
CAN Pack
Description
The CAN Pack block loads signal data into a message at specified
intervals during the simulation.
Note To use this block, you also need a license for Simulink software.
CAN Pack block has one input port by default. The number of block
inputs is dynamic and depends on the number of signals you specify for
the block. For example, if your block has four signals, it has four block
inputs.
This block has one output port, CAN Msg. The CAN Pack block takes
the specified input parameters and packs the signals into a message.
11-11
CAN Pack
Dialog Use the Function Block Parameters dialog box to select your CAN Pack
Box block parameters.
Parameters
Data is input as
Select your data signal:
• raw data: Input data as a uint8 vector array. If you select this
option, you only specify the message fields. all other signal
11-12
CAN Pack
11-13
CAN Pack
CANdb file
This option is available if you specify that your data is input
via a CANdb file in the Data is input as list. Click Browse to
find the CANdb file on your system. The message list specified
in the CANdb file populates the Message section of the dialog
box. The CANdb file also populates the Signals table for the
selected message.
11-14
CAN Pack
Message list
This option is available if you specify that your data is input via a
CANdb file in the Data is input as field and you select a CANdb
file in the CANdb file field. Select the message to display signal
details in the Signals table.
Message
Name
Specify a name for your CAN message. The default is CAN
Msg. This option is available if you choose to input raw data or
manually specify signals. This option in unavailable if you choose
to use signals from a CANdb file.
Identifier type
Specify whether your CAN message identifier is a Standard or an
Extended type. The default is Standard. A standard identifier
is an 11-bit identifier and an extended identifier is a 29-bit
identifier. This option is available if you choose to input raw data
or manually specify signals. For CANdb specified signals, the
Identifier type inherits the type from the database.
Identifier
Specify your CAN message ID. This number must be a positive
integer from 0 through 2047 for a standard identifier and from
0 through 536870911 for an extended identifier. You can also
specify hexadecimal values using the hex2dec function. This
option is available if you choose to input raw data or manually
specify signals.
11-15
CAN Pack
Length (bytes)
Specify the length of your CAN message from 0 to 8 bytes. If you
are using CANdb specified signals for your data input, the
CANdb file defines the length of your message. If not, this field
defaults to 8. This option is available if you choose to input raw
data or manually specify signals.
Remote frame
Specify the CAN message as a remote frame.
Signals Table
This table appears if you choose to specify signals manually or define
signals using a CANdb file.
If you are using a CANdb file, the data in the file populates this table
automatically and you cannot edit the fields. To edit signal information,
switch to manually specified signals.
If you have selected to specify signals manually, create your signals
manually in this table. Each signal you create has the following values:
Name
Specify a descriptive name for your signal. The Simulink block
in your model displays this name. The default is Signal [row
number].
Start bit
Specify the start bit of the data. The start bit is the least
significant bit counted from the start of the message data. The
start bit must be an integer from 0 through 63.
Length (bits)
Specify the number of bits the signal occupies in the message. The
length must be an integer from 1 through 64.
Byte order
Select either of the following options:
• LE: Where the byte order is in little-endian format (Intel®).
In this format you count bits from the start, which is the
11-16
CAN Pack
least significant bit, to the most significant bit, which has the
highest bit index. For example, if you pack one byte of data in
little-endian format, with the start bit at 20, the data bit table
resembles this figure.
11-17
CAN Pack
pack one byte of data in big-endian format, with the start bit at
20, the data bit table resembles this figure.
Data type
Specify how the signal interprets the data in the allocated bits.
Choose from:
• signed (default)
• unsigned
11-18
CAN Pack
• single
• double
Multiplex type
Specify how the block packs the signals into the CAN message
at each timestep:
• Standard: The signal is packed at each timestep.
• Multiplexor: The Multiplexor signal, or the mode signal
is packed. You can specify only one Multiplexor signal per
message.
• Multiplexed: The signal is packed if the value of the
Multiplexor signal (mode signal) at run time matches the
configured Multiplex value of this signal.
For example, a message has four signals with the following types
and values.
In this example:
• The block packs Signal-A (Standard signal) and Signal-D
(Multiplexor signal) in every timestep.
• If the value of Signal-D is 1 at a particular timestep, then the
block packs Signal-B along with Signal-A and Signal-D in that
timestep.
• If the value of Signal-D is 0 at a particular timestep, then the
block packs Signal-C along with Signal-A and Signal-D in that
timestep.
11-19
CAN Pack
Conversion Formula
The conversion formula is
11-20
CAN Pack
11-21
CAN Receive
Description
The CAN Receive block receives messages from the CAN network and
delivers them to the Simulink model. It outputs one message or all
messages at each timestep, depending on the block parameters.
Note You need a license for both Vehicle Network Toolbox and
Simulink software to use this block.
11-22
CAN Receive
Note You cannot have more than one Receive block in a model using
the same NI-CAN, NI-XNET, or PEAK-System device channel.
11-23
CAN Receive
In this example, gcs is the current model that you wish to build.
Building the model creates a zip file with the same name as model
name. You can move this zip file to another machine and the source
code in the zip file can be built to create an executable which can be run
independent of MATLAB and Simulink. The generated code compiles
with both C and C++ compilers. For more information on packNGo,
see packNGo.
Dialog Use the Source Block Parameters dialog box to select your CAN Receive
Box block parameters.
Tip Configure your CAN Configuration block before you configure the
CAN Receive block parameters.
11-24
CAN Receive
Device
Select the CAN device and a channel on the device you want
to receive CAN messages from. This field lists all the devices
installed on the system. It displays the vendor name, the device
name, and the channel ID. The default is the first available device
on your system.
Standard IDs Filter
Select the filter on this block for standard IDs. Valid choices are:
• Allow all: allows all standard IDs to pass the filter. This is
the default filter state of the CAN Receive block
• Allow only: Allows only ID or range of IDs specified in the text
field. You can specify a single ID or an array of IDs. You can
also specify disjointed IDs or arrays separated by a comma. For
example, to accept IDs from 400 through 500 and 600 through
650, enter [[400:500] [600:650]]. Standard IDs must be a
positive integer from 0 through 2047. You can also specify a
hexadecimal value using the hex2dec function.
• Block all: Blocks all standard IDs from passing the filter.
Extended IDs Filter
Select the filter on this block for extended IDs. Valid choices are:
• Allow all: allows all extended IDs to pass the filter. This is
the default filter state of the CAN Receive block
• Allow only: Allows only ID or range of IDs specified in the
text field. You can specify a single ID or an array of IDs. You
can also specify disjointed IDs or arrays separated by a comma.
For example, to accept IDs from 3000 through 3500 and 3600
through 3620, enter [[3000:3500] [3600:3620]]. Extended
IDs must be a positive integer from 0 through 536870911.
You can also specify a hexadecimal value using the hex2dec
function.
• Block all: Blocks all extended IDs from passing the filter.
11-25
CAN Receive
Sample time
Specify the sampling time of the block during simulation, which is
the simulation time as described by the Simulink documentation.
This value defines the frequency at which the CAN Receive
block runs during simulation. If the block is inside a triggered
subsystem or to inherit sample time, you can specify –1 as your
sample time. You can also specify a MATLAB variable for sample
time. The default value is 0.01 (in seconds).
Number of messages received at each timestep
Select how many messages the block receives at each specified
timestep. The choices are 1 and all. By default, the block receives
one message at each timestep. Then, the FIFO buffer delivers
one new message to the Simulink model. If the block does not
receive any message before the next timestep it outputs the last
received message.
If you select all, the CAN Receive block delivers all available
messages in the FIFO buffer to the model during a specific
timestep. The block generates one function call for every message
delivered to the model for that particular timestep. The output
port always contains one CAN message at a time.
11-26
CAN Replay
Description
The CAN Replay block replays logged messages from a .mat file to a
CAN network or to Simulink. You need a CAN Configuration block
to replay to the network.
To replay messages logged in the MATLAB Command window in
your Simulink model, convert them into a compatible format using
vntslgate and save it to a separate file. Refer to the Basic CAN
Message Replay and Logging example for information.
Note You need a license for both Vehicle Network Toolbox and
Simulink software to use this block.
Replay Timing
When you replay logged messages, Simulink uses the original
timestamps on the messages. When you replay to a network, the
timestamps correlate to real time, and when you replay to the Simulink
input port it correlates to simulation time. If the timestamps in the
messages are all 0, all messages are replayed as soon as the simulation
starts, because simulation time and real time will be ahead of the
timestamps in the replayed messages.
11-27
CAN Replay
In this example, gcs is the current model that you wish to build.
Building the model creates a zip file with the same name as model
11-28
CAN Replay
name. You can move this zip file to another machine and the source
code in the zip file can be built to create an executable which can be run
independent of MATLAB and Simulink. The generated code compiles
with both C and C++ compilers. For more information on packNGo,
see packNGo.
Dialog Use the Source Block Parameters dialog box to select your message
Box replay options.
Tip Configure your CAN Configuration block before you configure the
CAN Receive block parameters.
11-29
CAN Replay
File name
Specify the name and path of the file that contains logged CAN
messages that you can replay. You can click Browse to browse to
a file location and select the file.
Variable name
Specify the variable saved in the MAT-file that holds the CAN
message information.
Number of times to replay messages
Specify the number of times you want the message replayed in
your model. You can specify any positive integer, including Inf.
Specifying Inf continuously replays messages until simulation
stops.
Replay messages to
Specify if the model is replaying messages to the CAN network or
an output port. Select a device to replay to the CAN network.
Device
Select the device on the CAN network to replay messages to. This
filed is unavailable if you select Input port for Replay message
to option.
Sample time
Specify the sampling time of the block during simulation, which is
the simulation time as described by the Simulink documentation.
This value defines the frequency at which the CAN Replay
block runs during simulation. If the block is inside a triggered
subsystem or to inherit sample time, you can specify –1 as your
sample time. You can also specify a MATLAB variable for sample
time. The default value is 0.01 (in seconds).
11-30
CAN Transmit
Description
Note You need a license for both Vehicle Network Toolbox and
Simulink software to use this block.
The CAN Transmit block has one input port. This port accepts a CAN
message packed using the CAN Pack block. It has no output ports.
Note You cannot have more than one Transmit block in a model using
the same NI-XNET device channel.
11-31
CAN Transmit
The CAN Transmit block supports the use of code generation along with
the packNGo function to group required source code and dependent
shared libraries. For more information, see Code Generation.
In this example, gcs is the current model that you wish to build.
Building the model creates a zip file with the same name as model
name. You can move this zip file to another machine and the source
code in the zip file can be built to create an executable which can be run
independent of MATLAB and Simulink. The generated code compiles
with both C and C++ compilers. For more information on packNGo,
see packNGo.
11-32
CAN Transmit
Dialog Use the Sink Block Parameters dialog box to select your CAN Transmit
Box block parameters.
Tip Configure your CAN Configuration block before you configure the
CAN Transmit block parameters.
Device
Select the CAN device and a channel on the device to use to
transmit CAN messages to the network. This list shows all the
devices installed on the system. It displays the vendor name, the
device name, and the channel ID. The default is the first available
device on your system.
Transmit messages periodically
Select this option to enable periodic transmit of the message on
the configured channel to transmit at the specified period.
11-33
CAN Transmit
11-34
CAN Unpack
Description
The CAN Unpack block unpacks a CAN message into signal data using
the specified output parameters at every timestep. Data is output as
individual signals.
Note To use this block, you also need a license for Simulink software.
The CAN Unpack block has one output port by default. The number
of output ports is dynamic and depends on the number of signals you
specify for the block to output. For example, if your block has four
signals, it has four output ports.
11-35
CAN Unpack
Dialog Use the Function Block Parameters dialog box to select your CAN
Box message unpacking parameters.
Parameters
Data to be output as
Select your data signal:
11-36
CAN Unpack
11-37
CAN Unpack
11-38
CAN Unpack
the selected message in the CANdb file has four signals, your
block has four output ports.
CANdb file
This option is available if you specify that your data is input via a
CANdb file in the Data to be output as list. Click Browse to
find the CANdb file on your system. The messages and signal
definitions specified in the CANdb file populate the Message
section of the dialog box. The signals specified in the CANdb file
populate Signals table.
Message list
This option is available if you specify that your data is to be
output as a CANdb file in the Data to be output as list and you
select a CANdb file in the CANdb file field. You can select the
message that you want to view. The Signals table then displays
the details of the selected message.
Message
Name
Specify a name for your CAN message. The default is CAN Msg.
This option is available if you choose to output raw data or
manually specify signals.
Identifier type
Specify whether your CAN message identifier is a Standard or an
Extended type. The default is Standard. A standard identifier
is an 11-bit identifier and an extended identifier is a 29-bit
identifier. This option is available if you choose to output raw
11-39
CAN Unpack
Signals Table
This table appears if you choose to specify signals manually or define
signals using a CANdb file.
If you are using a CANdb file, the data in the file populates this table
automatically and you cannot edit the fields. To edit signal information,
switch to manually specified signals.
If you have selected to specify signals manually, create your signals
manually in this table. Each signal you create has the following values:
Name
Specify a descriptive name for your signal. The Simulink block
in your model displays this name. The default is Signal [row
number].
Start bit
Specify the start bit of the data. The start bit is the least
significant bit counted from the start of the message. The start
bit must be an integer from 0 through 63.
11-40
CAN Unpack
Length (bits)
Specify the number of bits the signal occupies in the message. The
length must be an integer from 1 through 64.
Byte order
Select either of the following options:
• LE: Where the byte order is in little-endian format (Intel). In
this format you count bits from the start, which is the least
significant bit, to the most significant bit, which has the
highest bit index. For example, if you pack one byte of data in
little-endian format, with the start bit at 20, the data bit table
resembles this figure.
11-41
CAN Unpack
11-42
CAN Unpack
Data type
Specify how the signal interprets the data in the allocated bits.
Choose from:
• signed (default)
• unsigned
• single
• double
11-43
CAN Unpack
Multiplex type
Specify how the block unpacks the signals from the CAN message
at each timestep:
• Standard: The signal is unpacked at each timestep.
• Multiplexor: The Multiplexor signal, or the mode signal is
unpacked. You can specify only one Multiplexor signal per
message.
• Multiplexed: The signal is unpacked if the value of the
Multiplexor signal (mode signal) at run time matches the
configured Multiplex value of this signal.
For example, a message has four signals with the following values.
In this example:
• The block unpacks Signal-A (Standard signal) and Signal-D
(Multiplexor signal) in every timestep.
• If the value of Signal-D is 1 at a particular timestep, then the
block unpacks Signal-B along with Signal-A and Signal-D in
that timestep.
• If the value of Signal-D is 0 at a particular timestep, then the
block unpacks Signal-C along with Signal-A and Signal-D in
that timestep.
• If the value of Signal-D is not 1 or 0, the block does not unpack
either of the Multiplexed signals in that timestep.
11-44
CAN Unpack
Multiplex value
This option is available only if you have selected the Multiplex
type to be Multiplexed. The value you provide here must match
the Multiplexor signal value at run time for the block to unpack
the Multiplexed signal. The Multiplex value must be a positive
integer or zero.
Factor
Specify the Factor value applied to convert the unpacked raw
value to the physical value (signal value). See “Conversion
Formula” on page 11-46 to understand how unpacked raw values
are converted to physical values.
Offset
Specify the Offset value applied to convert the physical value
(signal value) to the unpacked raw value. See “Conversion
Formula” on page 11-46 to understand how unpacked raw values
are converted to physical values.
Min
Specify the minimum raw value of the signal. The default value
is -inf (negative infinity). You can specify a number for the
minimum value. See “Conversion Formula” on page 11-46 to
understand how unpacked raw values are converted to physical
values.
Max
Specify the maximum raw value of the signal. The default value
is inf. You can specify a number for the maximum value. See
“Conversion Formula” on page 11-46 to understand how unpacked
raw values are converted to physical values.
Output Ports
Selecting an Output ports option adds an output port to your block.
Output identifier
Select this option to output a CAN message identifier. The data
type of this port is uint32.
11-45
CAN Unpack
Output remote
Select this option to output the message remote frame status.
This option adds a new output port to the block. The data type of
this port is uint8.
Output timestamp
Select this option to output the message time stamp. This option
adds a new output port to the block. The data type of this port
is double.
Output length
Select this option to output the length of the message in bytes.
This option adds a new output port to the block. The data type of
this port is uint8.
Output error
Select this option to output the message error status. This option
adds a new output port to the block. The data type of this port is
uint8.
Output status
Select this option to output the message received status. The
status is 1 if the block receives new message and 0 if it does not.
This option adds a new output port to the block. The data type of
this port is uint8.
If you do not select an Output ports option, the number of output ports
on your block depends on the number of signals you specify.
Conversion Formula
The conversion formula is
11-46
XCP Configuration
Description
The XCP Configuration block uses the parameters specified in the A2L
file and the ASAP2 database to establish XCP slave connection.
Specify the A2L file to use in your XCP Configuration before you acquire
or stimulate data. Use one XCP Configuration to configure one slave for
data acquisition or stimulation. If you add Data Acquisition and Data
Stimulation blocks, your model checks to see if there is a corresponding
XCP Configuration block and will prompt you to add one.
11-47
XCP Configuration
Dialog Use the Block Parameters dialog box to select your XCP configuration.
Box
Config name
Specify a unique name for your XCP session.
A2L File
Click Browse to select an A2L file for your XCP session.
Enable seed/key security
Select this option if your slave requires a secure key to establish
connection. You need to select a file that contains the seed/key
definition to enable the security.
File (*.DLL)
This field is enabled if you select Enable seed/key security.
Click Browse to select the file that contains seed and key security
algorithm used to unlock an XCP slave module.
11-48
XCP Configuration
11-49
XCP Data Acquisition
Description
The XCP Data Acquisition block acquires data from the configured slave
based on the selected measurements. The block uses the XCP CAN
transport layer to obtain raw data for the selected measurements at the
specified simulation time step. Configure your XCP connection and use
the XCP Data Acquisition block to select your event and measurements
for the configured slave. The block displays the selected measurements
as output ports.
Other The XCP Data Acquisition block supports the use of Simulink
Supported Accelerator and Rapid Accelerator mode. Using this feature, you can
Features speed up the execution of Simulink models.
For more information on this feature, see the Simulink documentation.
The XCP Configuration block also supports code generation with
limited deployment capabilities. Code generation requires the Microsoft
C++ compiler.
Dialog Use the Block Parameters dialog box to select your data acquisition
Box parameters.
11-50
XCP Data Acquisition
11-51
XCP Data Acquisition
Parameters
Config name
Select the name of XCP configuration you want to use. The
list displays all available names specified in the available XCP
Configuration blocks in the model. Selecting a configuration
displays events and measurements available in this
configuration’s A2L file.
Note You can acquire measurements for only one event using an
XCP Data Acquisition block. Use one block each for each event
whose measurements you want to acquire.
Event name
Select an event from the available list of events. The XCP
Configuration block uses the specified A2L file to populate the
events list.
Measurements
Search
Type the name of the measurement you want to use. The All
Measurements lists displays a list of all matching terms. Click
the x
11-52
XCP Data Acquisition
Selected Measurements
This list displays selected measurements. To remove a
measurement from this list, select the measurement and click
11-53
XCP Data Stimulation
Description
The XCP Data Stimulation block sends data to the selected slave for the
selected event measurements. The block uses the XCP CAN transport
layer to output raw data for the selected measurements at the specified
stimulation time step. Configure your XCP session and use the XCP
Data Stimulation block to select your event and measurements on the
configured slave. The block displays the selected measurements as
input ports.
Other The XCP Data Stimulation block supports the use of Simulink
Supported Accelerator and Rapid Accelerator mode. Using this feature, you can
Features speed up the execution of Simulink models.
For more information on this feature, see the Simulink documentation.
The XCP Configuration block also supports code generation with
limited deployment capabilities. Code generation requires the Microsoft
C++ compiler.
Dialog Use the Block Parameters dialog box to select your data stimulation
Box parameters.
11-54
XCP Data Stimulation
11-55
XCP Data Stimulation
Parameters
Config name
Select the name of XCP configuration you want to use. The
list displays all available names specified in the available XCP
Configuration blocks in the model. Selecting a configuration
displays events and measurements available in this
configuration’s A2L file.
Note You can stimulate measurements for only one event using
an XCP Data Stimulation block. Use one block each for each event
whose measurements you want to stimulate.
Event name
Select an event from the available list of events. The XCP
Configuration block uses the specified A2L file to populate the
events list.
Measurements
Search
Type the name of the measurement you want to use. The All
Measurements lists displays a list of all matching terms. Click
the x
11-56
XCP Data Stimulation
Selected Measurements
This list displays selected measurements. To remove a
measurement from this list, select the measurement and click
11-57
XCP CAN Transport Layer
Description
The XCP CAN Transport Layer subsystem uses the specified device to
transport and receive XCP messages.
Use this block with an XCP Data Acquisition block to acquire and
analyze specific XCP messages. Use this block with an XCP Data
Stimulation block to send specific information to modules.
11-58
XCP CAN Transport Layer
Dialog Use the Block Parameters dialog box to select your CAN Transport
Box configuration.
Device
+
11-59
XCP CAN Transport Layer
can also specify a MATLAB variable for sample time. The default
value is 0.01 (in seconds).
See Also XCP Configuration | XCP Data Acquisition | XCP Data Stimulation
11-60
XCP CAN TL Receive
Description
The XCP CAN Transport Layer Receive block receives XCP messages
from a CAN Receive block.
Dialog Use the Block Parameters dialog box to select your XCP CAN Transport
Box Layer Receive block parameters.
11-61
XCP CAN TL Receive
Sample time
Specify the sampling time of the block during simulation, which is
the simulation time as described by the Simulink documentation.
This value defines the frequency at which the XCP CAN Transport
Layer Receive block runs during simulation. If the block is inside
a triggered subsystem or to inherit sample time, you can specify
–1 as your sample time. You can also specify a MATLAB variable
for sample time. The default value is –1 (in seconds).
11-62
XCP CAN TL Transmit
Description
The XCP CAN Transport Layer Transmit block connects to a CAN
Transmit block to transmit queued XCP messages.
Dialog Use the Block Parameters dialog box to select your XCP CAN Transport
Box Layer Transmit block parameters.
11-63
XCP CAN TL Transmit
11-64