Vehicle Network Toolbox - User Guide
Vehicle Network Toolbox - User Guide
User's Guide
R2017a
How to Contact MathWorks
Phone: 508-647-7000
Getting Started
1
Vehicle Network Toolbox Product Description . . . . . . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
v
Hardware Support Package Installation
2
Vehicle Network Toolbox Supported Hardware . . . . . . . . . . 2-2
vi Contents
Monitoring Vehicle CAN Bus
5
Vehicle CAN Bus Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
About the Vehicle CAN Bus Monitor . . . . . . . . . . . . . . . . . . . 5-2
Opening the Vehicle CAN Bus Monitor . . . . . . . . . . . . . . . . . 5-2
Vehicle CAN Bus Monitor Fields . . . . . . . . . . . . . . . . . . . . . . 5-2
A2L File
7
A2L File Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
vii
Universal Measurement & Calibration Protocol
(XCP)
8
XCP Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
J1939
9
J1939 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2
viii Contents
CAN Communications in Simulink
10
Vehicle Network Toolbox Simulink Blocks . . . . . . . . . . . . . 10-2
Hardware Limitations
11
Vector Hardware Limitations . . . . . . . . . . . . . . . . . . . . . . . . 11-2
ix
Functions Alphabetical List
13
Block Reference
15
x Contents
1
Getting Started
Vehicle Network Toolbox provides connectivity to CAN devices from MATLAB and
Simulink using industry-standard CAN database files. The toolbox provides MATLAB
functions and Simulink blocks to send, receive, encode, and decode CAN, J1939, and XCP
messages. You can also connect to an ECU via XCP on CAN using A2L description files.
The toolbox lets you monitor, filter, and analyze live CAN bus data or log and record
messages for later analysis and replay. You also can simulate message traffic on a virtual
CAN bus or connect to a live network or ECU. Vehicle Network Toolbox supports CAN
interface devices from Vector, Kvaser, PEAK-System, and National Instruments.
Key Features
MATLAB functions for transmitting and receiving CAN and J1939 messages
Simulink blocks for connecting a model to a CAN or J1939 bus
XCP support for communicating with ECUs
Vector CAN database (.dbc) file and A2L description file support
Signal packing and unpacking for simplified encoding and decoding of CAN messages
and J1939 parameter groups
Vehicle CAN Bus Monitor app to configure devices and visualize live CAN network
traffic
Support for Vector, Kvaser, PEAK-System, and National Instruments CAN interface
devices
1-2
Toolbox Characteristics and Capabilities
Vehicle Network Toolbox provides host-side CAN connectivity using defined CAN
devices. CAN is the predominant protocol in automotive electronics by which many
distributed control systems in a vehicle function.
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.
You can use Vehicle Network Toolbox to communicate over the CAN bus using supported
Vector, Kvaser, PEAK-System, or National Instruments devices and drivers.
See Vehicle Network Toolbox Supported Hardware on page 2-2 for more
information.
1-3
1 Getting Started
Using a set of well-defined functions, you can transfer messages between the MATLAB
workspace and a CAN bus using a CAN device. You can run test applications that can log
and record CAN messages for you to process and analyze. You can also replay recorded
sequences of messages.
With Vehicle Network Toolbox block library and other blocks from the Simulink library,
you can create sophisticated models to connect to a live network and to simulate message
traffic on a CAN bus.
Using Vehicle CAN Bus Monitor, a simple graphical user interface, you can monitor
message traffic on a selected device and channel. You can then analyze these messages.
1-4
Toolbox Characteristics and Capabilities
In this illustration:
Using Vehicle Network Toolbox from MATLAB, you can configure a channel on the CAN
device to:
1-5
1 Getting Started
Attach the database to the configured CAN channel to interpret received CAN
messages.
Use the CAN database to construct messages to transmit.
Log and record messages and analyze them in MATLAB.
Replay live recorded sequence of messages in MATLAB.
Build Simulink models to connect to a CAN bus and to simulate message traffic.
Monitor CAN traffic with the Vehicle CAN Bus Monitor on page 5-2.
Prerequisite Knowledge
The Vehicle Network Toolbox document set 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, along with message and signal
definitions.
1-6
Vehicle Network Communication in MATLAB
Transmit Workflow
1-7
1 Getting Started
Receive Workflow
1-8
Transmit and Receive CAN Messages
1-9
1 Getting Started
2 Save the MathWorks virtual device information to a variable. The indexing indicates
vendors; so from this canHWInfo output, info.VendorInfo(1) corresponds to
MathWorks, info.VendorInfo(2) corresponds to Vector, etc.
mwvirt = info.VendorInfo(1)
mwvirt =
VendorName: 'MathWorks'
VendorDriverDescription: 'MathWorks Virtual CAN Driver'
VendorDriverVersion: '1'
ChannelInfo: [12 can.mathworks.ChannelInfo]
3 Get details about the first available virtual CAN channel on the device.
mwvirt.ChannelInfo(1)
ans =
Note To modify this example for a hardware CAN device, make a loopback connection
between the two channels.
1-10
Transmit and Receive CAN Messages
canch1 =
Filter History: Standard ID Filter: Allow All | Extended ID Filter: Allow All
canch2 =
Filter History: Standard ID Filter: Allow All | Extended ID Filter: Allow All
For each channel, notice that its initial status is Offline and its bus speed is 500000.
Note You cannot use the same variable to create multiple channels sequentially. Clear
any channel before using the same variable to construct a new CAN channel.
1-11
1 Getting Started
You cannot create arrays of CAN channel objects. Each object you create must be
assigned to its own scalar variable.
1 Change the bus speed of both channels to 250000, then view the channel BusSpeed
property to verify the setting.
configBusSpeed(canch1,250000)
canch1.BusSpeed
ans =
250000
2 You can also see the updated bus speed in the channel display.
canch1
canch1 =
1-12
Transmit and Receive CAN Messages
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
1-13
1 Getting Started
message using canch1 and receive it using canch2. To transmit a message, create a
message object and pack the message with the required data.
Build a CAN message with ID 500, of standard type, and a data length of 8 bytes.
messageout = canMessage(500,false,8)
messageout =
ID: 500
Extended: 0
Name: ''
Database: []
Error: 0
Remote: 0
Timestamp: 0
Data: [0 0 0 0 0 0 0 0]
Signals: []
UserData: []
Refer to the canMessage function to understand more about its input arguments.
Pack a Message
After you create the message, pack it with the required data.
1 Use the pack function to pack your message with these input parameters: a Data
value of 25, start bit of 0, signal size of 16, and byte order using little-endian format.
View the message Data property to verify the settings.
pack(messageout,25,0,16,'LittleEndian')
1-14
Transmit and Receive CAN Messages
messageout.Data
ans =
25 0 0 0 0 0 0 0
The only message property that changes from packing is Data. Refer to the pack
function to understand more about its input arguments.
Transmit a Message
Now you can transmit the packed message. Use the transmit function, supplying the
channel canch1 and the message as input arguments.
transmit(canch1,messageout)
canch1
canch1 =
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
MATLAB displays the updated channel. In the Status section, messages transmitted
since last start count increments by 1 each time you transmit a message. The
1-15
1 Getting Started
message to be received is available to all devices on the bus, so it shows up here even for
the transmitting channel.
Refer to the transmit function to understand more about its input arguments.
Receive a Message
Use the receive function to receive the available message on canch2.
canch2
canch2 =
Status: Online.
1 messages available to receive.
0 messages transmitted since last start.
0 messages received since last start.
messagein = receive(canch2,1)
messagein =
1-16
Transmit and Receive CAN Messages
ID: 500
Extended: 0
Name: ''
Database: []
Error: 0
Remote: 0
Timestamp: 0.6601
Data: [25 0 0 0 0 0 0 0]
Signals: []
UserData: []
Note the message Data property. This matches the data transmitted from canch1.
Refer to the receive function to understand more about its input arguments.
3 To check if the channel received the message, view the channel display.
canch2
canch2
canch2 =
Status: Online.
0 messages available to receive.
0 messages transmitted since last start.
1 messages received since last start.
The channel display indicates 1 messages received since last start and 0
messages available to receive.
1-17
1 Getting Started
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;
these should correspond to the parameters used for packing.
value = unpack(messagein,0,16,'LittleEndian','int16')
value =
int16
25
Refer to the unpack function to understand more about its input arguments.
If you have saved a CAN channel in a MATLAB file, you can load the channel
into MATLAB using the load function. For example, to reload the channel from
mycanch.mat that was created earlier, type:
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-18
Transmit and Receive CAN Messages
When you no longer need to communicate with your CAN bus, use thestop function to
disconnect the CAN channels that you configured.
.
.
.
Status: Offline - Waiting for START.
1 messages available to RECEIVE.
1 messages transmitted since last start.
0 messages received since last start.
3 Stop the second channel.
stop(canch2)
4 Check the channel status.
canch2
.
.
.
Status: Offline - Waiting for START.
0 messages available to RECEIVE.
0 messages transmitted since last start.
1 messages received since last start.
When you no longer need these objects and variables, remove them from the MATLAB
workspace with the clear command.
1-19
1 Getting Started
clear messagein
3 Clear the unpacked value.
clear value
Related Examples
Filter Messages on page 1-21
Multiplex Signals on page 1-22
Configure Silent Mode on page 1-25
1-20
Filter Messages
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
Note the Filter History in the last line of the channel display. When you start the
channel and receive messages, only those marked EngineMsg pass through the filter.
For more information about using a message database, see Message Database.
Related Examples
Transmit and Receive CAN Messages on page 1-9
1-21
1 Getting Started
Multiplex Signals
Use multiplexing to represent multiple signals in one signals location in a CAN
messages 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:
For example,
d = canDatabase('Mux.dbc')
m = canMessage(d,'Msg')
m =
can.Message handle
1-22
Multiplex Signals
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
MuxSig is the multiplexor signal, whose value determines which of the two
multiplexed signals are active in the message. SigA and SigB are the multiplexed
signals that are active in the message if their multiplex values match MuxSig. In the
example shown, SigA is active because its current multiplex value of 0 matches the
value of MuxSig (which is 0).
4 If you want to make SigB active, change the value of the MuxSig to 1.
m.Signals.MuxSig = 1
m.Signals
ans =
SigB: 0
SigA: 0
MuxSig: 1
1-23
1 Getting Started
SigB is now active because its multiplex value of 1 matches the current value of
MuxSig (which is 1).
5 Change the value of MuxSig to 2.
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.
Related Examples
Transmit and Receive CAN Messages on page 1-9
1-24
Configure Silent Mode
1 Change the SilentMode property of the first CAN channel, canch1 to true.
canch.SilentMode = true
2 To see the changed property value, type:
canch1.SilentMode
ans =
Related Examples
Transmit and Receive CAN Messages on page 1-9
1-25
2
For instructions on installing the drivers, see Install Hardware Support Package for
Device Driver on page 2-3.
More About
Vendor Limitations
2-2
Install Hardware Support Package for Device Driver
To communicate with a CAN device, you need to install the required driver on your
system. The drivers are available as support packages for the following vendors:
1 On the MATLAB Home tab, in the Environment section, click Add-Ons > Get
Hardware Support Packages.
2 In the Add-On Explorer, scroll to Refine by Type and check Hardware Support
Packages.
3 Under Refine by Hardware Type, check CAN Devices. The Add-On Explorer
displays all the vendors for supported CAN devices. Click the vendor for your device.
On the MATLAB Home tab, in the Environment section, click Add-Ons > Manage
Add-Ons.
On the MATLAB Home tab, in the Environment section, click Add-Ons > Check for
Updates > Hardware Support Packages.
2-3
2 Hardware Support Package Installation
More About
Get Add-Ons (MATLAB)
Vendor Limitations
2-4
3
3-2
CAN Transmit Workflow
See Also
Functions
canChannel | canDatabase | canMessage | canMessageImport | configBusSpeed
| pack | start | stop | transmit | transmitConfiguration | transmitEvent |
transmitPeriodic
Properties
Data | Database | Error | Extended | ID | Name | Remote | Signals | Timestamp
| UserData
Blocks
CAN Pack | CAN Replay | CAN Transmit
3-3
3 CAN Communication Workflows
See Also
Functions
attachDatabase | canDatabase | configBusspeed | extractAll |
extractRecent | extractTime | receive | stop | unpack
3-4
CAN Receive Workflow
Properties
MessageReceivedFcn | MessageReceivedFcnCount | MessagesAvailable
| MessagesReceived | MessagesTransmitted | ReceiveErrorCount |
TransmitErrorCount
Blocks
CAN Log | CAN Receive | CAN Unpack
3-5
4
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')
Tip: CAN database file names containing non-alphanumeric characters such as equal
signs, ampersands, and so forth are incompatible with Vehicle Network Toolbox. You
can use periods in your database name. Rename any CAN database files with non-
alphanumeric characters before you use them.
4-2
Load .dbc Files and Create Messages
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.
VehicleSpeed: 0
EngineRPM: 250
2 Change the value of the EngineRPM signal:
message.Signals.EngineRPM = 300
3 Display signal information again to see the change:
sig
sig =
4-3
4 Using a CAN Database
VehicleSpeed: 0
EngineRPM: 300
1 Reload the database file into your MATLAB session using the canDatabase
function.
2 Reattach the database to messages using the attachDatabase 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 =
Name: 'demoVNT_CANdbFiles'
Path: '\\central-mi\home\jpyle\Documents\MATLAB\examples\vnt-ex80654288\de
Nodes: {}
4-4
Load .dbc Files and Create Messages
ans =
51 cell array
'DoorControlMsg'
'EngineMsg'
'SunroofControlMsg'
'TransmissionMsg'
'WindowControlMsg'
Use messageInfo to view message information, including the identifier, data length,
and a signal list.
messageInfo(db, 'EngineMsg')
ans =
Name: 'EngineMsg'
Comment: ''
ID: 100
Extended: 0
J1939: []
Length: 8
Signals: {21 cell}
SignalInfo: [21 struct]
TxNodes: {01 cell}
Attributes: {}
AttributeInfo: [00 struct]
4-5
4 Using a CAN Database
messageInfo(db)
ans =
Name
Comment
ID
Extended
J1939
Length
Signals
SignalInfo
TxNodes
Attributes
AttributeInfo
Use signalInfo to view signal definition information, including type, byte ordering,
size, and scaling values that translate raw signals to physical values.
ans =
Name: 'EngineRPM'
Comment: ''
StartBit: 0
SignalSize: 32
ByteOrder: 'LittleEndian'
Signed: 0
ValueType: 'Integer'
Class: 'uint32'
Factor: 0.1000
Offset: 250
Minimum: 250
Maximum: 9500
Units: 'rpm'
4-6
Load .dbc Files and Create Messages
You can also query for information on all signals in the message at once.
signalInfo(db, 'EngineMsg')
ans =
Name
Comment
StartBit
SignalSize
ByteOrder
Signed
ValueType
Class
Factor
Offset
Minimum
Maximum
Units
ValueTable
Multiplexor
Multiplexed
MultiplexMode
RxNodes
Attributes
AttributeInfo
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.
4-7
4 Using a CAN Database
msgEngineInfo =
ID: 100
Extended: 0
Name: 'EngineMsg'
Database: [11 can.Database]
Error: 0
Remote: 0
Timestamp: 0
Data: [0 0 0 0 0 0 0 0]
Signals: [11 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 =
4-8
Load .dbc Files and Create Messages
ID: 100
Extended: 0
Name: 'EngineMsg'
Database: [11 can.Database]
Error: 0
Remote: 0
Timestamp: 0
Data: [23 205 0 0 0 0 0 0]
Signals: [11 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 =
ID: 100
Extended: 0
Name: 'EngineMsg'
Database: [11 can.Database]
Error: 0
Remote: 0
Timestamp: 0
Data: [23 205 0 0 71 0 0 0]
Signals: [11 struct]
UserData: []
4-9
4 Using a CAN Database
ans =
VehicleSpeed: 71
EngineRPM: 5.5003e+03
Attach a database to a CAN channel that receives messages to apply database definitions
to incoming messages automatically. The database decodes only messages that are
defined. All other messages are received in their raw form.
rxCh =
Filter History: Standard ID Filter: Allow All | Extended ID Filter: Allow All
Receive Messages
Start the channel, generate some message traffic and receive messages with physical
message decoding.
start(rxCh);
generateMsgsDb();
4-10
Load .dbc Files and Create Messages
ans =
stop(rxCh);
clear rxCh
rxMsg(10, :)
rxMsg.Signals{10}
ans =
18 timetable array
4-11
4 Using a CAN Database
ans =
VehicleSpeed: 50
EngineRPM: 3.5696e+03
ans =
4-12
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.
ans =
4-13
4 Using a CAN Database
More About
View Message Information in a CAN Database on page 4-15
View Signal Information in a CAN Message on page 4-17
Attach a CAN Database to Existing Messages on page 4-18
4-14
View Message Information in a CAN Database
This returns the message structure of information about messages in the database. For
example:
msgInfo = messageInfo(db)
msgInfo =
This returns information about the message as defined in the database. For example:
msgInfo = messageInfo(db,'EngineMsg')
msgInfo =
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:
msgInfo = messageInfo(db,100,false)
4-15
4 Using a CAN Database
This command provides the database name, the message ID, and a Boolean value for the
extended value of the ID.
See Also
Functions
messageInfo
More About
Load .dbc Files and Create Messages on page 4-2
View Signal Information in a CAN Message on page 4-17
Attach a CAN Database to Existing Messages on page 4-18
4-16
View Signal Information in a CAN Message
You can also get information about a specific signal by providing the signal name:
sigInfo = signalInfo(db, 'EngineMsg', 'EngineRPM')
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.
See Also
Functions
signalInfo
More About
Load .dbc Files and Create Messages on page 4-2
View Message Information in a CAN Database on page 4-15
Attach a CAN Database to Existing Messages on page 4-18
4-17
4 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:
attachDatabase(message name, [])
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.
See Also
Functions
attachDatabase
More About
Load .dbc Files and Create Messages on page 4-2
View Message Information in a CAN Database on page 4-15
View Signal Information in a CAN Message on page 4-17
4-18
5
In this section...
About the Vehicle CAN Bus Monitor on page 5-2
Opening the Vehicle CAN Bus Monitor on page 5-2
Vehicle CAN Bus Monitor Fields on page 5-2
5-2
Vehicle CAN Bus Monitor
File Menu
5-3
5 Monitoring Vehicle CAN Bus
Configure Menu
Channel Displays all available CAN devices and channels on your system. Select
the CAN channel to monitor.
Bus Speed Opens the Specified bus speed dialog box. To change the bus speed of
the selected channel, type the new value in bits per second in the box.
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.
5-4
Vehicle CAN Bus Monitor
Run Menu
View Menu
Maximum message count Opens the Specify maximum message count dialog
box. To change the maximum number of messages displayed at a time in the Vehicle
CAN Bus Monitor, type the new value in the box.
Number Format Select the number format to display message identifier data.
Choose Hexadecimal or Decimal.
Show Unique Messages Select this option to display the most recent instance
of each message received on the selected channel. If you select this option, the tool
displays a simplified version of the message traffic. In this view, messages do not
scroll up, but each message refreshes its data with each timestamp. If you do not
5-5
5 Monitoring Vehicle CAN Bus
select this option, the tool displays all instances of all messages in the order that the
selected channel receives them.
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.
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 .
5-6
Vehicle CAN Bus Monitor
Undocking
Click this button to undock the Vehicle CAN Bus Monitor from the MATLAB
desktop. To dock, click .
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:
To change the format to decimal, select View > Number Format > Decimal.
Name
Displays the name of the message, if available.
Length
Displays the length of the message in bytes.
Data
Displays the data in the message in hexadecimal format.
To change the format to decimal, select View > Number Format > Decimal.
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.
More About
Using the Vehicle CAN Bus Monitor on page 5-8
5-7
5 Monitoring Vehicle CAN Bus
In this section...
View Messages on a Channel on page 5-8
Configure the Channel Bus Speed on page 5-8
Filter CAN Messages in Vehicle CAN Bus Monitor on page 5-9
Attach a Database on page 5-9
Change the Message Count on page 5-12
Change the Number Format on page 5-12
View Unique Messages on page 5-12
Save the Message Log File on page 5-13
5-8
Using the Vehicle CAN Bus Monitor
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.
3 To set filters on extended message IDs, select:
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.
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.
5-9
5 Monitoring Vehicle CAN Bus
1 Select Run > Stop to stop the message display in the Vehicle CAN Bus Monitor.
2 Select Configure > Database.
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.
5-10
Using the Vehicle CAN Bus Monitor
4 Click the plus (+) sign to see the details of the message.
5-11
5 Monitoring Vehicle CAN Bus
The tool displays the signal name as defined in the attached database and the signal's
physical value.
click .
5-12
Using the Vehicle CAN Bus Monitor
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 messages when Show Unique Messages is selected, click Pause and then click
Save. You cannot save just the unique message list. This operation saves the complete
message log in the window.
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.
More About
Vehicle CAN Bus Monitor on page 5-2
5-13
6
6-2
XCP Database and Communication Workflow
6-3
6 XCP Communication Workflows
See Also
Functions
connect | createMeasurementList | disconnect | freeMeasurementLists |
getEventInfo | getMeasurementInfo | isConnected | isMeasurementRunning
| readDAQListData | readSingleValue | startMeasurement | stopMeasurement
| viewMeasurementLists | writeSingleValue | writeSTIMListData | xcpA2L |
xcpChannel
Properties
A2LFileName | A2LFileName | DAQInfo | Events | FileName | FilePath
| Measurements | ProtocolLayerInfo | SeedKeyDLL | SeedKeyDLL |
SlaveName | SlaveName | SlaveName | TransportLayer | TransportLayer |
TransportLayerCANInfo | TransportLayerDevice | TransportLayerDevice
Blocks
XCP CAN TL Receive | XCP CAN TL Transmit | XCP CAN Transport Layer |
XCP Configuration | XCP Configuration | XCP Data Acquisition | XCP Data
Stimulation
6-4
7
A2L File
7-2
Access an A2L File
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');
Tip: A2L file names containing non-alphanumeric characters such as equal signs,
ampersands, and so forth are incompatible with Vehicle Network Toolbox. You can use
periods in your database name. Rename any A2L files with non-alphanumeric characters
before you use them.
This command returns a A2L object that you can use with live communication to a slave
module using XCP channels.
7-3
7 A2L File
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' 'FilterBypassDaq' 'Filte
Measurements: {1x38 cell}
ans =
ans =
7-4
Inspect the Contents of an A2L File
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' 'FilterBypassDaq' 'Filte
Measurements: {1x38 cell}
Columns 1 through 8
Columns 9 through 16
Columns 17 through 25
Columns 26 through 33
Columns 34 through 38
7-5
7 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'
7-6
8
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.
8-2
XCP Hardware Connection
8-3
8 Universal Measurement & Calibration Protocol (XCP)
8-4
XCP Hardware Connection
In this section...
Create XCP Channel Using CAN Device on page 8-5
Configure the Channel to Unlock the Slave on page 8-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]
8-5
8 Universal Measurement & Calibration Protocol (XCP)
SeedKeyDLL: []
Create your XCP channel and set the channels 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.
8-6
Read a Single Value
readSingleValue(xcpch, 'Triangle')
ans =
50
8-7
8 Universal Measurement & Calibration Protocol (XCP)
8-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.
createMeasurementList(xcpch, 'DAQ', '10 ms', {'PWMFiltered','Triangle'});
Read 10 samples of data from the configured measurement list for the 'Triangle'
measurement.
readDAQListData(xcpch, 'Triangle', 10)
18 18 18 18 18 18 18 18 18 18
8-9
8 Universal Measurement & Calibration Protocol (XCP)
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.
createMeasurementList(xcpch, 'STIM', '100ms', {'PWMFiltered','Triangle'});
8-10
9
J1939
J1939 Interface
J1939 is a high-level protocol built on the CAN bus that provides serial data
communication between electronic control units (ECUs) in heavy-duty vehicles.
Applications of J1939 include:
The J1939 protocol uses CAN as the physical layer, which defines the communication
between ECUs in the vehicle network. The protocol has a second data-link layer that
defines rules of communication and error detection. A third application layer defines the
data transferred over the network.
More About
J1939 Parameter Group Format on page 9-3
J1939 Network Management on page 9-5
J1939 Transport Protocols on page 9-6
J1939 Channel Workflow on page 9-7
9-2
J1939 Parameter Group Format
The message contains a group of parameters that define related messages. For example,
a message sent to the engine controller can contain both engine speed and RPM. These
parameters are represented in the CAN identifier by a parameter group number (PGN).
Parameter groups use 29-bit identifiers with this message structure:
First three bits represent the priority of the message on the network. Zero is the
highest priority.
The next bit is reserved for future use. For transmit messages, set this to zero.
The next bit is the data page, which extends the maximum number of possible PGs in
the identifier.
The next 8 bits are the protocol data unit (PDU) format, which specifies whether the
message is targeted for a single device or is broadcast. If the PDU is less than 240,
then the message is sent to a specific device and if it over 240, it is sent to the entire
network.
The next 8 bits are the PDU specific, which contains the address of the device when
the PDU format is less than 240. If PDU format is greater than 240, PDU specific
contains group extension, or the number of extended broadcast messages in this
parameter group.
The last 8 bits contain the source address, which is the address of the device sending
the parameter groups.
The protocol application layer transmits the PG on the CAN network. PG length can be
up to 1785 bytes and is not limited by the length of a CAN message. However, PGs larger
than 8 bytes must be transmitted using a transport protocol.
9-3
9 J1939
More About
J1939 Interface on page 9-2
J1939 Network Management on page 9-5
J1939 Transport Protocols on page 9-6
J1939 Channel Workflow on page 9-7
9-4
J1939 Network Management
Address Claiming
The application sending a PG must claim an ECU address. The application sends an
address claiming PG first, and resumes sending other PGs if there is not address conflict.
If the source application encounters an address conflict, it can send a PG to the global
(255) address to request all devices to declare their addresses. It can then claim one of
the unused addresses.
More About
J1939 Interface on page 9-2
J1939 Parameter Group Format on page 9-3
J1939 Transport Protocols on page 9-6
J1939 Channel Workflow on page 9-7
9-5
9 J1939
Messages that have multiple packets are transmitted with a dedicated PGN, and have
the same message ID and similar functionality.
The length of each message in the packet must be 8 bytes or fewer.
The first byte in the data field of a message specifies the sequence of the message (one
to 255) and the next seven bytes contain the original data.
All unused bytes in the data field are set to zero.
A different PGN controls the message flow.
The data package is passed to the application layer after it is reassembled in the order
specified by the first data-field byte.
More About
J1939 Interface on page 9-2
J1939 Parameter Group Format on page 9-3
J1939 Network Management on page 9-5
J1939 Transport Protocols on page 9-6
J1939 Channel Workflow on page 9-7
9-6
J1939 Channel Workflow
9-7
9 J1939
9-8
J1939 Channel Workflow
More About
J1939 Interface on page 9-2
J1939 Parameter Group Format on page 9-3
J1939 Network Management on page 9-5
J1939 Transport Protocols on page 9-6
9-9
9 J1939
J1939 Examples
In this section...
Create and Use J1939 Parameter Groups on page 9-10
Create and Use J1939 Channels on page 9-16
pg =
Data Details:
-------------
Timestamp: 0
Data: [255 255 255 255 255 255 255 255]
9-10
J1939 Examples
Other Information:
------------------
UserData: []
To fully define the parameter group and determine the logistics of its transmission on a
network, set the source and destination addresses.
pg.SourceAddress = 30
pg.DestinationAddress = 50
pg =
Data Details:
-------------
Timestamp: 0
Data: [255 255 255 255 255 255 255 255]
Signals: [11 struct]
Other Information:
------------------
UserData: []
pg =
9-11
9 J1939
---------------------------
Name: 'VehicleDataSingle'
PGN: 40192
Priority: 6
PDUFormatType: 'Peer-to-Peer Type 1 '
SourceAddress: 30
DestinationAddress: 50
Data Details:
-------------
Timestamp: 0
Data: [255 255 255 255 255 255 255 255]
Signals: [11 struct]
Other Information:
------------------
UserData: []
Set Priority
Use the Signals property to see signal values for this parameter group. You can directly
write to and read from these signals to pack or unpack data in the parameter group.
pg.Signals
ans =
VehicleSignal4: -1
VehicleSignal3: -1
VehicleSignal2: -1
VehicleSignal1: -1
Write directly to a signal to change a value and read its current value back.
9-12
J1939 Examples
pg.Signals.VehicleSignal1 = 10
pg.Signals.VehicleSignal2 = 100
pg.Signals.VehicleSignal3 = 1000
pg.Signals.VehicleSignal4 = 10000
pg.Signals
pg =
Data Details:
-------------
Timestamp: 0
Data: [10 0 255 255 255 255 255 255]
Signals: [11 struct]
Other Information:
------------------
UserData: []
pg =
Data Details:
9-13
9 J1939
-------------
Timestamp: 0
Data: [10 0 100 0 255 255 255 255]
Signals: [11 struct]
Other Information:
------------------
UserData: []
pg =
Data Details:
-------------
Timestamp: 0
Data: [10 0 100 0 232 3 255 255]
Signals: [11 struct]
Other Information:
------------------
UserData: []
pg =
9-14
J1939 Examples
SourceAddress: 30
DestinationAddress: 50
Data Details:
-------------
Timestamp: 0
Data: [10 0 100 0 232 3 16 39]
Signals: [11 struct]
Other Information:
------------------
UserData: []
ans =
VehicleSignal4: 10000
VehicleSignal3: 1000
VehicleSignal2: 100
VehicleSignal1: 10
You can also write values directly into the Data property.
pg.Data(1:2) = [50 0]
pg.Signals
pg =
9-15
9 J1939
Data Details:
-------------
Timestamp: 0
Data: [50 0 100 0 232 3 16 39]
Signals: [11 struct]
Other Information:
------------------
UserData: []
ans =
VehicleSignal4: 10000
VehicleSignal3: 1000
VehicleSignal2: 100
VehicleSignal1: 50
Create J1939 channels on which you can send and receive information.
txCh = j1939Channel(db, 'MathWorks', 'Virtual 1', 1)
rxCh = j1939Channel(db, 'MathWorks', 'Virtual 1', 2)
txCh =
9-16
J1939 Examples
Device Information:
-------------------
DeviceVendor: 'MathWorks'
Device: 'Virtual 1'
DeviceChannelIndex: 1
DeviceSerialNumber: 0
Data Details:
-------------
ParameterGroupsAvailable: 0
ParameterGroupsReceived: 0
ParameterGroupsTransmitted: 0
FilterPassList: []
FilterBlockList: []
Channel Information:
--------------------
Running: 0
BusStatus: 'N/A'
InitializationAccess: 1
InitialTimestamp: [00 datetime]
SilentMode: 0
TransceiverName: 'N/A'
TransceiverState: 0
BusSpeed: 500000
SJW: 0
TSEG1: 0
TSEG2: 0
NumOfSamples: 0
Other Information:
------------------
UserData: []
rxCh =
Device Information:
-------------------
DeviceVendor: 'MathWorks'
Device: 'Virtual 1'
9-17
9 J1939
DeviceChannelIndex: 2
DeviceSerialNumber: 0
Data Details:
-------------
ParameterGroupsAvailable: 0
ParameterGroupsReceived: 0
ParameterGroupsTransmitted: 0
FilterPassList: []
FilterBlockList: []
Channel Information:
--------------------
Running: 0
BusStatus: 'N/A'
InitializationAccess: 1
InitialTimestamp: [00 datetime]
SilentMode: 0
TransceiverName: 'N/A'
TransceiverState: 0
BusSpeed: 500000
SJW: 0
TSEG1: 0
TSEG2: 0
NumOfSamples: 0
Other Information:
------------------
UserData: []
pgSingleFrame =
9-18
J1939 Examples
Data Details:
-------------
Timestamp: 0
Data: [255 255 255 255 255 255 255 255]
Signals: [11 struct]
Other Information:
------------------
UserData: []
pgMultiFrame =
Data Details:
-------------
Timestamp: 0
Data: [255 255 255 255 255 255 255 255 255 255 255 255]
Signals: [11 struct]
Other Information:
------------------
UserData: []
9-19
9 J1939
To begin using channels for transmit and receive operations, place them online.
start(rxCh);
start(txCh);
The transmit function sends parameter groups onto the network. The J1939 channel
automatically sends parameter groups requiring multiframe messaging via its transport
protocol.
transmit(txCh, pgSingleFrame)
transmit(txCh, pgSingleFrame)
transmit(txCh, pgMultiFrame)
transmit(txCh, pgSingleFrame)
transmit(txCh, pgSingleFrame)
pause(1);
The receive function retrieves information from the channel which represents
messaging that occurred on the network.
pgRx = receive(rxCh, Inf)
pgRx =
Data Details:
-------------
Timestamp
9-20
J1939 Examples
Data
Signals
Other Information:
------------------
UserData
pgRx(1)
ans =
Data Details:
-------------
Timestamp: 0.1530
Data: [255 255 255 255 255 255 255 255]
Signals: [11 struct]
Other Information:
------------------
UserData: []
Parameter groups sent using the transport protocol are reconstructed in full detail by the
channel.
pgRx(3)
9-21
9 J1939
ans =
Data Details:
-------------
Timestamp: 0.3810
Data: [255 255 255 255 255 255 255 255 255 255 255 255]
Signals: [11 struct]
Other Information:
------------------
UserData: []
To stop receiving data from the network, stop the J1939 channels.
stop(rxCh);
stop(txCh);
More About
J1939 Interface on page 9-2
J1939 Parameter Group Format on page 9-3
J1939 Network Management on page 9-5
J1939 Transport Protocols on page 9-6
J1939 Channel Workflow on page 9-7
9-22
10
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 (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.
10-2
CAN Communication Workflows in Simulink
In this section...
Message Transmission Workflow on page 10-3
Message Reception Workflow on page 10-5
10-3
10 CAN Communications in Simulink
Use a Mux block to combine every message from the source if they are transmitted at
the same rate.
10-4
CAN Communication Workflows in Simulink
Use one CAN Transmit block for each configured Mux block.
For workflow examples, see Build CAN Communication Simulink Models on page
10-9 and the Vehicle Network Toolbox demos.
10-5
10 CAN Communications in Simulink
Message Filtering
Set up filters to process only relevant messages. This ensures optimal simulation
performance.
Downstream Processing
Within the function-call subsystem if your downstream process must respond to all
messages received in a single timestep in this model.
Outside the function-call subsystem if your downstream process responds only to the
most recent message received in a given timestep in this model.
In this case, the CAN Unpack block will not respond to any other messages received,
irrespective of the messages ID.
10-6
Open the Vehicle Network Toolbox Block Library
In this section...
Using the Simulink Library Browser on page 10-7
Using the MATLAB Command Window on page 10-8
simulink
In the Simulink start page dialog, click Blank Model, and then Create Model. An
empty, Editor window opens.
The Simulink Library Browser opens. Its left pane contains a tree of available block
libraries in alphabetical order. Expand the Vehicle Network Toolbox node and click
CAN Communication.
10-7
10 CAN Communications in Simulink
10-8
Build CAN Communication Simulink Models
In this section...
Build a Message Transmit Model on page 10-9
Build a Message Receive Model on page 10-13
Save and Run the Model on page 10-21
Use this section with Build a Message Receive Model on page 10-13 and Save and
Run the Model on page 10-21 to build your complete model and run the simulation.
1 To start Simulink and create a new model, enter the following at the MATLAB
command prompt:
simulink
10-9
10 CAN Communications in Simulink
In the Simulink start page dialog, click Blank Model, and then Create Model. An
empty, Editor window opens.
2 In the Editor, click File > Save As to assign a name to your new model.
To use the blocks in a model, click a block in the library and drag it into the editor. For
this example, you need one instance each of the CAN Configuration, CAN Pack, and CAN
Tarnsmit blocks in your model.
Note The default configuration of each block in your model is based on the first
appropriate device that it finds on your system. The block settings in the images you
10-10
Build CAN Communication Simulink Models
see in the following steps might differ from those on your system until all the required
settings are applied.
This example requires a source block that feeds data to the CAN Pack block. Add a
Constant block to your model.
Make a connection between the Constant block and the CAN Pack block. When you move
the pointer near the output port of the Constant block, the pointer becomes a cross hair.
10-11
10 CAN Communications in Simulink
Click the Constant block output port and, 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.
You set parameters for the blocks in your model by double-clicking the block.
Double-click the CAN Configuration block to open its parameters dialog box. Set:
Click OK.
Double-click the CAN Pack block to open its parameters dialog box. Set the:
Click OK.
Double-click the CAN Transmit block to open its parameters dialog box. Set Device to
Vector Virtual 1 (Channel 1). Click Apply, then OK.
10-12
Build CAN Communication Simulink Models
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.
10-13
10 CAN Communications in Simulink
Step 7: Drag Vehicle Network Toolbox Blocks into the Model on page 10-14
Step 8: Drag Other Blocks to Complete the Model on page 10-15
Step 9: Connect the Blocks on page 10-17
Step 10: Specify the Block Parameter Values on page 10-19
Use this section with Build a Message Transmit Model on page 10-9 and Save and
Run the Model on page 10-21 to build your complete model and run the simulation.
For this example, you need one instance each of the CAN Configuration, CAN Receive,
and CAN Unpack blocks in your model. However, you add only the CAN Configuration
and the CAN Receive blocks here. Add the CAN Unpack block into the Function-Call
Subsystem described in Step 8: Drag Other Blocks to Complete the Model on page
10-15.
Tip: Configure a separate CAN channel for the CAN Receive and CAN Transmit blocks.
10-14
Build CAN Communication Simulink Models
Use the Function-Call Subsystem block from the Simulink Ports & Subsystems block
library to build your CAN Message pack subsystem.
10-15
10 CAN Communications in Simulink
3 Drop the CAN Unpack block from the Vehicle Network Toolbox block library in this
subsystem.
10-16
Build CAN Communication Simulink Models
To see the results of the simulation visually, drag the Scope block from the Simulink
block library into your model.
1 Connect the CAN Msg output port on the CAN Receive block to the In1 input port
on the Function-Call Subsystem block.
10-17
10 CAN Communications in Simulink
5 Connect the CAN Unpack Subsystem output port to the input port on the Scope
block.
10-18
Build CAN Communication Simulink Models
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.
Set parameters for the blocks in your model by double-clicking the block.
Configure the CAN Configuration1 Block
Double-click the CAN Configuration block to open its parameters dialog box. Set the:
10-19
10 CAN Communications in Simulink
Click OK.
Double-click the CAN Receive block to open its Parameters dialog box. Set the:
Click OK.
Double-click the CAN Unpack subsystem to open the Function-Call Subsystem editor. In
the model, double-click the CAN Unpack block to open its parameters dialog box. Set the:
Click OK.
10-20
Build CAN Communication Simulink Models
10-21
10 CAN Communications in Simulink
Before you run the simulation, save your model by clicking the Save icon or selecting
File > Save from the menu bar.
To run the simulation, click the Run button on the model window toolbar. Alternatively,
you can use the Simulation menu in the model window and choose the Run option.
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.
10-22
Build CAN Communication Simulink Models
10-23
10 CAN Communications in Simulink
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.
10-24
Build CAN Communication Simulink Models
More About
Build and Edit a Model in the Simulink Editor (Simulink)
10-25
10 CAN Communications in Simulink
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:
1 Define the IMPORT_SCANUTIL identifier that imports the required symbols when
you compile the S-function:
#define IMPORT_SCANUTIL
2 Include the can_datatype.h header located in[MATLABROOT]\toolbox\vnt
\vntblks\include\candatatype at the top of the S-function:
#include "can_datatype.h"
mdlInitialize_CAN_datatype(S);
5 Get custom data type ID using ssGetDataTypeId:
dataTypeID = ssGetDataTypeId(S,SL_CAN_MESSAGE_DTYPE_NAME);
6 Do one of the following:
10-26
Create Custom Blocks
More About
S-Function Basics (Simulink)
10-27
11
Hardware Limitations
This topic describes limitations of using hardware in the Vehicle Network Toolbox based
on limitations placed by the hardware vendor:
11 Hardware Limitations
Use only a single Receive block for message reception in Simulink and connect all
downstream Unpack blocks to it.
Use a Mux block to combine CAN messages from Unpack blocks transmitting at
the same rate into a single Transmit block.
Try reusing channels you have already created for your application in MATLAB.
11-2
12
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 (Simulink) to understand its functionality better.
12-2
Open the Vehicle Network Toolbox XCP Block Library
12-3
12 XCP Communications in Simulink
To start the Simulink Library Browser, enter simulink in the MATLAB Command
Window.
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.
12-4
XCP Data Acquisition over CAN
Vehicle Network Toolbox provides Simulink blocks for acquiring measurement values
from a slave via Simulink models over Controller Area Networks (CAN). This example
uses the XCP Configuration, XCP Data Acquisition, and XCP CAN Transport Layer
blocks to perform data transfer over a CAN bus.
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:
12-5
12 XCP Communications in Simulink
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
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.
12-6
XCP Data Acquisition over CAN
Plot the results to see the measurement values for Triangle and PWM from the slave.
The X-axis corresponds to the simulation timestep.
12-7
13
attachDatabase
Attach CAN database to messages and remove CAN database from messages
Syntax
attachDatabase (message, database)
attachDatabase (message, [])
Description
attachDatabase (message, database) attaches the specified database to the
specified message. You can then use signal-based interaction with the message data,
interpreting the message in its physical form.
attachDatabase (message, []) removes any attached database from the specified
message. You can then interpret messages in their raw form.
Input Arguments
message
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.
Examples
candb = canDatabase('C:\Database.dbc')
message = receive(canch, Inf)
attachDatabase(message, candb)
13-2
attachDatabase
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.
See Also
canDatabase | receive
Introduced in R2009a
13-3
13 Functions Alphabetical List
attributeInfo
Information about CAN database attributes
Syntax
info = attributeInfo(db,'Database',AttrName)
info = attributeInfo(db,'Node',AttrName,NodeName)
info = attributeInfo(db,'Message',AttrName,MsgName)
info = attributeInfo(db,'Signal',AttrName,MsgName,SignalName)
Description
info = attributeInfo(db,'Database',AttrName) returns a structure containing
information for the specified database attribute.
Examples
View Database Attribute Information
Create a CAN database object, and view information about its bus type and database
version.
db = canDatabase('J1939DB.dbc');
13-4
attributeInfo
db.Attributes
'BusType'
'DatabaseVersion'
'ProtocolType'
info = attributeInfo(db,'Database','BusType')
Name: 'BusType'
ObjectType: 'Database'
DataType: 'Double'
DefaultValue: 'CAN-test'
Value: 'CAN'
info = attributeInfo(db,'Database','DatabaseVersion')
Name: 'DatabaseVersion'
ObjectType: 'Database'
DataType: 'Double'
DefaultValue: '1.0'
Value: '8.1'
db = canDatabase('J1939DB.dbc');
db.Nodes
'AerodynamicControl'
'Aftertreatment_1_GasIntake'
'Aftertreatment_1_GasOutlet'
db.NodeInfo(1).Attributes
'ECU'
'NmJ1939AAC'
'NmJ1939Function'
info = attributeInfo(db,'Node','ECU','AerodynamicControl')
Name: 'ECU'
ObjectType: 'Network node'
DataType: 'Double'
DefaultValue: 'ECU-1'
13-5
13 Functions Alphabetical List
Value: 'ECU-10'
'A1'
'A1DEFI'
'A1DEFSI'
db.MessageInfo(1).Attributes
a = db.MessageInfo(1).Attributes
a =
'GenMsgCycleTime'
'GenMsgCycleTimeFast'
'GenMsgDelayTime'
'VFrameFormat'
info = attributeInfo(db,'Message','GenMsgCycleTime','A1')
Name: 'GenMsgCycleTime'
ObjectType: 'Message'
DataType: 'Undefined'
DefaultValue: 0
Value: 500
s =
2x1 struct array with fields:
Name
Comment
StartBit
SignalSize
ByteOrder
Signed
ValueType
13-6
attributeInfo
Class
Factor
Offset
Minimum
Maximum
Units
ValueTable
Multiplexor
Multiplexed
MultiplexMode
RxNodes
Attributes
AttributeInfo
s(1).Name
EngBlowerBypassValvePos
s(1).Attributes
'GenSigEVName'
'GenSigILSupport'
'GenSigInactiveValue'
info = attributeInfo(db,'Signal','GenSigInactiveValue','A1','EngBlowerBypassValvePos')
Name: 'GenSigInactiveValue'
ObjectType: 'Signal'
DataType: 'Undefined'
DefaultValue: 0
Value: 0
Input Arguments
db CAN database
CAN database object
13-7
13 Functions Alphabetical List
Output Arguments
info Attribute information
structure
Field Description
Name Attribute name
ObjectType Type of attribute
13-8
attributeInfo
Field Description
DataType Data class of attribute value
DefaultValue Default value assigned to attribute
Value Current value of attribute
See Also
See Also
Functions
canDatabase | messageInfo | nodeInfo | signalInfo | valueTableText
Properties
AttributeInfo | Attributes
Introduced in R2015b
13-9
13 Functions Alphabetical List
canChannel
Construct CAN channel connected to selected device
Syntax
canch = canChannel('vendor', 'device', devicechannelindex)
canch = canChannel('vendor', 'devicenumber')
Description
canch = canChannel('vendor', 'device', devicechannelindex) returns a
CAN channel connected to a device from a specified vendor.
For Vector products, device is a character vector that combines the device type and
a device index, such as 'CANCaseXL 1'. For example, if there are two CANcardXL
devices, device can be 'CANcardXL 1' or 'CANcardXL 2'.
For National Instruments, vendor is the character vector 'NI', and the devicenumber
is interface number defined in the NI Measurement & Automation Explorer.
For PEAK-System devices vendor is the character vector 'PEAK-System', and the
devicenumber is thealphanumeric device number defined for the channel.
Check the CAN Device Constructor in the canHWInfo display for channel construction.
Input Arguments
vendor
The name of the CAN device vendor. Specify the vendor name as a character vector.
device
13-10
canChannel
devicechannelindex
canch
Properties
Examples
canch = canChannel('Vector','CANCaseXL 1',1)
canch = canChannel('Vector','Virtual 1',2)
canch = canChannel('NI','CAN1')
canch = canChannel('PEAK-System','PCAN_USBBUS1')
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.
Tips
You cannot have more than one canChannel configured on the same NI-XNET or
PEAK-System device channel.
Use canHWInfo to obtain a list of available devices.
13-11
13 Functions Alphabetical List
See Also
canHWInfo
Introduced in R2009a
13-12
canDatabase
canDatabase
Create handle to CAN database file
Syntax
candb = canDatabase('dbfile.dbc')
Description
candb = canDatabase('dbfile.dbc') creates a handle to the specified database file
dbfile.dbc. You can specify just a file name, a full path, or a relative path. MATLAB
looks for dbfile.dbc on the MATLAB path. Vehicle Network Toolbox supports the
Vector CAN database (.dbc) files.
Input Arguments
dbfile.dbc
Database file name. You can specify just the name or the full path of the database file.
Properties
Examples
candb = canDatabase('C:\Database.dbc')
See Also
canMessage
Introduced in R2009a
13-13
13 Functions Alphabetical List
canHWInfo
Information on available CAN devices
Syntax
out = canHWInfo()
Description
out = canHWInfo() returns information about CAN devices and displays the
information on a per vendor and channel basis.
Output Arguments
out
Examples
info = canHWInfo
ans =
13-14
canHWInfo
See Also
canChannel
Introduced in R2009a
13-15
13 Functions Alphabetical List
canMessage
Build CAN message based on user-specified structure
Syntax
message = canMessage(id, extended, datalength)
message = canMessage(database, messagename)
Description
message = canMessage(id, extended, datalength) creates and returns a CAN
message object, from the raw message information.
Input Arguments
id
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
messagename
13-16
canMessage
Output Arguments
message
Properties
Examples
To construct a CAN message, type:
message = canMessage(2500, true, 4)
candb = canDatabase('c:\database.dbc')
message = canMessage (candb, 'messagename')
See Also
attachDatabase | extractAll | canDatabase | extractRecent | extractTime |
pack | unpack
Introduced in R2009a
13-17
13 Functions Alphabetical List
canMessageImport
Import CAN message log file from third-party tool
Syntax
message = canMessageImport('file','vendor')
message = canMessageImport('file','vendor',database)
message = canMessageImport( ___ 'OutputFormat','timetable')
Description
message = canMessageImport('file','vendor') imports a CAN message log file,
file, from a third-party vendor, vendor. All the messages in the log file are imported as
CAN messages, compatible with MATLAB and displayed as an array.
Input Arguments
file
vendor
database
Handle of the database whose information is applied to the imported log file.
13-18
canMessageImport
Output Arguments
message
Examples
To import a message log file as raw messages.
message = canMessageImport('MsgLog.asc','Vector','OutputFormat','timetable')
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.
See Also
canDatabase | receive | transmit
Introduced in R2010b
13-19
13 Functions Alphabetical List
canMessageReplayBlockStruct
Convert CAN messages for use as CAN Replay block output
Syntax
msgstructofarrays = canMessageReplayBlockStruct(msgs)
Description
msgstructofarrays = canMessageReplayBlockStruct(msgs) formats specified
CAN messages for use with the CAN Replay block. The CAN Replay block requires a
specific format for CAN messages, defined by a structure of arrays containing the ID,
Extended, Data, and other message elements.
Use this function to assign the formatted message structure to a variable. Then save this
variable to a MAT-file. The CAN Replay block mask allows selection of this MAT file and
the variable within it, to define the messages to replay in a Simulink model.
Examples
Create CAN Replay Block Message Structure
Create a message structure for the CAN Replay block, and save it to a MAT-file.
canMsgs = canMessageReplayBlockStruct(messages);
save('ReplayBlockMessages.mat','canMsgs');
Input Arguments
msgs Original CAN messages
CAN message objects | CAN message timetable
13-20
canMessageReplayBlockStruct
Example:
Output Arguments
msgstructofarrays Formatted CAN messages
struct
Formatted CAN messages, returned as structure of arrays containing the ID, Extended,
Data, and other elements of the messages.
See Also
See Also
Functions
canMessageTimetable | save
Blocks
CAN Replay
Introduced in R2017a
13-21
13 Functions Alphabetical List
canMessageTimetable
Convert CAN messages into timetable
Syntax
msgtimetable = canMessageTimetable(msg)
msgtimetable = canMessageTimetable(msg,database)
Description
msgtimetable = canMessageTimetable(msg) creates a CAN message timetable
from existing raw messages. The output message timetable contains the raw message
information (ID, Extended, Data, etc.) from the messages. If CAN message objects are
input which contain decoded information, that decoding is retained in the CAN message
timetable.
In many cases, using CAN message information in a timetable format can provide better
performance than using CAN message objects.
Examples
Convert Log Block Output to Timetable
13-22
canMessageTimetable
msgTimetable = canMessageTimetable(canMsgs);
Input Arguments
msg Raw CAN messages
CAN message timetable, array, or structure
Raw CAN messages, specified as a CAN message timetable, an array of CAN message
objects, or a CAN message structure from the CAN log block.
Example:
Output Arguments
msgtimetable CAN message timetable
timetable
See Also
See Also
Functions
canDatabase | canSignalTimetable
13-23
13 Functions Alphabetical List
Introduced in R2017a
13-24
canSignalImport
canSignalImport
Import CAN log file into decoded signal timetables
Syntax
sigtimetable = canSignalImport(file,vendor,database)
sigtimetable = canSignalImport(file,vendor,database,msgnames)
Description
sigtimetable = canSignalImport(file,vendor,database) imports a CAN
message log file from the specified vendor directly into decoded signal value timetables
using the provided database. The function returns a structure with a field for each
unique message in the timetable. Each field value is a timetable of all the signals in all
instances of that message. Use this form of syntax to convert an entire set of messages in
a single function call.
Examples
Import Signals from Log for All Messages
13-25
13 Functions Alphabetical List
sigtimetable1 = canSignalImport('MsgLog.asc','Vector',db,'Message1');
sigtimetable2 = canSignalImport('MsgLog.asc','Vector',db,{'Message1','Message2'});
Input Arguments
file CAN message log file
character vector | string
Vendor file format, specified as a character vector or string. The supported file formats
are those defined by Vector and Kvaser.
Example: 'Vector'
Data Types: char | string
Output Arguments
sigtimetable CAN signals
structure
13-26
canSignalImport
CAN signals, returned as a structure. The structure field names correspond to the
messages of the input, and each field value is a timetable of CAN signals.
Data Types: struct
See Also
See Also
Functions
canDatabase | canMessageImport | canSignalTimetable
Introduced in R2017a
13-27
13 Functions Alphabetical List
canSignalTimetable
Create CAN signal timetable from CAN message timetable
Syntax
sigtimetable = canSignalTimetable(msgtimetable)
sigtimetable = canSignalTimetable(msgtimetable,msgnames)
Description
sigtimetable = canSignalTimetable(msgtimetable) converts a timetable of
CAN message information into individual timetables of signal values. The function
returns a structure with a field for each unique message in the timetable. Each field
value is a timetable of all the signals in that message. Use this syntax form to convert an
entire set of messages in a single function call.
Examples
Create CAN Signal Timetables from All Messages
Create CAN signal timetables from all messages in a CAN message timetable.
sigTable = canSignalTimetable(msgTimetable);
Create CAN signal timetables from only specified messages in a CAN message timetable.
sigTable1 = canSignalTimetable(msgTimetable,'Message1');
13-28
canSignalTimetable
sigTable2 = canSignalTimetable(msgTimetable,{'Message1','Message2'});
Input Arguments
msgtimetable CAN message timetable
timetable
Output Arguments
sigtimetable CAN signals
structure
CAN signals, returned as a structure. The structure field names correspond to the
messages of the input, and each field value is a timetable of CAN signals.
Data Types: struct
See Also
See Also
Functions
canMessageTimetable | canSignalImport
Introduced in R2017a
13-29
13 Functions Alphabetical List
canSupport
Generate technical support log
Syntax
canSupport()
Description
canSupport() returns diagnostic information for all installed CAN devices and saves
output to the text file cansupport.txt in the current working directory.
For online support of Vehicle Network Toolbox software, visit the toolbox page on the
MathWorks Web site.
Introduced in R2009a
13-30
canTool
canTool
Open Vehicle CAN Bus Monitor
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.
See Also
See Also
Apps
Vehicle CAN Bus Monitor
Topics
Using the Vehicle CAN Bus Monitor on page 5-8
Vehicle CAN Bus Monitor on page 5-2
Introduced in R2009a
13-31
13 Functions Alphabetical List
configBusSpeed
Set bit timing rate of CAN channel
Syntax
configBusSpeed(canch,busspeed)
configBusSpeed(canch,busspeed,sjw,tseg1,tseg2,numberofsamples)
Description
configBusSpeed(canch,busspeed) sets the speed of the CAN channel in a direct
form that uses baseline bit timing calculation factors.
Input Arguments
canch
CAN channel object that you want to set the bit timing rate for
busspeed
Bit timing rate specified in bits per second for the identified object
sjw
Synchronization jump width. This value is the maximum value of time bit adjustments
tseg1
Length of time at the start of the sample point within a bit time
tseg2
Length of time at the end of the sample point within a bit time
13-32
configBusSpeed
numberofsamples
Examples
To configure the bus speed using baseline bit timing calculation, type:
canch = canChannel('Vector','CANCaseXL 1',1)
configBusSpeed(canch,250000)
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.
See Also
canChannel
Introduced in R2009a
13-33
13 Functions Alphabetical List
configBusSpeed (J1939)
Configure bit timing of J1939 channel
Syntax
configBusSpeed(chan,busspeed)
configBusSpeed(chan,busspeed,SJW,TSeg1,TSeg2,numsamples)
Description
configBusSpeed(chan,busspeed) sets the speed of the J1939 channel chan to
busspeed in a direct form that uses default bit timing calculation factors.
Note You can set bit timing only when the channel is offline and has initialization access
to the device.
Note Unless you have specific timing requirements provided for your network, you
should use the direct form of the function.
Examples
Set Bus Speed for Channel Directly
Use the direct form of syntax to configure a J1939 channel bus speed.
db = canDatabase('MyDatabase.dbc');
chan = j1939Channel(db,'Vector','CANCaseXL 1',1);
13-34
configBusSpeed (J1939)
configBusSpeed(chan,250000)
Use the advanced form of syntax to configure a J1939 channel bus speed with specific
calculation factors.
db = canDatabase('MyDatabase.dbc');
chan = j1939Channel(db,'Vector','CANCaseXL 1',1);
configBusSpeed(chan,500000,1,4,3,1)
Input Arguments
chan J1939 channel
channel object
Bit rate for channel, specified as a double. Provide the speed of the network in bits per
second.
Example: 250000
Data Types: double
Time segment 1, specified as a double, which defines the section before a bit is sampled
on a network.
13-35
13 Functions Alphabetical List
Time segment 2, specified as a double, which defines the section after a bit is sampled on
a network.
Data Types: double
Number of samples for bit state, specified as a double. Specify the number of samples
used for determining the bit state of a network.
Data Types: double
See Also
See Also
Functions
j1939Channel | start | stop | transmit
Introduced in R2015b
13-36
discard
discard
Discard all messages from CAN channel
Syntax
discard(canch)
Description
discard(canch) discards messages that are available to receive on the channel, canch.
Input Arguments
canch
Examples
Set up a CAN channel to receive messages and discard the messages received by the
channel.
See Also
canChannel
13-37
13 Functions Alphabetical List
Introduced in R2012a
13-38
discard (J1939)
discard (J1939)
Discard available parameter groups on J1939 channel
Syntax
discard(chan)
Description
discard(chan) deletes all parameter groups available on the J1939 channel chan. The
channel also deactivates when it is cleared from memory.
Examples
Discard Parameter Groups on Channel
db = canDatabase('MyDatabase.dbc');
chan = j1939Channel(db,'Vector','CANCaseXL 1',1);
start(chan)
discard(chan)
Input Arguments
chan J1939 channel
channel object
13-39
13 Functions Alphabetical List
See Also
See Also
Functions
j1939Channel | start
Introduced in R2015b
13-40
extractAll
extractAll
Select all instances of message from message array
Syntax
[extracted, remainder] = extractAll(message, messagename)
[extracted, remainder] = extractAll(message, id, extended)
Description
[extracted, remainder] = extractAll(message, messagename) parses the
given array message, and returns all instances of messages matching the specified
message name.
Input Arguments
message
An array of CAN message objects that you specify to parse and find the specified
messages by name or ID.
messagename
id
extended
Indicates whether the message ID is a standard or extended type. The Boolean value is
true if extended and false if standard.
13-41
13 Functions Alphabetical List
Output Arguments
extracted
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.
Examples
[msgOut, remainder] = extractAll(message, 'msg1')
[msgOut, remander] = extractAll(message,{'msg1' 'msg2' 'msg3'})
[msgOut, remainder] = extractAll(message, 3000, true)
[msgOut, remainder] = extractAll(message,[200 5000],[false true])
Tips
You can specify id as a cell array of message names or a vector of identifiers. For
example, if you pass id in as [250 5000], [false true], extractAll returns every instance
of both CAN message 250 and message 5000 that it finds in the message array. If any
id in the vector is an extended type, set extended to true and as a vector of the same
length as id.
See Also
extractRecent | extractTime
Introduced in R2009a
13-42
extractRecent
extractRecent
Select most recent message from array of messages
Syntax
extracted = extractRecent(message)
extracted = extractRecent(message, messagename)
extracted = extractRecent(message, id, extended)
Description
extracted = extractRecent(message) parses the given array message and returns
the most recent instance of each unique CAN message found in the array.
Input Arguments
message
An array of CAN message objects that you specify to parse and find the specified
messages by name or ID.
messagename
id
13-43
13 Functions Alphabetical List
extended
Indicates whether the message ID is a standard or extended type. The Boolean value is
true if extended and false if standard.
Output Arguments
extracted
An array of CAN message objects returned with the most recent instance of id found in
the message.
Examples
msgOut = extractRecent(message)
msgOut = extractRecent(message, 'msg1')
msgOut = extractRecent(message, {'msg1' 'msg2' msg3'})
msgOut = extractRecent(message, 3000, true)
msgOut = extractRecent(message, [400, 5000], [false true])
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.
See Also
extractAll | extractTime
Introduced in R2009a
13-44
extractTime
extractTime
Messages occurring within specified time range
Syntax
extracted = extractTime(message,starttime,endtime)
Description
extracted = extractTime(message,starttime,endtime) parses the array
message and returns all messages with a timestamp within the specified starttime
and endtime, including the starttime and endtime.
Input Arguments
message
starttime
Beginning of the time range, specified in seconds. Returns messages with a timestamp
greater than or equal to the specified start time.
endtime
End of the time range, specified in seconds. Returns messages with a timestamp up to
and including the specified end time.
Output Arguments
extracted
Returned array of CAN message objects whose messages occur within starttime and
endtime, inclusive.
13-45
13 Functions Alphabetical List
Examples
msgRange = extractTime(message,5,10.5)
msgRange = extractTime(message,0,60)
msgRange = extractTime(message,150,Inf)
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.
See Also
See Also
Functions
extractAll | extractRecent
Introduced in R2009a
13-46
extractAll (J1939)
extractAll (J1939)
Occurrences of specified parameter groups
Syntax
extractedPGs = extractAll(pgrp,pgname)
[extractedPGs,remainderPGs] = extractAll(pgrp,pgname)
Description
extractedPGs = extractAll(pgrp,pgname) returns all parameter groups whose
name occurs in pgname.
Examples
Extract Parameter Groups
Extract all parameter groups with a name of 'PG1' or 'PG2', and also return
unmatched parameter groups to a different array.
[extractedPGs,remainderPGs] = extractAll(parameterGroups, {'PG1' 'PG2'})
Input Arguments
pgrp J1939 parameter group
array of ParameterGroup objects
13-47
13 Functions Alphabetical List
Names of J1939 parameter groups to extract, specified as a character vector or cell array
of character vectors.
Example:
'PG1'
Data Types: char
Output Arguments
extractedPGs Extracted parameter groups
array of ParameterGroup objects
See Also
See Also
Functions
extractRecent | extractTime | j1939ParameterGroup
Introduced in R2015b
13-48
extractRecent (J1939)
extractRecent (J1939)
Occurrences of most recent parameter groups
Syntax
extractedPGs = extractRecent(pgrp)
extractedPGs = extractRecent(pgrp,pgname)
Description
extractedPGs = extractRecent(pgrp) returns the most recent instance of each
unique parameter group found in the array pgrp, based on the parameter group
timestamps.
Examples
Extract Most Recent Parameter Groups
Extract the most recent of each parameter group named 'PG1' or 'PG2'.
extractedPGs = extractRecent(pgrp,{'PG1' 'PG2'})
Input Arguments
pgrp J1939 parameter group
array of ParameterGroup objects
13-49
13 Functions Alphabetical List
Names of J1939 parameter groups to extract, specified as a character vector or cell array
of character vectors.
Example:
'PG1'
Data Types: char
Output Arguments
extractedPGs Extracted parameter groups
array of ParameterGroup objects
See Also
See Also
Functions
extractAll | extractTime | j1939ParameterGroup
Introduced in R2015b
13-50
extractTime (J1939)
extractTime (J1939)
Occurrences of parameter groups within time range
Syntax
extractedPGs = extractTime(pgrp,starttime,endtime)
Description
extractedPGs = extractTime(pgrp,starttime,endtime) returns the parameter
groups found in the array pgrp, with timestamps between the specified starttime and
endtime, inclusive.
Examples
Extract Parameter Groups Within Specified Time Range
Input Arguments
pgrp J1939 parameter group
array of ParameterGroup objects
13-51
13 Functions Alphabetical List
Start time and end time, specified as numeric values. These arguments define the range
of time from which to extract parameter groups, inclusively. For the earliest possible
starttime use 0, for the latest possible endtime use Inf. The endtime value must be
greater than the starttime value.
Data Types: double | single
Output Arguments
extractedPGs Extracted parameter groups
array of ParameterGroup objects
See Also
See Also
Functions
extractAll | extractRecent | j1939ParameterGroup
Introduced in R2015b
13-52
filterAllowAll
filterAllowAll
Allow all messages of specified identifier type
Syntax
filterAllowAll(canch, type)
Description
filterAllowAll(canch, type) opens the filter on the specified CAN channel to allow
all messages matching the specified identifier type to pass the acceptance filter.
Input Arguments
canch
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:
See Also
filterAllowOnly | filterBlockAll
13-53
13 Functions Alphabetical List
Introduced in R2011b
13-54
filterAllowOnly
filterAllowOnly
Configure message filter to allow only specified messages
Syntax
filterAllowOnly(canch,name)
filterAllowOnly(canch,ids,type)
Description
filterAllowOnly(canch,name) configures the filter on the channel canch, to pass
only messages with the specified name.
Input Arguments
canch
name
the name of the CAN message that you want to allow. You can specify a single name as a
character vector or a cell array of message names.
ids
The CAN message ID or IDs that you want to allow. You can specify:
13-55
13 Functions Alphabetical List
type
The identifier type by which to filter messages. CAN messages are 'Standard' and
'Extended'.
Examples
To filter a database defined message with name 'EngineMsg', type:
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.
See Also
filterAllowAll | filterBlockAll | hex2dec
Introduced in R2011b
13-56
filterBlockAll
filterBlockAll
Configure filter to block messages with specified identifier type
Syntax
filterBlockAll(canch,type)
Description
filterBlockAll(canch,type) configures the message filter to block all messages
matching the specified identifier type.
Input Arguments
canch
type
The identifier type by which to filter messages. CAN messages are 'Standard' and
'Extended'.
Examples
To block all standard message types, type:
See Also
filterAllowAll | filterAllowOnly
13-57
13 Functions Alphabetical List
Introduced in R2011b
13-58
filterAcceptRange
filterAcceptRange
Set range of CAN identifiers to pass acceptance filter
Syntax
filterAcceptRange(canch, rangestart, rangeend)
Description
filterAcceptRange(canch, rangestart, rangeend) sets the acceptance filter
for standard identifier CAN messages. It allows messages within the given range on the
CAN channel canch to pass. rangestart and rangeend establish the beginning and
end of the acceptable range. You can use this function with Vector devices only.
Notes
You can configure message filtering only when the CAN channel is offline.
13-59
13 Functions Alphabetical List
Input Arguments
canch
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.
Examples
canch = canChannel('Vector','CANCaseXL 1',1)
filterAcceptRange(canch,600,625)
filterAcceptRange(canch,705,710)
Tips
When you call filterAcceptRange on an open or reset filter, it automatically blocks
the entire standard CAN identifier range, allowing only the desired range to pass.
Subsequent calls to filterAcceptRange open additional ranges on the filter without
blocking the ranges previously allowed.
See Also
filterBlockRange | filterSet | filterReset
Introduced in R2009a
13-60
filterBlockRange
filterBlockRange
Set range of CAN identifiers to block via acceptance filter
Syntax
filterBlockRange(canch, rangestart, rangeend)
Description
filterBlockRange(canch, rangestart, rangeend) blocks messages within a
given range by setting an acceptance filter. You can use this function with Vector devices
only.
Input Arguments
canch
The CAN channel that you want to set the filter for.
rangestart
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.
13-61
13 Functions Alphabetical List
Examples
You can set the filter to block or accept messages within a specific range.
canch = canChannel('Vector','CANCaseXL 1',1)
filterBlockRange(canch, 500, 750)
filterAcceptRange(canch,600,625)
filterAcceptRange(canch,705,710)
filterBlockRange(canch,1075,1080)
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.
See Also
filterAcceptRange | filterSet | filterReset
Introduced in R2009a
13-62
filterReset
filterReset
Open CAN message acceptance filters
Syntax
filterReset(canch)
Description
filterReset(canch) resets the CAN message filters on the CAN channel canch for
both standard and extended CAN identifier types. Then all messages of all identifier
types can pass.
This function does not work if the channel is online. Make sure that the channel is offline
before calling filterReset.
Input Arguments
canch
The CAN channel that you want to reset the filter for.
Examples
Reset the message filters as shown:
13-63
13 Functions Alphabetical List
See Also
filterAcceptRange | filterSet | filterBlockRange
Introduced in R2009a
13-64
filterSet
filterSet
Set specific CAN message acceptance filter configuration
Syntax
filterSet(canch, code, mask, idtype)
filterSet(canch, id, idtype)
Description
filterSet(canch, code, mask, idtype) sets the CAN message acceptance filter to
the specified code and mask. You also must specify the CAN identifier type idtype on
the CAN channel canch.
Input Arguments
canch
The CAN channel that you want to set the filter for.
code
13-65
13 Functions Alphabetical List
mask
id
Set a filter on the CAN message with the id, range of ids, multiple ranges of ids, or a
combination of ids.
idtype
Examples
canch = canChannel('Vector','CANCaseXL 1',1)
filterSet(canch,500,750, 'Standard')
filterSet(canch,2500,3000,'Extended')
To let Vehicle Network Toolbox determine the best possible code and mask option:
canch = canChannel('Kvaser', 'USBcan Professional 1', 1)
filterSet(canch, [500:502 1000], 'Standard')
filterSet(canch, [7500:8000 12000], 'Extended')
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.
See Also
filterAcceptRange | filterBlockRange | filterReset
Introduced in R2009a
13-66
filterAllowAll (J1939)
filterAllowAll (J1939)
Open parameter group filters on channel
Syntax
filterAllowAll(chan)
Description
filterAllowAll(chan) opens all parameter group filters on the specified channel,
making all parameter groups receivable.
Examples
Allow All Parameter Groups to Be Received
Open the filter to allow all J1939 parameter groups on the channel.
db = canDatabase('MyDatabase.dbc');
chan = j1939Channel(db,'Vector','CANCaseXL 1',1);
filterAllowAll(chan)
Input Arguments
chan J1939 channel
channel object
13-67
13 Functions Alphabetical List
See Also
See Also
Functions
filterAllowOnly | filterBlockOnly | j1939Channel
Introduced in R2015b
13-68
filterAllowOnly (J1939)
filterAllowOnly (J1939)
Allow only specified parameter groups to pass channel filter
Syntax
filterAllowOnly(chan,pgname)
Description
filterAllowOnly(chan,pgname) configures the filter on the channel chan to pass
only the parameter groups specified by pgname.
Examples
Allow Only Some Parameter Groups to Be Received
Configure the channel filter to allow only specified J1939 parameter groups to be
received on the channel.
db = canDatabase('MyDatabase.dbc');
chan = j1939Channel(db,'Vector','CANCaseXL 1',1);
filterAllowOnly(chan,{'PG1' 'PG2'})
Input Arguments
chan J1939 channel
channel object
13-69
13 Functions Alphabetical List
Allowed J1939 parameter groups, specified as a character vector or cell array of character
vectors.
Example:
'PG1'
Data Types: char
See Also
See Also
Functions
filterAllowAll | filterBlockOnly | j1939Channel
Introduced in R2015b
13-70
filterBlockOnly (J1939)
filterBlockOnly (J1939)
Block only specified parameter groups on channel filter
Syntax
filterBlockOnly(chan,pgname)
Description
filterBlockOnly(chan,pgname) configures the filter on the channel chan to block
only the parameter groups specified by pgname.
Examples
Block Only Some Parameter Groups on Channel
Configure the channel filter to block only specified J1939 parameter groups on the
channel.
db = canDatabase('MyDatabase.dbc');
chan = j1939Channel(db,'Vector','CANCaseXL 1',1);
filterBlockOnly(chan,{'PG1' 'PG2'})
Input Arguments
chan J1939 channel
channel object
13-71
13 Functions Alphabetical List
Blocked J1939 parameter groups, specified as a character vector or cell array of character
vectors.
Example:
'PG1'
Data Types: char
See Also
See Also
Functions
filterAllowAll | filterAllowOnly | j1939Channel
Introduced in R2015b
13-72
j1939ParameterGroupImport
j1939ParameterGroupImport
Import J1939 log file
Syntax
pgs = j1939ParameterGroupImport(file,vendor,database)
Description
pgs = j1939ParameterGroupImport(file,vendor,database) reads the input file
as a CAN message log file from the specified vendor. Using the specified CAN database,
the CAN messages are converted into J1939 parameter groups, and assigns the output to
the array pgs.
Examples
Import Log Data to J1939 Parameter Groups
Read a CAN message log file, and generate J1939 parameter groups according to a CAN
database.
db = canDatabase('MyDatabase.dbc');
pgs = j1939ParameterGroupImport('MsgLog.asc','Vector',db);
Input Arguments
file CAN message log file
character vector | string
13-73
13 Functions Alphabetical List
Vendor file format, specified as a character vector or string. The supported file formats
are those defined by Vector and Kvaser.
Example: 'Vector'
Data Types: char | string
Output Arguments
pgs J1939 parameter groups
parameter group array
See Also
See Also
Functions
canDatabase
Introduced in R2017a
13-74
mdf
mdf
Access information contained in MDF file
Syntax
mdfObj = mdf(mdfFileName)
Description
mdfObj = mdf(mdfFileName) identifies a measurement data format (MDF) file and
returns an MDF file object, which you can use to access information and data contained
in the file. You can specify a full or partial path to the file.
Examples
Create MDF File Object for Specified MDF File
Create an MDF object for a given file, and view the object display.
mdfObj = mdf('MDFFile.mf4')
File Details
Name: 'MDFFile.mf4'
Path: 'c:\temp\MDFFile.mf4'
Author: 'HOK'
Department: 'Research'
Project: 'MDF'
Subject: 'CAN bus'
Comment: 'This file contains CAN messages'
Version: '4.10'
DataSize: 32100
InitialTimestamp: 2016-02-27 12:09:02
Creator Details
ProgramIdentifier: 'mmddff.04'
13-75
13 Functions Alphabetical List
File Contents
Attachment: [11 struct]
ChannelNames: {61 cell}
ChannelGroup: [16 struct]
Input Arguments
mdfFileName MDF file name
char vector
MDF file name, specified as a char vector, including necessary full or relative path.
Example: 'MDFFile.mf4'
Data Types: char
Output Arguments
mdfObj MDF file
MDF file object
MDF file, returned as an MDF file object. The object provides access to the MDF file
information contained in the following properties.
Property Description
Name Name of the MDF file, including extension
Path Full path to the MDF file, including file name
Author Author who originated the MDF file
Department Department that originated the MDF file
Project Project that originated the MDF file
Subject Subject matter in the MDF file
Comment Open comment field from the MDF file
Version MDF standard version of the file
DataSize Total size of the data in the MDF file, in bytes
13-76
mdf
Property Description
InitialTimestamp Time when file data acquisition began
ProgramIdentifier Originating program of the MDF file
Creator Structure containing details about creator of the MDF file,
with these fields: VendorName, ToolName, ToolVersion,
UserName, and Comment
Attachment Structure of information about attachments contained within
the MDF file, with these fields: Name, Path, Comment, Type,
MIMEType, Size, EmbeddedSize, and MD5CheckSum
ChannelNames Cell array of the channel names in each channel group
ChannelGroup Structure of information about channel groups contained within
the MDF file, with these fields: AcquisitionName, Comment,
NumSamples, DataSize, Sorted, and Channel
See Also
See Also
Functions
read | saveAttachment
Introduced in R2016b
13-77
13 Functions Alphabetical List
messageInfo
Information about CAN database messages
Syntax
msgInfo = messageInfo(candb)
msgInfo = messageInfo(candb,msgName)
msgInfo = messageInfo(candb,id,msgIsExtended)
Description
msgInfo = messageInfo(candb) returns a structure with information about the CAN
messages in the specified database candb.
Examples
Get All Messages
candb = canDatabase('J1939DB.dbc');
msgInfo = messageInfo(candb)
msgInfo =
3x1 struct array with fields:
Name
Comment
ID
Extended
J1939
13-78
messageInfo
Length
Signals
SignalInfo
TxNodes
Attributes
AttributeInfo
You can index into the structure for information on a particular message.
Get information from one message in a CAN database using the message name.
candb = canDatabase('J1939DB.dbc');
msgInfo = messageInfo(candb,'A1')
msgInfo =
Name: 'A1'
Comment: 'This is an A1 message'
ID: 419364350
Extended: 1
J1939: [1x1 struct]
Length: 8
Signals: {2x1 cell}
SignalInfo: [2x1 struct]
TxNodes: {'AerodynamicControl'}
Attributes: {4x1 cell}
AttributeInfo: [4x1 struct]
Get information from one message in a CAN database using the message ID.
candb = canDatabase('J1939DB.dbc');
msgInfo = messageInfo(candb,419364350,true)
msgInfo =
Name: 'A1'
Comment: 'This is an A1 message'
ID: 419364350
Extended: 1
J1939: [1x1 struct]
Length: 8
Signals: {2x1 cell}
SignalInfo: [2x1 struct]
13-79
13 Functions Alphabetical List
TxNodes: {'AerodynamicControl'}
Attributes: {4x1 cell}
AttributeInfo: [4x1 struct]
Input Arguments
candb CAN database
CAN database object
CAN database, specified as a CAN database object. candb identifies the database
containing the CAN messages that you want information about.
Example: candb = canDatabase(_____)
Message name, specified as a character vector. Provide the name of the message you
want information about.
Example: 'A1'
Data Types: char
id Message ID
numeric value
Message ID, specified as a numeric value. id is the numeric identifier of the specified
message, in either extended or standard form.
Example: 419364350
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 |
uint32 | uint64
13-80
messageInfo
Output Arguments
msgInfo Message information
structure
Message information, returned as a structure or array of structures for the specified CAN
database and messages.
See Also
See Also
Functions
attributeInfo | canDatabase | canMessage | nodeInfo | signalInfo
Properties
MessageInfo | Messages
Introduced in R2009a
13-81
13 Functions Alphabetical List
nodeInfo
Information about CAN database node
Syntax
info = nodeInfo(db)
info = nodeInfo(db,NodeName)
Description
info = nodeInfo(db) returns a structure containing information for all nodes found
in the database db.
If no matches are found in the database, nodeInfo returns an empty node information
structure.
Examples
View Information from All Nodes
Create a CAN database object, and view information about its nodes.
db = canDatabase('c:\Database.dbc')
info = nodeInfo(db)
info =
3x1 struct array with fields:
Name
Comment
Attributes
AttributeInfo
13-82
nodeInfo
n = info(1).Name
n =
AerodynamicControl
Create a CAN database object, and view information about its first node, listed in the
previous example.
db = canDatabase('c:\Database.dbc')
info = nodeInfo(db,'AerodynamicControl')
info =
Name: 'AerodynamicControl'
Comment: 'This is an AerodynamicControl node'
Attributes: {3x1 cell}
AttributeInfo: [3x1 struct]
Input Arguments
db CAN database
CAN database object
Output Arguments
info Node information
structure
13-83
13 Functions Alphabetical List
Field Description
Name Node name
Comment Text about node
See Also
See Also
Functions
attributeInfo | canDatabase | messageInfo | signalInfo
Properties
NodeInfo | Nodes
Introduced in R2015b
13-84
pack
pack
Pack signal data into CAN message
Syntax
pack(message, value, startbit, signalsize, byteorder)
Description
pack(message, value, startbit, signalsize, byteorder) takes specified
input parameters and packs them into the message.
Input Arguments
message
The CAN message structure that you specify for the signal to be packed in.
value
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'.
13-85
13 Functions Alphabetical List
Examples
pack(message, 25, 0, 16, 'LittleEndian')
See Also
canMessage | extractAll | extractRecent | unpack | extractTime
Introduced in R2009a
13-86
read
read
Read channel data from MDF file
Syntax
data = read(mdfObj,chanGroupIndex,chanName)
data = read(mdfObj,chanGroupIndex,chanName,startPosition)
data = read(mdfObj,chanGroupIndex,chanName,startPosition,
endPosition)
data = read(mdfObj,chanGroupIndex,chanName,startPosition,
endPosition,'OutputFormat',fmtType)
[data,time] = read(mdfObj,chanGroupIndex,chanName,startPosition,
endPosition,'OutputFormat','Vector')
Description
data = read(mdfObj,chanGroupIndex,chanName) reads all data for the specified
channel from the MDF file identified by the MDF file object mdfObj.
data = read(mdfObj,chanGroupIndex,chanName,startPosition,
endPosition) reads data for the range specified from startPosition to
endPosition.
data = read(mdfObj,chanGroupIndex,chanName,startPosition,
endPosition,'OutputFormat',fmtType) returns data with the specified output
format.
[data,time] = read(mdfObj,chanGroupIndex,chanName,startPosition,
endPosition,'OutputFormat','Vector') returns two vectors of channel data and
corresponding timestamps.
13-87
13 Functions Alphabetical List
Examples
Read All Data from Multiple Channels
Read all available data from the MDF file for specified channels.
mdfObj = mdf('MDFFile.mf4');
data = read(mdfObj,1,{'Channel1','Channel2'});
Read a range of data from the MDF file using indexing for startPosition and
endPosition to specify the data range.
mdfObj = mdf('MDFFile.mf4');
data = read(mdfObj,1,{'Channel1','Channel2'},1,10);
Read a range of data from the MDF file using time values for startPosition and
endPosition to specify the data range.
mdfObj = mdf('MDFFile.mf4');
data = read(mdfObj,1,{'Channel1','Channel2'},seconds(5.5),seconds(7.3));
Read all available data from the MDF file, returning data and time vectors.
mdfObj = mdf('MDFFile.mf4');
[data,time] = read(mdfObj,1,'Channel1','OutputFormat','Vector');
Read all available data from the MDF file, returning time series data.
mdfObj = mdf('MDFFile.mf4');
data = read(mdfObj,1,'Channel1','OutputFormat','TimeSeries');
Input Arguments
mdfObj MDF file
MDF file object
13-88
read
Index of channel group, specified as a numeric value that identifies the channel group
from which to read.
Example: 1
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 |
uint32 | uint64
13-89
13 Functions Alphabetical List
Last position of channel data range, specified as a numeric value or duration. The
endPosition option specifies the last position for reading a range of channel data.
Provide both the startPosition and endPosition to specify retrieval of a range of
data. The function returns up to but not including endPosition when reading a range.
Provide a numeric value to specify an index position; use a duration to specify a time
position.
Example: 1000
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 |
uint32 | uint64 | duration
Format for output data, specified as a character vector. This option formats the output
according to the following table.
OutputFormat Description
'Timetable' Return a timetable from one or more channels into one output
variable. This is the only format that supports reading from
multiple channels at the same time. (Default.)
Example: 'Vector'
Data Types: char
13-90
read
Output Arguments
data Channel data
double | timeseries | timetable
Channel data times, returned as a vector of double elements. The time vector is returned
only when the 'OutputFormat' is set to 'Vector'.
See Also
See Also
Functions
mdf | saveAttachment
Topics
Time Series (MATLAB)
Represent Dates and Times in MATLAB (MATLAB)
Tables (MATLAB)
Introduced in R2016b
13-91
13 Functions Alphabetical List
receive
Receive messages from CAN bus
Syntax
message = receive(canch,
messagesrequested,'OutputFormat','timetable')
message = receive(canch,messagesrequested)
Description
message = receive(canch,
messagesrequested,'OutputFormat','timetable') returns a timetable of CAN
messages received on the CAN channel canch. The number of messages returned
is less than or equal to messagesrequested. If fewer messages are available than
messagesrequested specifies, the function returns the currently available messages. If
no messages are available, the function returns an empty array. If messagesrequested
is Inf, the function returns all available messages.
Input Arguments
canch
messagesrequested
13-92
receive
Output Arguments
message
CAN messages from the channel, returned as a timetable of messages or an array of CAN
message objects.
Properties
Examples
Receive up to five messages as an array of message objects.
canch = canChannel('Vector','CANCaseXL 1',1)
start(canch)
message = receive(canch,5)
See Also
canChannel | canMessage | transmit
Introduced in R2009a
13-93
13 Functions Alphabetical List
receive (J1939)
Receive parameter groups from J1939 bus
Syntax
pgrp = receive(chan,count)
Description
pgrp = receive(chan,count) receives parameter groups from the bus via channel
chan. The number of received parameter groups is limited to the value of count.
Examples
Receive Parameter Groups from Bus
Receive all the available parameter groups from the bus by specifying a count of Inf.
db = canDatabase('MyDatabase.dbc')
chan = j1939Channel(db,'Vector','CANCaseXL 1',1)
start(chan)
pgrp = receive(chan,Inf)
Input Arguments
chan J1939 channel
channel object
13-94
receive (J1939)
Output Arguments
pgrp J1939 parameter groups
array of ParameterGroup objects
See Also
See Also
Functions
j1939Channel | start | transmit
Introduced in R2015b
13-95
13 Functions Alphabetical List
replay
Retransmit messages from CAN bus
Syntax
replay(canch, message)
Description
replay(canch, message) retransmits the message or messages message on the
channel canch, based on the relative differences of their timestamps. The replay function
also replays messages from MATLAB to Simulink
Input Arguments
canch
message
Examples
This example uses a loopback connection between two channels where:
13-96
replay
The timestamp differentials between messages in the two receive arrays, msgRx1 and
msgRx2, are equal.
See Also
canChannel | canMessage | receive | transmit
Introduced in R2009a
13-97
13 Functions Alphabetical List
saveAttachment
Save attachment from MDF file
Syntax
saveAttachment(mdfObj,AttachmentName)
saveAttachment(mdfObj,AttachmentName,DestFile)
Description
saveAttachment(mdfObj,AttachmentName) saves the specified attachment from
the MDF file to the current MATLAB working folder. The attachment is saved with its
existing name.
Examples
Save Attachment with Original Name
Save an MDF file attachment with its original name in the current folder.
mdfObj = mdf('MDFFile.mf4');
saveAttachment(mdfObj,'AttachmentName.ext')
Save an MDF file attachment with a new name in the current folder.
mdfObj = mdf('MDFFile.mf4');
saveAttachment(mdfObj,'AttachmentName.ext','MyFile.ext')
Save an MDF file attachment in a folder specified with a relative path name, in this case
in the parent of the current folder.
13-98
saveAttachment
mdfObj = mdf('MDFFile.mf4');
saveAttachment(mdfObj,'AttachmentName.ext','..\MyFile.ext')
This example saves an MDF file attachment using an absolute path name.
mdfObj = mdf('MDFFile.mf4');
saveAttachment(mdfObj,'AttachmentName.ext','C:\MyDir\MyFile.ext')
Input Arguments
mdfObj MDF file
MDF file object
MDF file attachment name, specified as a character vector. The name of the attachment
is available in the Name field of the MDF file object Attachment property.
Example: 'file1.dbc'
Data Types: char
Destination file name for the saved attachment, specified as a character vector. The
specified destination can include an absolute or relative path, otherwise the attachment
is saved in the current folder.
Example: 'MyFile.ext'
Data Types: char
13-99
13 Functions Alphabetical List
See Also
See Also
Functions
mdf | read
Introduced in R2016b
13-100
signalInfo
signalInfo
Information about signals in CAN message
Syntax
SigInfo = signalInfo(candb,msgName)
SigInfo = signalInfo(candb,id,extended)
SigInfo = signalInfo(candb,id,extended,signalName)
Description
SigInfo = signalInfo(candb,msgName) returns information about the signals in
the specified CAN message msgName in the specified database candb.
Examples
Use Message Name to Get Information
Get signal information from the message 'Battery_Voltage'.
SigInfo = signalInfo(candb,'Battery_Voltage');
13-101
13 Functions Alphabetical List
SigInfo = signalInfo(candb,196608,true,'BatVlt');
Input Arguments
candb CAN database
CAN database object
CAN database, specified as a CAN database object, that contains the signals that you
want information about.
Example: candb = canDatabase('C:\Database.dbc')
Message name, specified as a character vector. Provide the name of the message that
contains the signals that you want information about.
Example: 'Battery_Voltage'
Data Types: char
id Message identifier
numeric value
Message identifier, specified as a numeric value. Provide the numeric identifier of the
specified message that contains the signals you want information about.
Example: 196608
Extended message indicator, specified as true or false. Indicate whether the message
ID is standard or extended type. Use the logical value true if extended, or false if
standard.
Example: true
Data Types: logical
13-102
signalInfo
Name of the signal, specified as a character vector. Provide the name of the specific
signal that you want information about.
Example: 'BatVlt'
Data Types: char
Output Arguments
SigInfo Signal information
struct or array of struct
See Also
See Also
Functions
canDatabase | canMessage | messageInfo
Properties
MessageInfo | Messages
Introduced in R2009a
13-103
13 Functions Alphabetical List
start
Set CAN channel online
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:
Examples
canch = canChannel('Vector','CANCaseXL 1',1)
start(canch)
See Also
stop
Introduced in R2009a
13-104
start (J1939)
start (J1939)
Start channel connection to J1939 bus
Syntax
start(chan)
Description
start(chan) activates the channel chan on a J1939 bus. The channel remains
activated until stop is called or it is cleared from the memory.
Examples
Start J1939 Channel
db = canDatabase('MyDatabase.dbc');
chan = j1939Channel(db,'Vector','CANCaseXL 1',1);
start(chan)
Input Arguments
chan J1939 channel
channel object
13-105
13 Functions Alphabetical List
See Also
See Also
Functions
j1939Channel | stop
Introduced in R2015b
13-106
stop
stop
Set CAN channel offline
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.
Examples
canch = canChannel('Vector','CANCaseXL 1',1)
start(canch)
stop(canch)
See Also
start
Introduced in R2009a
13-107
13 Functions Alphabetical List
stop (J1939)
Stop channel connection to J1939 bus
Syntax
stop(chan)
Description
stop(chan) deactivates the channel chan on a J1939 bus. The channel also deactivates
when it is cleared from the memory.
Examples
Stop J1939 Channel
db = canDatabase('MyDatabase.dbc');
chan = j1939Channel(db,'Vector','CANCaseXL 1',1);
start(chan)
stop(chan)
Input Arguments
chan J1939 channel
channel object
13-108
stop (J1939)
See Also
See Also
Functions
j1939Channel | start
Introduced in R2015b
13-109
13 Functions Alphabetical List
transmit
Send CAN messages to CAN bus
Syntax
transmit(canch,message)
Description
transmit(canch,message) sends the message or array of messages onto the bus via
the CAN channel.
Note The transmit function ignores the Timestamp property and the Error property.
Examples
transmit(canch,[message0,message1,message2])
13-110
transmit
message = canMessage(250,false,8);
message.Data = ([45 213 53 1 3 213 123 43]);
message.Remote = true;
canch = canChannel('MathWorks','Virtual 1',1);
start(canch)
transmit(canch,message)
Input Arguments
canch CAN channel
CAN channel object
CAN channel, specified as a CAN channel object. This is the channel by which you access
the CAN bus.
See Also
See Also
Functions
canChannel | canMessage | receive
Introduced in R2009a
13-111
13 Functions Alphabetical List
transmit (J1939)
Send parameter groups via channel to J1939 bus
Syntax
transmit(chan,pgrp)
Description
transmit(chan,pgrp) sends the specified parameter groups in the array pgrp onto
the J1939 bus via the channel chan.
Examples
Send Parameter Groups onto Bus
db = canDatabase('MyDatabase.dbc');
chan = j1939Channel(db,'Vector','CANCaseXL 1',1);
start(chan)
pgrp = j1939ParameterGroup(db,'MyParameterGroup')
transmit(chan,pgrp)
Input Arguments
chan J1939 channel
channel object
13-112
transmit (J1939)
See Also
See Also
Functions
j1939Channel | j1939ParameterGroup | receive | start
Introduced in R2015b
13-113
13 Functions Alphabetical List
transmitConfiguration
Display messages configured for automatic transmission
Syntax
transmitConfiguration(canch)
Description
transmitConfiguration(canch) displays information about all messages in the CAN
Channel, canch, configured for periodic transmit or event-based transmit.
Input Arguments
canch
Name of the CAN channel configured for periodic transmit or event-based transmit.
Examples
Create a CAN channel and configure two messages:
canch = canChannel('Vector', 'Virtual 1', 1);
msg1 = canMessage(500, false, 8);
msg2 = canMessage(750, false, 8);
13-114
transmitConfiguration
transmitConfiguration(canch)
Event Messages
See Also
canChannel | canMessage | transmitEvent | transmitPeriodic
Introduced in R2010b
13-115
13 Functions Alphabetical List
transmitEvent
Configure messages for event-based transmission
Syntax
transmitEvent(canch, msg, state)
Description
transmitEvent(canch, msg, state) enables an event-based transmit of the CAN
message, msg, on the channel, canch when 'state' is On and disables it when 'state'
is Off.
Input Arguments
canch
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
Examples
Construct a CAN channel and configure a message on the channel:
canch = canChannel('Vector', 'CANCaseXL 1', 1);
msg = canMessage(500, false, 4);
13-116
transmitEvent
Enable the message for event-based transmit, start the channel, and change some data to
trigger the event-based transmit:
transmitEvent(ch, msg, 'On');
start(canch);
msg.Data = [1 2 3 4];
See Also
canChannel | canMessage | transmitConfiguration | transmitPeriodic
Introduced in R2010b
13-117
13 Functions Alphabetical List
transmitPeriodic
Configure messages for periodic transmission
Syntax
transmitPeriodic(canch, msg, 'On', period)
transmitPeriodic(canch, msg, 'Off')
Description
transmitPeriodic(canch, msg, 'On', period) enables periodic transmit of the
message, msg, on the channel, canch, to transmit at the specified period, period.
Input Arguments
canch
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.
13-118
transmitPeriodic
Examples
Construct a CAN channel and configure a message on the channel:
canch = canChannel('Vector', 'Virtual 1', 1);
msg = canMessage(500, false, 4);
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:
transmitPeriodic(canch, msg, 'On', 1);
start(canch);
msg.Data = [1 2 3 4];
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.
See Also
canChannel | canMessage | transmitConfiguration | transmitEvent
Introduced in R2010b
13-119
13 Functions Alphabetical List
unpack
Unpack signal data from message
Syntax
value = unpack(message, startbit, signalsize, byteorder, datatype)
Description
value = unpack(message, startbit, signalsize, byteorder, datatype)
takes a set of input parameters to unpack the signal value from the message and returns
the value as output.
Input Arguments
message
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.
13-120
unpack
Output Arguments
value
Examples
value = unpack(message, 0, 16, 'LittleEndian', 'int16')
See Also
canMessage | extractAll | extractRecent | pack | extractTime
Introduced in R2009a
13-121
13 Functions Alphabetical List
valueTableText
Look up value of table text for signal
Syntax
vtt = valueTableText(db,MsgName,SignalName,TableVal)
Description
vtt = valueTableText(db,MsgName,SignalName,TableVal) returns the text from
the value table for a specified message signal.
Examples
View Table Text for Signal
Create a CAN database object, and select a message and signal to retrieve their table
text.
Identify a message.
db = canDatabase('J1939DB.dbc');
m = db.MessageInfo(1)
m =
Name: 'A1'
Comment: 'This is a A1message'
ID: 419364350
Extended: 1
J1939: [1x1 struct]
Length: 8
Signals: {2x1 cell}
SignalInfo: [2x1 struct]
TxNodes: {'AerodynamicControl'}
Attributes: {4x1 cell}
AttributeInfo: [4x1 struct]
13-122
valueTableText
s =
Name: 'EngGasSupplyPress'
Comment: 'Gage pressure of gas supply to fuel metering device.'
StartBit: 8
SignalSize: 16
ByteOrder: 'LittleEndian'
Signed: 0
ValueType: 'Integer'
Class: 'uint16'
Factor: 0.5000
Offset: 0
Minimum: 0
Maximum: 3.2128e+04
Units: 'kPa'
ValueTable: [4x1 struct]
Multiplexor: 0
Multiplexed: 0
MultiplexMode: 0
RxNodes: {'Aftertreatment_1_GasIntake'}
Attributes: {3x1 cell}
AttributeInfo: [3x1 struct]
vtt =
pump error
Input Arguments
db CAN database
CAN database object
13-123
13 Functions Alphabetical List
Message name, specified as a character vector. You can view available message names
from the db.Messages property.
Example: 'A1'
Data Types: char
Signal name, specified as a character vector. You can view available signal names from
the db.MessageInfo(n).Signals property.
Example: 'EngGasSupplyPress'
Data Types: char
Output Arguments
vtt Table text
table text
See Also
See Also
Functions
attributeInfo | canDatabase | messageInfo | nodeInfo | signalInfo
13-124
valueTableText
Properties
MessageInfo | Messages
Introduced in R2015b
13-125
13 Functions Alphabetical List
Description
The Vehicle CAN Bus Monitor displays live CAN message traffic.
Examples
Using the Vehicle CAN Bus Monitor on page 5-8
See Also
See Also
Functions
canTool
Topics
Using the Vehicle CAN Bus Monitor on page 5-8
Vehicle CAN Bus Monitor on page 5-2
Introduced in R2009a
13-126
xcpA2L
xcpA2L
Access A2L file
Syntax
a2lfile = xcpA2L(filename)
Description
a2lfile = xcpA2L(filename) creates an object that accesses an A2L file. The object
can parse the contents of the file and view events and measurement information.
Examples
Link to an A2L File
Input Arguments
filename A2L file name
character vector
A2L file name, specified as a character vector. You must provide the file ending .a2l
with the name. You can also provide a partial or full path to the file with the name.
See Also
See Also
getEventInfo | getMeasurementInfo
13-127
13 Functions Alphabetical List
Topics
Inspect the Contents of an A2L File on page 7-5
A2L File Support on page 7-2
Introduced in R2013a
13-128
getEventInfo
getEventInfo
Get event information about specific event from A2L file
Syntax
info = getEventInfo(a2lFile,eventName)
Description
info = getEventInfo(a2lFile,eventName) returns information about the specified
event from the specified A2L file, and stores it in the structure, info.
Examples
Get XCP Event Information
Create a handle to parse an A2L file and get information about the 10 ms event.
a2lfile = xcpA2L('C:\XCPSIM.a2l')
info = getEventInfo(a2lfile, '10 ms')
info =
13-129
13 Functions Alphabetical List
Input Arguments
a2lFile A2L file
xcp.A2L object
A2L file, specified as an xcp.A2L object, used in this connection. You can create an A2L
file object using xcpA2L.
XCP event name specified as a character vector. Event name corresponds to the XCP
event defined in your A2L file. Make sure the name matches the name specified in the
A2L file.
Output Arguments
info XCP event information
character vector | numeric
XCP event information returned, as character vector and numeric values, containing
event details such as timing and priority.
See Also
See Also
getMeasurementInfo | xcpA2L
Topics
Inspect the Contents of an A2L File on page 7-5
A2L File Support on page 7-2
Introduced in R2013a
13-130
getMeasurementInfo
getMeasurementInfo
Get information about specific measurement from A2L file
Syntax
info = getMeasurementInfo(a2lFile,measurementName)
Description
info = getMeasurementInfo(a2lFile,measurementName) returns information
about the specified measurement from the specified A2L file, and stores it in the
structure, info.
Examples
Get XCP Measurement Information
Create a handle to parse an A2L file and get information about the BitSlice
measurement.
a2lfile = xcpA2L('C:\XCPSIM.a2l')
info = getMeasurementInfo(a2lfile, 'PWM')
info =
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
13-131
13 Functions Alphabetical List
SizeInNibbles: 2
SizeInBits: 8
MATLABType: 'uint8'
Input Arguments
a2lFile A2L file
xcp.A2L object
A2L file, specified as an xcp.A2L object, used in this connection. You can create an A2L
file object using xcpA2L.
Output Arguments
info XCP measurement information
character vector | numeric
See Also
See Also
getEventInfo | xcpA2L
Topics
Inspect the Contents of an A2L File on page 7-5
13-132
getMeasurementInfo
Introduced in R2013a
13-133
13 Functions Alphabetical List
xcpChannel
Create XCP channel
Syntax
xcpch = xcpChannel(a2lFile,transportLayer,vendor,deviceNumber)
xcpch = xcpChannel(a2lFile,transportLayer,vendor,device,
deviceChannelIndex)
Description
xcpch = xcpChannel(a2lFile,transportLayer,vendor,deviceNumber) creates
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 character
vector '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.
Examples
Create an XCP Channel using a CAN Slave Module
Create an XCP channel using a Vector CAN modules virtual channel.
13-134
xcpChannel
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyCallbackFcn: []
KeyValue: []
Input Arguments
A2L file, specified as an xcp.A2L object, used in this connection. You can create an A2L
file object using xcpA2L.
Interface used to transport XCP messages, specified as a character vector. Use this
information to indicate the interface you are connecting to.Currently XCP works with
CAN interface only.
13-135
13 Functions Alphabetical List
Device name and defined interface number for the device, specified as a character vector.
Use this input for National Instruments CAN devices, where the devicenumber is the
interface number defined for the channel in NI Measurement & Automation Explorer.
Device on the interface you want to connect to, specified as a character vector.
Output Arguments
xcpch XCP channel that you create
XCP channel object
See Also
See Also
connect | disconnect | isConnected
Introduced in R2013a
13-136
connect
connect
Connect XCP channel to slave module
Syntax
connect(xcpch)
Description
connect(xcpch) creates an active connection between the XCP channel and the slave
module, enabling active messaging between the channel and the slave.
Examples
Connect to a Slave Module
Create an XCP channel connected to a Vector CAN device on a virtual channel and
connect it.
ans =
Input Arguments
xcpch XCP channel
XCP channel object
13-137
13 Functions Alphabetical List
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
See Also
See Also
xcpA2L | xcpChannel
Introduced in R2013a
13-138
disconnect
disconnect
Disconnect from slave module
Syntax
disconnect(xcpch)
Description
disconnect(xcpch) disconnects the specified XCP channel from the slave module.
Disconnecting the channel stops active messaging between the channel and the slave
module.
Examples
Disconnect an Active XCP Connection
Create an XCP channel using a CAN module, connect the channel and disconnect it from
the specified slave module.
Create an XCP channel using a Vector CAN moduless virtual channel. Check to see if
channel is connected.
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
ans =
13-139
13 Functions Alphabetical List
ans =
Input Arguments
xcpch XCP channel
XCP channel object
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
See Also
See Also
connect | isConnected | xcpA2L | xcpChannel
Introduced in R2013a
13-140
isConnected
isConnected
Return connection status
Syntax
isConnected(xcpch)
Description
isConnected(xcpch) returns a boolean value to indicate active connection to the slave.
Examples
Verify if XCP Channel is Connected
a2l = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1)
isConnected(xcpch)
ans =
Input Arguments
xcpch XCP channel
XCP channel object
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
13-141
13 Functions Alphabetical List
See Also
See Also
xcpChannel
Introduced in R2013a
13-142
createMeasurementList
createMeasurementList
Create measurement list for XCP channel
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.
Examples
Create a DAQ Measurement List
Create an XCP channel connected to a Vector CAN device on a virtual channel and set up
a DAQ measurement list.
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: []
13-143
13 Functions Alphabetical List
connect(xcpch)
Setup a data acquisition measurement list with the 10 ms event and 'Triangle'
measurement.
Create an XCP channel connected to a Vector CAN device on a virtual channel and set up
a STIM measurement list.
a2l = xcp.A2L('XCPSIM.a2l')
xcpch = xcp.Channel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1)
xcpch =
Channel with properties:
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.
Input Arguments
xcpch XCP channel
XCP channel object
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
13-144
createMeasurementList
Name of event, specified as a character vector. The event is used to trigger the specified
measurement list. The list of available events depends on your A2L file.
See Also
See Also
freeMeasurementLists | startMeasurement | viewMeasurementLists
Introduced in R2013a
13-145
13 Functions Alphabetical List
freeMeasurementLists
Remove all measurement lists from XCP channel
Syntax
freeMeasurementLists(xcpch)
Description
freeMeasurementLists(xcpch) removes all configured measurement lists from the
specified XCP channel.
Examples
Free DAQ Lists
Create an object to parse an A2L file and connect that to an XCP channel.
a2lfile = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
Setup a data acquisition measurement list with the '10 ms' event and 'PMW'
measurement.
createMeasurementList(xcpch, 'DAQ', '10 ms', {'BitSlice0','PWMFiltered','Triangle'})
Create another measurement list with the '100ms' event and 'PWMFiltered', and
'Triangle' measurements.
createMeasurementList(xcpch, 'DAQ', '100ms', {'PWMFiltered','Triangle'})
13-146
freeMeasurementLists
viewMeasurementLists(xcpch)
DAQ List #1 using the "10 ms" event @ 0.010000 seconds and the following measurements:
PWM
DAQ List #2 using the "100ms" event @ 0.100000 seconds and the following measurements:
PWMFiltered
Triangle
Input Arguments
xcpch XCP channel
XCP channel object
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
See Also
See Also
createMeasurementList | viewMeasurementLists | xcpA2L | xcpChannel
Introduced in R2013a
13-147
13 Functions Alphabetical List
viewMeasurementLists
View configured measurement lists on XCP channel
Syntax
viewMeasurementLists(xcpch)
Description
viewMeasurementLists(xcpch) shows you all configured measurement list sets for
this XCP channel.
Examples
View DAQ Measurement Lists
Create an XCP channel and configure a data acquisition measurement list, then view the
configured measurement list.
Create an object to parse an A2L file and connect that to an XCP channel.
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: []
13-148
viewMeasurementLists
Setup a data acquisition measurement list with the '10 ms' event and 'PMW'
measurement.
createMeasurementList(xcpch, 'DAQ', '10 ms', {'BitSlice0','PWMFiltered','Triangle'});
Create another measurement list with the '100ms' event and 'PWMFiltered'and
'Triangle' measurements.
DAQ List #1 using the "10 ms" event @ 0.010000 seconds and the following measurements:
PMW
DAQ List #2 using the "100ms" event @ 0.100000 seconds and the following measurements:
PWMFiltered
Triangle
Input Arguments
xcpch XCP channel
XCP channel object
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
See Also
See Also
createMeasurementList | freeMeasurementLists
Introduced in R2013a
13-149
13 Functions Alphabetical List
startMeasurement
Start configured DAQ and STIM lists
Syntax
startMeasurement(xcpch)
Description
startMeasurement(xcpch) starts all configured data acquisition and stimulation lists
on the specified XCP channel. When you start the measurement, configured DAQ lists
begin acquiring data values from the slave module and STIM lists begin transmitting
data values to the slave model.
Examples
Start a DAQ Measurement
Create an XCP channel connected to a Vector CAN device on a virtual channel. Set up a
DAQ measurement list and start measuring data.
a2l = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2l, 'CAN', 'Vector', 'Virtual 1', 1),
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyCallbackFcn: []
KeyValue: []
13-150
startMeasurement
Setup a data acquisition measurement list with the 10 ms event and 'Bitslice'
measurement.
createMeasurementList(xcpch, 'DAQ', '10 ms', 'BitSlice')
Create an XCP channel connected to a Vector CAN device on a virtual channel. Set up a
DAQ measurement list and start measuring data.
a2l = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2l, 'CAN', 'Vector', 'Virtual 1', 1)
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyCallbackFcn: []
KeyValue: []
Setup a data stimulation measurement list with the 100ms event and 'Bitslice0',
'PWMFiletered', and 'Triangle'measurements.
createMeasurementList(xcpch, 'STIM', '100ms', {'BitSlice0','PWMFiletered','Triangle'})
Input Arguments
xcpch XCP channel
XCP channel object
13-151
13 Functions Alphabetical List
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
See Also
See Also
stopMeasurement | xcpChannel
Introduced in R2013a
13-152
stopMeasurement
stopMeasurement
Stop configured DAQ and STIM lists
Syntax
stopMeasurement(xcpch)
Description
stopMeasurement(xcpch) stops all configured data acquisition and stimulation lists
on the specified XCP channel. When you stop the measurement, configured DAQ lists
stop acquiring data values from the slave module and STIM lists stop transmitting data
values to the slave model.
Examples
Stop a DAQ Measurement
Create an XCP channel connected to a Vector CAN device on a virtual channel. Set up a
DAQ measurement list and start and stop measuring data.
a2l = xcp2L('XCPSIM.a2l')
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1)
xcpch =
SlaveName: 'CPP'
A2LFileName: 'XCPSIM.a2l'
TransportLayer: 'CAN'
TransportLayerDevice: [1x1 struct]
SeedKeyCallbackFcn: []
KeyValue: []
13-153
13 Functions Alphabetical List
connect(xcpch)
Setup a data acquisition measurement list with the 10 ms event and 'Bitslice'
measurement and start your measurement.
createMeasurementList(xcpch, 'DAQ', '10 ms', 'BitSlice')
startMeasurement(xcpch);
Input Arguments
xcpch XCP channel
XCP channel object
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
See Also
See Also
startMeasurement | xcpChannel
Introduced in R2013a
13-154
isMeasurementRunning
isMeasurementRunning
Indicate if measurement is active
Syntax
isMeasurementRunning(xcpch)
Description
isMeasurementRunning(xcpch) returns a boolean indicating if the configured
measurements are active and running.
Examples
Verify if Configured Measurement List is Active
Set up a DAQ measurement list and start it. Verify if this list is running.
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)
13-155
13 Functions Alphabetical List
ans =
Input Arguments
xcpch XCP channel
XCP channel object
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
See Also
See Also
startMeasurement
Introduced in R2013a
13-156
readDAQListData
readDAQListData
Read single value of specified measurement
Syntax
value = readDAQListData(xcpch,measurementName)
value = readDAQListData(xcpch,measurementName,count)
Description
value = readDAQListData(xcpch,measurementName) acquires a single value for a
specified measurement, and stores it in the variable, value. If the measurement has no
data, then the function returns an empty value.
Examples
Acquire Data for Triangle Measurement in a DAQ List
Create an XCP channel connected to a Vector CAN device on a virtual channel. Set
up a DAQ measurement list and acquire data from a '100ms' events 'Triangle'
measurement.
Create an object to parse an A2L file and connect that to an XCP channel.
a2lfile = xcp.A2L('XCPSIM.a2l')
xcpch = xcp.Channel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
connect(xcpch)
13-157
13 Functions Alphabetical List
Create a measurement list with the '100ms' event and 'PMW', 'PWMFiltered', and
'Triangle' measurements.
startMeasurement(xcpch)
value =
Input Arguments
xcpch XCP channel
XCP channel object
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
Number of samples to read, specified as a numeric value, for the specified measurement
name. If number of samples in the measurement is less than the specified count, only the
available number of samples are returned.
13-158
readDAQListData
Output Arguments
value Value from specified measurement
numeric array
See Also
See Also
readSingleValue
Topics
Acquire Measurement Data via Dynamic DAQ Lists on page 8-9
Introduced in R2013a
13-159
13 Functions Alphabetical List
writeSTIMListData
Write to specified measurement
Syntax
writeSTIMListData(xcpch,measurementName,value)
Description
writeSTIMListData(xcpch,measurementName,value) writes the specified value to
the specified measurement on the XCP channel.
Examples
Write Data to a Measurement in a Stimulation list
Create an XCP channel connected to a Vector CAN device on a virtual channel. Set up
data stimulation list and write to a '100ms' events 'Triangle' measurement.
Create an object to parse an A2L file and connect that to an XCP channel.
a2lfile = xcp.A2L('XCPSIM.a2l')
xcpch = xcp.Channel(a2lfile,'CAN','Vector','Virtual 1',1);
Create a measurement list with the '100ms' event and 'Bitslice0', 'PWMFiltered',
and 'Triangle' measurements.
createMeasurementList(xcpch,'STIM','100ms',{'BitSlice0','PWMFiltered','Triangle'});
13-160
writeSTIMListData
writeSTIMListData(xcpch,'Triangle',10)
Input Arguments
xcpch XCP channel
XCP channel object
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
See Also
See Also
writeSingleValue
Introduced in R2013a
13-161
13 Functions Alphabetical List
readSingleValue
Read single sample of specified measurement from memory
Syntax
value = readSingleValue(xcpch,'measurementName')
Description
value = readSingleValue(xcpch,'measurementName') acquires a single value
for the specified measurement through the configured XCP channel and stores it in a
variable for later use. The values are read directly from memory.
Examples
Acquire a Single Value for Triangle Measurement
Create an object to parse an A2L file and connect that to an XCP channel.
a2lfile = xcpA2L('XCPSIM.a2l')
xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1);
connect(xcpch)
value =
13-162
readSingleValue
14
Input Arguments
xcpch XCP channel
XCP channel object
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
Output Arguments
value Value of the measurement
numeric value
See Also
See Also
readDAQListData
Introduced in R2013a
13-163
13 Functions Alphabetical List
writeSingleValue
Write single sample to specified measurement
Syntax
writeSingleValue(xcpch,measurementName,value)
Description
writeSingleValue(xcpch,measurementName,value) writes a single value to the
specified measurement through the configured XCP channel. The values are written
directly to the memory on the slave module.
Examples
Write a single value
Create an XCP channel and write a single value for the Triangle measurement directly
to memory.
Input Arguments
xcpch XCP channel
XCP channel object
13-164
writeSingleValue
XCP channel, specified as an XCP channel object created using xcpChannel. The XCP
channel object can then communicate with the specified slave module defined by the A2L
file.
See Also
See Also
writeSTIMListData
Introduced in R2013a
13-165
13 Functions Alphabetical List
CAN.ChannelInfo class
Package: CAN
Description
vendor.ChannelInfo(index) displays channel information for the device vendor with
the specified index. Obtain the vendor information using CAN.VendorInfo.
Input Arguments
index Device channel index
numeric value
Properties
Device
DeviceChannelIndex
DeviceSerialNumber
ObjectConstructor
13-166
CAN.ChannelInfo class
Examples
Examine Kvaser Device Channel Information
info =
ans =
See Also
See Also
Functions
can.VendorInfo | canHWInfo
13-167
13 Functions Alphabetical List
CAN.VendorInfo class
Package: CAN
Syntax
info = canHWInfo
info.VendorInfo(index)
Description
info = canHWInfo creates an object with information of all available CAN hardware
devices.
Input Arguments
index Device channel index
numeric value
Properties
VendorName
VendorDriverDescription
13-168
CAN.VendorInfo class
VendorDriverVersion
ChannelInfo
Examples
Examine Kvaser Vendor Information
info = canHWInfo
info =
info.VendorInfo
ans =
VendorName
VendorDriverDescription
VendorDriverVersion
13-169
13 Functions Alphabetical List
ChannelInfo
See Also
See Also
Functions
CAN.ChannelInfo | canHWInfo
13-170
j1939Channel
j1939Channel
Create J1939 CAN channel
Syntax
j1939Ch = j1939Channel(database,'vendor','device')
j1939Ch = j1939Channel(database,'vendor','device',chanIndex)
Description
j1939Ch = j1939Channel(database,'vendor','device') creates a J1939
channel connected to the specified CAN device. Use this syntax for National Instruments
and PEAK-System devices, which do not require a channel index argument.
Examples
Create a J1939 CAN Channel for a Vector Device
Specify a database.
db = canDatabase('C:\J1939DB.dbc');
j1939Ch =
Device Information:
-------------------
DeviceVendor: 'Vector'
Device: 'Virtual 1'
13-171
13 Functions Alphabetical List
DeviceChannelIndex: 1
DeviceSerialNumber: 0
Data Details:
-------------
ParameterGroupsAvailable: 0
ParameterGroupsReceived: 0
ParameterGroupsTransmitted: 0
FilterPassList: []
FilterBlockList: []
Channel Information:
--------------------
Running: 0
BusStatus: 'N/A'
InitializationAccess: 1
InitialTimestamp: [00 datetime]
SilentMode: 0
TransceiverName: ''
TransceiverState: 0
BusSpeed: 500000
SJW: 1
TSEG1: 4
TSEG2: 3
NumOfSamples: 1
Other Information:
------------------
UserData: []
Specify a database.
db = canDatabase('C:\J1939DB.dbc');
Input Arguments
database CAN database
CAN database object
13-172
j1939Channel
CAN database specified as a CAN database object. The specified database contains J1939
parameter group definitions.
Example: database = canDatabase('C:\database.dbc')
Name of CAN device attached to the J1939 CAN channel, specified as a character vector.
For Kvaser and Vector products, device is a combination of the device type and a device
index. For example, a Kvaser device might be 'USBcanProfessional 1'; if you have
two Vector CANcardXL devices, device can be 'CANcardXL 1' or 'CANcardXL 2'.
For National Instruments devices the devicenumber is the interface number defined in
the NI Measurement & Automation Explorer.
Channel number of the CAN device attached to the J1939 CAN channel, specified as a
numeric value. Use this argument with Kvaser and Vector devices.
Example: 1
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 |
uint32 | uint64
13-173
13 Functions Alphabetical List
Output Arguments
j1939Ch J1939 CAN channel
J1939 CAN channel object
See Also
See Also
Functions
canDatabase | j1939ParameterGroup | receive | transmit
Properties
SilentMode | TransceiverState | UserData
Topics
J1939 Channel Workflow on page 9-7
Introduced in R2015b
13-174
j1939ParameterGroup
j1939ParameterGroup
Create J1939 parameter group
Syntax
pg = j1939ParameterGroup(database, name)
Description
pg = j1939ParameterGroup(database, name) creates a parameter group using the
name defined in the specified database.
Examples
Create a Parameter Group
This example shows how to attach a database to a parameter group name and view the
signal information in the group.
db = canDatabase('C:\j1939Demo.dbc');
pg = j1939ParameterGroup(db, 'PackedData')
pg =
13-175
13 Functions Alphabetical List
SourceAddress: 50
DestinationAddress: 255
Data Details:
-------------
Timestamp: 0
Data: [255 255 255 255 255 255 255 255]
Signals: [1x1 struct]
Other Information:
------------------
UserData: []
pg.Signals
ans =
ToggleSwitch: -1
SliderSwitch: -1
RockerSwitch: -1
RepeatingStairs: 255
PushButton: 1
Input Arguments
database Handle to CAN database
character vector
Handle to CAN database, specified as a character vector. The specified database contains
J1939 parameter group definitions.
Example: db = canDatabase('C:\database.dbc')pg =
j1939ParameterGroup('db', 'pgName') assigns a handle to the database and
creates a parameter group.
Parameter group name, specified as a character vector. The name must match the name
specified in the attached CAN database.
13-176
j1939ParameterGroup
See Also
See Also
Functions
canDatabase | j1939Channel
Properties
DestinationAddress | PDUFormatType | Priority | Signals | SourceAddress |
UserData
Topics
J1939 Interface on page 9-2
J1939 Parameter Group Format on page 9-3
Introduced in R2015b
13-177
14
AttributeInfo
Information on CAN database attributes
Description
The Attributeinfo property is a structure with information about all attributes
defined in the specified CAN database.
Characteristics
Usage CAN database
Read only Always
Data type Structure
Values
The AttributeInfo property is a read-only structure. Use indexing to access the
information of each attribute.
Examples
Display Database Attribute Information
db = canDatabase('J1939DB.dbc');
db.AttributeInfo
db.AttributeInfo(1).Name
14-2
AttributeInfo
BusType
db.AttributeInfo(1).Value
CAN
See Also
See Also
Functions
attributeInfo | canDatabase
Properties
Attributes
14-3
14 Properties Alphabetical List
Attributes
Attribute names from CAN database
Description
The Attributes property stores the names of all attributes defined in the specified CAN
database.
Characteristics
Usage CAN database
Read only Always
Data type Cell array of character vectors
Values
The Attributes property displays a cell array of character vectors. You cannot edit this
property.
Examples
'BusType'
'DatabaseVersion'
'ProtocolType'
db.Attributes{1}
BusType
14-4
Attributes
See Also
See Also
Functions
attributeInfo | canDatabase
Properties
AttributeInfo
14-5
14 Properties Alphabetical List
BusLoad
Load on CAN bus
Description
The BusLoad property displays information about the load on the CAN network for
message traffic on Kvaser devices.
Characteristics
Usage CAN channel
Read only Always
Data type Float
Values
The current message traffic on a CAN network is represented as a percentage ranging
from 0.00% to 100.00%.
See Also
Functions
canChannel
14-6
BusSpeed
BusSpeed
Bit rate of bus
Description
The BusSpeed property indicates the speed at which messages are transmitted in bits
per second. You can set BusSpeed to an acceptable bit rate using the configBusSpeed
function.
Characteristics
Values
The default value is assigned by the vendor driver. To change the bus speed of your
channel, use the configBusSpeed function with the channel name and the value as
input parameters.
Examples
Change the bus speed of the CAN channel object canch to 250,000 bits per second, and
view the result.
configBusSpeed(canch,250000);
bs = canch.BusSpeed
14-7
14 Properties Alphabetical List
See Also
Functions
canChannel, j1939Channel, configBusSpeed
Properties
NumOfSamples, SJW, TSEG1, TSEG2
14-8
BusStatus
BusStatus
Determine status of bus
Description
The BusStatus property displays information about the state of the CAN or the J1939
bus.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Character vector
Values
N/A
BusOff
ErrorOff
ErrorActive
See Also
Functions
canChannel, j1939Channel
14-9
14 Properties Alphabetical List
Data
CAN message or J1939 parameter group data
Description
Use the Data property to define your message data in a CAN message or parameter
group data in a J1939 parameter group.
Characteristics
Usage CAN message, J1939 parameter group
Read only Never
Data type Numeric
Values
The data value is a uint8 array, based on the data length you specify in the message.
Examples
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.
14-10
Data
See Also
Functions
canMessage, pack
14-11
14 Properties Alphabetical List
Database
Store CAN database information
Description
The Database property stores information about an attached CAN database.
Characteristics
Usage CAN channel, CAN message
Read only For a CAN message property
Data type Database handle
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')
Tip: CAN database file names containing non-alphanumeric characters such as equal
signs and ampersands are incompatible with Vehicle Network Toolbox. You can use
14-12
Database
a period sign in your database name. Rename any CAN database files with non-
alphanumeric characters before you use them.
See Also
Functions
attachDatabase, canChannel, canDatabase, canMessage
14-13
14 Properties Alphabetical List
DestinationAddress
Address of parameter group destination
Description
Address of the J1939 parameter group destination. DestinationAddress identifies the
parameter group source on the J1939 network. The source uses the specified destination
address to send parameter groups.
Characteristics
Usage J1939 parameter group
Read only Never
Data type Numeric
Values
Specify DestinationAddress of the parameter group as a number from 0 through 253.
254 is a null value and is used by your application to detect available addresses on the
J1939 network. To send a parameter group to all devices on the network, use 255, which
is the global value.
See Also
Functions
j1939ParameterGroup
14-14
Device
Device
Display channel device type
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 or J1939 channel is connected.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Character vector
Values
Values are automatically defined when you configure the channel with the canChannel
or the j1939Channel function.
See Also
Functions
canChannel, canHWInfo, j1939Channel
Properties
DeviceChannelIndex, DeviceSerialNumber, DeviceVendor
14-15
14 Properties Alphabetical List
Device(NI)
Display NI CAN channel device type
Description
For National Instruments devices, the DeviceType property displays information about
the device type to which the CAN channel is connected.
Characteristics
Usage CAN channel
Read only Always
Data type Character vector
Values
Values are automatically defined when you configure the channel with the canChannel
function.
See Also
Functions
canChannel, canHWInfo
Properties
DeviceChannelIndex, DeviceVendor
14-16
DeviceChannelIndex
DeviceChannelIndex
Display device channel index
Description
The DeviceChannelIndex property displays the channel index on which the selected
CAN or J1939 channel is configured.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Numeric
Values
Values are automatically defined when you configure the channel with the canChannel
function.
See Also
Functions
canChannel, canHWInfo, j1939Channel
Properties
Device, DeviceVendor
14-17
14 Properties Alphabetical List
DeviceSerialNumber
Display device serial number
Description
The DeviceSerialNumber property displays the serial number of the device connected
to the CAN or J1939 channel.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Numeric
Hexadecimal character vector (NI CAN devices only)
Values
Values are automatically defined when you configure the channel with the canChannel
function.
See Also
Functions
canChannel, canHWInfo, j1939Channel
Properties
Device, DeviceVendor
14-18
DeviceVendor
DeviceVendor
Display device vendor name
Description
The DeviceVendor property displays the name of the device vendor.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Character vector
Values
Values are automatically defined when you configure the channel with the canChannel
or j1939Channel function.
See Also
Functions
canChannel, canHWInfo, j1939Channel
Properties
Device, DeviceChannelIndex, DeviceSerialNumber
14-19
14 Properties Alphabetical List
Error
CAN message error frame
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.
Characteristics
Usage CAN message
Read only Always
Data type Boolean
Values
false The message is not an error frame.
true The message is an error frame.
The Error property displays false, unless the message is an error frame.
See Also
Functions
canMessage
14-20
Extended
Extended
Identifier type for CAN message
Description
The Extended property is the identifier type for a CAN message. It can either be a
standard identifier or an extended identifier.
Characteristics
Usage CAN message
Read only Always
Data type Boolean
Values
false The identifier type is standard (11 bits).
true The identifier type is extended (29 bits).
Examples
To set the message identifier type to extended with the ID set to 2350 and the data
length to eight bytes, type:
message = canMessage(2350, true, 8)
See Also
Functions
canMessage
14-21
14 Properties Alphabetical List
Properties
ID
14-22
FilterBlockList
FilterBlockList
List of parameter groups to block
Description
FilterBlockList displays a list of parameter group names and numbers blocked by
the channel.
Characteristics
Usage J1939 channel
Read only Always
Data type Character vector, Cell array
Values
The list displays parameter group names and numbers as character vectors or cell
arrays of character vectors and numbers. To change the values, use one of the filtering
functions.
See Also
Functions
j1939Channel, filterAllowOnly, filterAllowAll, filterBlockAll
Properties
FilterPassList
14-23
14 Properties Alphabetical List
FilterPassList
List of parameter groups to pass
Description
FilterPassList displays a list of parameter group names and numbers that the
channel can pass to the network.
Characteristics
Usage J1939 channel
Read only Always
Data type Character vector, Cell array
Values
The list displays parameter group names and numbers as character vectors or cell
arrays of character vectors and numbers. To change the values, use one of the filtering
functions.
See Also
Functions
j1939Channel, filterAllowOnly, filterAllowAll, filterBlockAll
Properties
FilterBlockList
14-24
ID
ID
Identifier for CAN message
Description
The ID property represents a numeric identifier for a CAN message.
Characteristics
Usage CAN message
Read only Always
Data type Numeric
Values
The ID value must be a positive integer from:
You can also specify a hexadecimal value using the hex2dec function.
Examples
To configure a message ID to a standard identifier of value 300 and a data length of eight
bytes, type:
message = canMessage(300, false, 8)
See Also
Functions
canMessage
14-25
14 Properties Alphabetical List
Properties
Extended
14-26
InitialTimestamp
InitialTimestamp
Indicate when channel started
Description
The InitialTimestamp property indicates when the channel was set online with the
start function or when its start trigger was received. For National Instruments devices,
the time is obtained from the device driver; for devices from other vendors the time is
obtained from the operating system where MATLAB is running.
Characteristics
Usage CAN channel
Read only Always
Data type Datetime
Examples
canch = canChannel('Vector','CANCaseXL 1',1)
start(canch);
StrtTime = canch.InitialTimestamp
See Also
See Also
Functions
canChannel | start
Properties
StartTriggerTerminal
14-27
14 Properties Alphabetical List
Introduced in R2016a
14-28
InitializationAccess
InitializationAccess
Determine control of device channel
Description
The InitializationAccess property determines if the configured CAN or J1939
channel object has full control of the device channel. You can change some property
values of the hardware channel only if the object has full control over the hardware
channel.
Note: Only the first channel created on a device is granted initialization access.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Boolean
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.
See Also
Functions
canChannel
14-29
14 Properties Alphabetical List
MessageInfo
Information on CAN database messages
Description
The MessageInfo property is a structure with information about all messages defined in
the specified CAN database.
Characteristics
Usage CAN database
Read only Always
Data type Structure
Values
The MessageInfo property is a read-only structure. Use indexing to access the
information of each message.
Examples
14-30
MessageInfo
Signals
SignalInfo
TxNodes
Attributes
AttributeInfo
db.MessageInfo(1).Name
A1
db.MessageInfo(1).Signals
'EngBlowerBypassValvePos'
'EngGasSupplyPress'
See Also
See Also
Functions
canDatabase | messageInfo | signalInfo | valueTableText
Properties
Messages | SignalInfo | Signals
14-31
14 Properties Alphabetical List
MessageReceivedFcn
Specify function to run
Description
Configure MessageReceivedFcn as a callback function to run a character vector
expression, a function handle, or a cell array when a specified number of messages are
available.
Characteristics
Usage CAN channel
Read only Never
Data type Callback function
Values
The default value is an empty character vector. You can specify the name of a callback
function that you want to run when the specified number of messages are available.
Examples
Specify Callback
canch.MessageReceivedFcn = @Myfunction;
14-32
MessageReceivedFcn
See Also
See Also
Functions
canChannel
Properties
MessageReceivedFcnCount | MessagesAvailable
Topics
CAN Message Reception Callback Functions
14-33
14 Properties Alphabetical List
MessageReceivedFcnCount
Specify number of messages available before function is triggered
Description
Configure MessageReceivedFcnCount to the number of messages that must be
available before a MessageReceivedFcn is triggered.
Characteristics
Values
The default value is 1. You can specify a positive integer for your
MessageReceivedFcnCount.
Examples
Specify Message Count
canch.MessageReceivedFcnCount = 55;
14-34
MessageReceivedFcnCount
See Also
See Also
Functions
canChannel
Properties
MessageReceivedFcn | MessagesAvailable
Topics
CAN Message Reception Callback Functions
14-35
14 Properties Alphabetical List
Messages
Message names from CAN database
Description
The Messages property stores the names of all messages defined in the specified CAN
database.
Characteristics
Usage CAN database
Read only Always
Data type Cell array of character vectors
Values
The Messages property displays a cell array of character vectors. You cannot edit this
property.
Examples
'A1'
'A1DEFI'
'A1DEFSI'
db.Messages{1}
A1
14-36
Messages
See Also
See Also
Functions
canDatabase | messageInfo | signalInfo | valueTableText
Properties
MessageInfo | SignalInfo | Signals
14-37
14 Properties Alphabetical List
MessagesAvailable
Display number of messages available to be received by CAN channel
Description
The MessagesAvailable property displays the total number of messages available to
be received by a CAN channel.
Characteristics
Usage CAN channel
Read only Always
Data type Double
Values
The value is 0 when no messages are available.
See Also
Functions
canChannel
Properties
MessagesReceived, MessagesTransmitted
14-38
MessagesReceived
MessagesReceived
Display number of messages received by CAN channel
Description
The MessagesReceived property displays the total number of messages received since
the channel was last started.
Characteristics
Usage CAN channel
Read only Always
Data type Double
Values
The value is 0 when no messages have been received. This number increments based on
the number of messages the channel receives.
See Also
Functions
canChannel, canHWInfo
Properties
MessagesAvailable, MessagesTransmitted
14-39
14 Properties Alphabetical List
MessagesTransmitted
Display number of messages transmitted by CAN channel
Description
The MessagesTransmitted property displays the total number of messages
transmitted since the channel was last started.
Characteristics
Usage CAN channel
Read only Always
Data type Double
Values
The default is 0 when no messages have been sent. This number increments based on the
number of messages the channel transmits.
See Also
Functions
canChannel
Properties
MessagesAvailable, MessagesReceived
14-40
Name (Database)
Name (Database)
CAN database name
Description
The Name (Database) property displays the name of the database.
Characteristics
Usage CAN database
Read only Always
Data type Character vector
Values
Name is a character vector value. This value is acquired from the name of the database
file. You cannot edit this property.
See Also
Functions
canDatabase
Properties
Extended, ID
14-41
14 Properties Alphabetical List
Name (CAN)
CAN message name
Description
The Name (Message) property displays the name of the message.
Characteristics
Usage CAN message
Read only Always
Data type Character vector
Values
Name is a character vector 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.
See Also
Functions
canMessage
Properties
Extended, ID
14-42
Name (J1939)
Name (J1939)
J1939 parameter group name
Description
The Name property displays the name of the J1939 parameter group.
Characteristics
Usage J1939 parameter group
Read only Never
Data type Character vector
Values
Name is a character vector value. This value is acquired from the name you define when
you create the parameter group.
See Also
Functions
j1939ParameterGroup
14-43
14 Properties Alphabetical List
NodeInfo
Information on CAN database nodes
Description
The NodeInfo property is a structure with information about all nodes defined in the
specified CAN database.
Characteristics
Usage CAN database
Read only Always
Data type Structure
Values
The NodeInfo property is a read-only structure. Use indexing to access the information
of each node.
Examples
db.NodeInfo(1).Name
14-44
NodeInfo
AerodynamicControl
See Also
See Also
Functions
canDatabase | nodeInfo
Properties
Nodes
14-45
14 Properties Alphabetical List
Nodes
Node names from CAN database
Description
The Nodes property stores the names of all nodes defined in the specified CAN database.
Characteristics
Usage CAN database
Read only Always
Data type Cell array of character vectors
Values
The Nodes property displays a cell array of character vectors. You cannot edit this
property.
Examples
'AerodynamicControl'
'Aftertreatment_1_GasIntake'
'Aftertreatment_1_GasOutlet'
db.Nodes{1}
AerodynamicControl
14-46
Nodes
See Also
See Also
Functions
canDatabase | nodeInfo
Properties
NodeInfo
14-47
14 Properties Alphabetical List
NumOfSamples
Display number of samples available to channel
Description
The NumOfSamples property displays the total number of samples available to this
channel. If you do not specify a value, the BusSpeed property determines the default
value.
Note: This property is not available for National Instruments CAN devices. The channel
displays NaN for the value.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Double
Values
The value is a positive integer based on the driver settings for the channel.
See Also
Functions
canChannel, j1939ChannelconfigBusSpeed
Properties
BusSpeed, SJW, TSEG1, TSEG2
14-48
OnboardTermination
OnboardTermination
Configure bus termination on device
Description
The OnboardTermination property specifies the device to use its onboard termination
of the CAN bus. For more information on the behavior and characteristics of a specific
device, refer to its vendors documentation.
Characteristics
Usage NI-XNET CAN channel
Read only When online
Data type Logical
Examples
canch = canChannel('NI','CAN1');
canch.OnboardTermination = true
See Also
Functions
canChannel
Introduced in R2016a
14-49
14 Properties Alphabetical List
ParameterGroupsAvailable
Number of parameter groups available
Description
ParameterGroupsAvailable displays the total number of parameter groups available
to the channel.
Characteristics
Usage J1939 channel
Read only Always
Data type Double
Values
The property displays the number of available parameters to the channel.
See Also
Functions
j1939Channel
Properties
ParameterGroupsReceived, ParameterGroupsTransmitted
14-50
ParameterGroupsReceived
ParameterGroupsReceived
Number of parameter groups received
Description
ParameterGroupsTransmitted displays the total number of parameter groups
transmitted since the channel was started.
Characteristics
Usage J1939 channel
Read only Always
Data type Double
Values
The property displays the number of received parameters through the channel.
See Also
Functions
j1939Channel
Properties
ParameterGroupsTransmitted, ParameterGroupsAvailable
14-51
14 Properties Alphabetical List
ParameterGroupsTransmitted
Number of parameter groups transmitted
Description
ParameterGroupsTransmitted displays the total number of parameter groups
transmitted since the channel was started.
Characteristics
Usage J1939 channel
Read only Always
Data type Double
Values
The property displays the number of transmitted parameter through the channel.
See Also
Functions
j1939Channel
Properties
ParameterGroupsReceived, ParameterGroupsAvailable
14-52
Path
Path
CAN database folder path
Description
The Path property displays the path to the CAN database.
Characteristics
Usage CAN database
Read only Always
Data type Character vector
Values
The path name is a character vector value, pointing to the CAN database in your folder
structure.
See Also
Functions
canDatabase
14-53
14 Properties Alphabetical List
PDUFormatType
J1939 parameter group PDU format
Description
The PDUFormatType property displays the J1939 protocol data unit format of the
parameter group.
Characteristics
Usage J1939 parameter group
Read only Always
Data type Character vector
Values
PDUFormatType is displayed as a character vector. This value is automatically assigned
when you create the parameter group.
See Also
Functions
j1939ParameterGroup
14-54
PGN
PGN
J1939 parameter group number
Description
The PGN property displays the number of the parameter group.
Characteristics
Usage J1939 parameter group
Read only Never
Data type Number
Values
PGN is represented as a number. This value is automatically assigned when you create
the parameter group.
See Also
Functions
j1939ParameterGroup
14-55
14 Properties Alphabetical List
Priority
Priority of parameter group
Description
The Priority property specifies the precedence of the parameter group on the J1939
network.
Values
Priority takes a numeric value of 0 to 7, which specifies the order of importance of the
parameter group.
See Also
Functions
j1939ParameterGroup
Characteristics
Usage J1939 parameter group
Read only Never
Data type Numeric
14-56
ReceiveErrorCount
ReceiveErrorCount
Display number of received errors detected by channel
Description
The ReceiveErrorCount property displays the total number of errors detected by this
channel during receive operations.
Characteristics
Usage CAN channel
Read only Always
Data type Double
Values
The value is 0 when no error messages have been received.
See Also
Functions
canChannel, receive
Properties
TransmitErrorCount
14-57
14 Properties Alphabetical List
Remote
Specify CAN message remote frame
Description
Use the Remote property to specify the CAN message as a remote frame.
Characteristics
Usage CAN message
Read only Never
Data type Boolean
Values
{false} The message is not a remote frame.
true The message is a remote frame.
Examples
To change the default value of Remote and make the message a remote frame, type:
message.Remote = true
See Also
Functions
canMessage
14-58
Running
Running
Determine status of channel
Description
The Running property displays information about the state of the CAN or J1939
channel.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Boolean
Values
{false} The channel is offline.
true The channel is online.
See Also
Functions
canChannel, j1939Channel, start
14-59
14 Properties Alphabetical List
SilentMode
Specify if channel is active or silent
Description
Specify whether the channel operates silently. By default SilentMode is false. In this
mode, the channel both transmits and receives 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, change SilentMode to true. In this mode, you can only
receive messages and not transmit any.
Characteristics
Usage CAN channel, J1939 CAN channel
Read only Never
Data type Boolean
Values
{false} The channel is in normal or active mode.
true The channel is in silent mode.
Examples
To configure the channel to silent mode, type:
canch.SilentMode = true
canch.SilentMode = false
14-60
SilentMode
See Also
Functions
canChannelj1939Channel
14-61
14 Properties Alphabetical List
SignalInfo
Information on CAN database message signals
Description
The SignalInfo property is a structure with information about all signals defined in
the specified CAN database message.
Characteristics
Usage CAN database
Read only Always
Data type Structure
Values
The SignalInfo property is a read-only structure. Use indexing to access the
information of each signal.
Examples
Display Database Signal Information
db = canDatabase('J1939DB.dbc');
db.MessageInfo
14-62
SignalInfo
SignalInfo
TxNodes
Attributes
AttributeInfo
s = db.MessageInfo(1).SignalInfo
s(2).Name
EngGasSupplyPress
See Also
See Also
Functions
canDatabase | messageInfo | signalInfo
Properties
MessageInfo | Messages | Signals
14-63
14 Properties Alphabetical List
Signals
Physical signals defined in CAN message or J1939 parameter group
Description
The Signals property allows you to view and edit signal values defined for a CAN
message or a J1939 parameter group. This property displays an empty structure if
the message has no defined signals or a database is not attached to the message or
parameter group. The input values for this property depends on the signal type.
Characteristics
Usage CAN message, J1939 parameter group
Read only Sometimes
Data type Structure
Examples
message = canMessage(canDb,'messageName');
message.Signals
VehicleSpeed: 0
EngineRPM: 250
message.Signals.EngineRPM = 300
14-64
Signals
ToggleSwitch: -1
SliderSwitch: -1
RockerSwitch: -1
RepeatingStairs: 255
PushButton: 1
ToggleSwitch: -1
SliderSwitch: -1
RockerSwitch: -1
RepeatingStairs: 200
PushButton: 1
See Also
See Also
Functions
canDatabase | canMessage | j1939ParameterGroup | messageInfo | signalInfo
Properties
MessageInfo | Messages | SignalInfo
14-65
14 Properties Alphabetical List
SJW
Synchronization jump width (SJW) of bit time segment
Description
SJW displays the synchronization jump width of the bit time segment. To adjust the on-
chip bus clock, the 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.
Note: This property is not available for National Instruments CAN devices. The channel
displays NaN for the value.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Numeric
Values
The value of the SJW is determined by the specified bus speed.
See Also
Functions
canChannel, j1939Channel, configBusSpeed
Properties
BusSpeed, NumOfSamples, TSEG1, TSEG2
14-66
SourceAddress
SourceAddress
Address of parameter group source
Description
Address of the J1939 parameter group source. SourceAddress identifies the parameter
group source on the J1939 network. This allows the destinations to identify the sender
and respond appropriately.
Characteristics
Usage J1939 parameter group
Read only Never
Data type Numeric
Values
Specify SourceAddress of the parameter group as a number between 0 and 253. 254 is
a null value and is used by your application to detect available addresses on the J1939
network. To send a parameter group to all devices on the network, use 255, which is the
global value.
See Also
Functions
j1939ParameterGroup
14-67
14 Properties Alphabetical List
StartTriggerTerminal
Specify start trigger source terminal
Description
The StartTriggerTerminal property specifies a synchronization trigger connection to
start the NI-XNET channel on the connected source terminal.
Note This property can be configured only once. After it is assigned, the property is
read-only and cannot be changed. The only way to set a different value is to clear the
channel object, recreate the channel with canChannel, and configure its properties.
Characteristics
Usage NI-XNET CAN channel
Read only After assigned
Data type Character vector
Examples
Configure a NI-XNET CAN module start trigger on terminal /cDAQ3/PFI0.
ch1 = canChannel('NI','CAN1')
ch1.StartTriggerTerminal = '/cDAQ3/PFI0'
start(ch1) % Acquisition begins on hardware trigger
14-68
StartTriggerTerminal
ch1.InitialTimestamp
messages = receive(ch1,Inf);
messages(1).Timestamp
See Also
See Also
Functions
canChannel
Properties
InitialTimestamp
Introduced in R2016a
14-69
14 Properties Alphabetical List
Timestamp (CAN)
Display message received timestamp
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.
Characteristics
Usage CAN message
Read only Never
Data type Double
Values
Timestamp displays a numeric value indicating the time the message was received,
based on the start time of the CAN channel
Examples
To set the time stamp of a message to 12, type:
message.Timestamp = 12
See Also
Functions
canChannel, canMessage, receive, replay
14-70
Timestamp (J1939)
Timestamp (J1939)
Display parameter received timestamp
Description
The Timestamp property displays the time at which the parameter group was received
on a J1939 channel. This time is based on the hardware log.
Characteristics
Usage J1939 parameter group
Read only Never
Data type Double
Values
Timestamp displays a numeric value indicating the time the parameter group was
received, based on the logged time on the hardware.
See Also
Functions
j1939ParameterGroup
14-71
14 Properties Alphabetical List
TransceiverName
Name of device transceiver
Description
TransceiverName displays the name of the device transceiver. The device transceiver
translates the digital bit stream going to and coming from the bus into the real electrical
signals present on the bus.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Character vector
Values
Values are automatically defined when you configure the channel with the canChannel
or the j1939Channel function.
See Also
Functions
canChannel, j1939Channel
Properties
TransceiverState
14-72
TransceiverState
TransceiverState
Display state or mode of transceiver
Description
If your CAN or J1939 transceiver allows you to control its mode, you can use the
TransceiverState property to set the mode.
Characteristics
Usage CAN channel, J1939 CAN channel
Read only Never
Data type Numeric
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
See Also
Functions
canChannel
14-73
14 Properties Alphabetical List
Properties
TransceiverName
14-74
TransmitErrorCount
TransmitErrorCount
Display number of transmitted errors by channel
Description
The TransmitErrorCount property displays the total number of errors detected by this
channel during transmit operations.
Characteristics
Usage CAN channel
Read only Always
Data type Double
Values
The value is 0 when no error messages have been transmitted.
See Also
Functions
canChannel, transmit
Properties
ReceiveErrorCount
14-75
14 Properties Alphabetical List
TSEG1
Display amount that channel can lengthen sample time
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.
Note: This property is not available for National Instruments CAN devices. The channel
displays NaN for the value.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Double
Values
The value is inherited when you configure the bus speed of your CAN channel.
See Also
Functions
canChannel, j1939Channel, configBusSpeed
Properties
BusSpeed, NumOfSamples, SJW, TSEG2
14-76
TSEG2
TSEG2
Display amount that channel can shorten sample time
Description
The TSEG2 property displays the number of bit time segments the channel can shorten
the sample to resynchronize.
Note: This property is not available for National Instruments CAN devices. The channel
displays NaN for the value.
Characteristics
Usage CAN channel, J1939 channel
Read only Always
Data type Double
Values
The value is inherited when you configure the bus speed of your CAN channel.
See Also
Functions
canChannel, j1939Channel, configBusSpeed
Properties
BusSpeed, NumOfSamples, SJW, TSEG1
14-77
14 Properties Alphabetical List
UserData
Enter custom data
Description
Enter custom data to be stored in your CAN message or a J1939 parameter group,
channel, or database object using the UserData property. 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.
Characteristics
Usage CAN channel, J1939 channel, CAN message, J1939 parameter
group, CAN database
Read only Never
Data type User defined
See Also
Functions
canChannel, canMessage, canDatabase, j1939ParameterGroup, j1939Channel
14-78
Events
Events
Display A2L events list
Description
The Events property displays events available in the selected A2L description file. This
property contains a cell array of character vectors that correspond to the names of events
in the A2L file. To use the A2L file events, see Access Event Information on page 7-4.
14-79
14 Properties Alphabetical List
Measurements
Display A2L measurements list
Description
The Measurements property displays measurements available in the selected A2L
description file. This property contains a cell array of character vectors that correspond
to the names of measurements in the A2L file. To use the A2L file measurements see
Access Measurement Information on page 7-5.
14-80
DAQInfo
DAQInfo
Data acquisition information in A2L file
Description
The DAQInfo property displays data acquisition information in the A2L description file.
This property contains a structure with values corresponding to the DAQ features in the
slave.
14-81
14 Properties Alphabetical List
SlaveName
Name of connected slave
Description
The SlaveName property displays the name of the slave node as specified in the A2L file.
The name is specified as a character vector.
14-82
FileName
FileName
Name of referenced A2L file
Description
The FileName property displays the name of the referenced A2L file as a character
vector.
14-83
14 Properties Alphabetical List
FilePath
Path of A2L file
Description
The FileName property displays the full file path to the A2L file as a character vector.
14-84
ProtocolLayerInfo
ProtocolLayerInfo
Protocol layer information
Description
The ProtocolLayerInfo property displays a structure containing general information
about the XCP protocol implementation of the slave as defined in the A2L file.
14-85
14 Properties Alphabetical List
TransportLayerCANInfo
CAN transport layer information
Description
The TransportLayerCANInfo property displays a structure containing general
information about the CAN transport layer for the XCP connection to the slave as defined
in the A2L file.
14-86
A2LFileName
A2LFileName
Name of the A2L file
Description
The A2LFileName property displays the name of the A2L file contains information
about the slave that an XCP channel can access.
14-87
14 Properties Alphabetical List
SeedKeyDLL
Name of seed and key security access dll
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.
14-88
TransportLayer
TransportLayer
Transport layer type
Description
The TransportLayer property displays the type of transport layer used in the XCP
connection.
14-89
14 Properties Alphabetical List
TransportLayerDevice
XCP transport layer connection
Description
The TransportLayerDevice property contains a structure with XCP transport layer
connection details, including information about the device through which the channel
communicates with the slave.
14-90
15
Block Reference
CAN Configuration
CAN Log
CAN Pack
CAN Receive
CAN Replay
CAN Transmit
CAN Unpack
J1939 CAN Transport Layer
J1939 Network Configuration
J1939 Node Configuration
J1939 Receive
J1939 Transmit
XCP Configuration
XCP Data Acquisition
XCP Data Stimulation
XCP CAN Transport Layer
XCP CAN TL Receive
XCP CAN TL Transmit
15 Block Reference
CAN Configuration
Configure parameters for specified CAN device
Library
Vehicle Network Toolbox: CAN Communication
Description
The CAN Configuration block configures parameters for a CAN device that you can use
to transmit and receive messages.
Specify the configuration of your CAN device before you configure other CAN blocks.
Use one CAN Configuration block to configure each device that sends and receives
messages in your model. If you use a CAN Receive or a CAN Transmit block to receive
and send messages on a device, your model checks to see if there is a corresponding CAN
Configuration block for the specified device. If the device is not configured, you will see a
prompt advising you to use a CAN Configuration block to configure the specified device.
Note: You need a license for both Vehicle Network Toolbox and Simulink software to use
this block.
15-2
CAN Configuration
The CAN Configuration block supports the use of code generation when you use it with
the CAN Receive and CAN Transmit blocks.
Parameters
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 BusSpeed property for the selected device, in bits per second. The default bus
speed is the default assigned by the selected device.
Enable bit parameters manually
Select this check box to specify bit parameter settings manually. The bit parameter
settings include:
Tip: Use the default bit parameter settings unless you have specific timing
requirements for your CAN connection.
15-3
15 Block Reference
Specify the amount of bit time segments that the channel can lengthen the sample
time. 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 TSEG1 property
for more information.
Time segment 2
Specify the amount of bit time segments that the channel can shorten the sample
time to resynchronize. 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 TSEG2 property for more information.
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.
15-4
CAN Configuration
See Also
CAN Receive, CAN Transmit
Introduced in R2009a
15-5
15 Block Reference
CAN Log
Log received CAN messages
Library
Vehicle Network Toolbox: CAN Communication
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.
Note: If your model uses a National Instruments device, you cannot connect CAN
Receive block and CAN Log to the same channel on the device.
You cannot connect a channel on a National Instruments device to more than one block.
Configure your CAN Log block to log from the Simulink input port. Refer to the Basic
CAN Message Replay and Logging example for more information.
The Log block appends the specified filename with the current date and time, creating
unique log files for repeated logging.
If you want to use messages logged using Simulink blocks in the MATLAB Command
window, use canMessage to convert messages to the correct format. 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.
15-6
CAN Log
The CAN Log 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 on page 15-7.
Code Generation
Vehicle Network Toolbox Simulink blocks allow you to generate code, enabling models
containing these blocks to run in Accelerator, Rapid Accelerator, External, and Deployed
modes.
To set up packNGo:
set_param(gcs,'PostCodeGenCommand','packNGo(buildInfo)');
In this example, gcs is the current model that you want to build. Building the model
creates a zip file with the same name as model name. You can move this zip file to
15-7
15 Block Reference
another machine and there build the source code in the zip file to create an executable
which can run independent of MATLAB and Simulink. The generated code compiles with
both C and C++ compilers. For more information, see Build Process Customization
(Simulink Coder).
Parameters
Tip: If you are logging from the network, you need to configure your CAN channel with a
CAN Configuration block.
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.
Maximum number of messages to log
Specify the maximum number of messages this block can log from the selected device
or port. The specified value must be a positive integer. If you do not specify a value
the block uses the default value of 10,000 messages. The log file saves the most
recent messages up to the specified maximum number.
Log messages from
Select the source of the messages logged by the block. Possible values are CAN Bus or
Input port. To log messages from the network, you must specify a device.
Device
Select the device on the CAN network that you want to log messages from. This filed
is unavailable if you select Input port for Log messages from 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 Log block runs during simulation. If the block is inside a triggered
15-8
CAN Log
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).
See Also
CAN Replay
Introduced in R2011b
15-9
15 Block Reference
CAN Pack
Pack individual signals into CAN message
Library
CAN Communication
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.
The use of Simulink Accelerator Rapid Accelerator mode. Using this feature, you can
speed up the execution of Simulink models.
The use of model referencing. Using this feature, your model can include other
Simulink models as modular components.
15-10
CAN Pack
Note: Code generation is not supported if your signal information consists of signed or
unsigned integers greater than 32-bits long.
Dialog Box
Use the Function Block Parameters dialog box to select your CAN Pack 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 parameter fields are unavailable. This
option opens only one input port on your block.
manually specified signals: Allows you to specify data signal definitions. If you
select this option, use the Signals table to create your signals. The number of
block inputs depends on the number of signals you specify.
CANdb specified signals: Allows you to specify a CAN database file that
contains message and signal definitions. If you select this option, select a CANdb
file. The number of block inputs depends on the number of signals specified in the
CANdb file for the selected message.
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.
Note: File names that contain non-alphanumeric characters such as equal signs,
ampersands, and so forth are not valid CAN database file names. You can use
15-11
15 Block Reference
periods in your database name. Rename CAN database files with non-alphanumeric
characters before you use them.
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.
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.
15-12
CAN Pack
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 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.
15-13
15 Block Reference
Little-Endian Byte Order Counted from the Least Significant Bit to the Highest Address
BE: Where byte order is in big-endian format (Motorola). In this format you count
bits from the start, which is the least significant bit, to the most significant bit.
For example, if you pack one byte of data in big-endian format, with the start bit
at 20, the data bit table resembles this figure.
15-14
CAN Pack
Big-Endian Byte Order Counted from the Least Significant Bit to the Lowest Address
Data type
Specify how the signal interprets the data in the allocated bits. Choose from:
signed (default)
unsigned
single
double
Multiplex type
Specify how the block packs the signals into the CAN message at each timestep:
15-15
15 Block Reference
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.
If the value of Signal-D is not 1 or 0, the block does not pack either of the
Multiplexed signals in that timestep.
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 pack the Multiplexed signal. The Multiplex
value must be a positive integer or zero.
Factor
Specify the Factor value to apply to convert the physical value (signal value) to the
raw value packed in the message. See Conversion Formula on page 15-17 to
understand how physical values are converted to raw values packed into a message.
Offset
15-16
CAN Pack
Specify the Offset value to apply to convert the physical value (signal value) to the
raw value packed in the message. See Conversion Formula on page 15-17 to
understand how physical values are converted to raw values packed into a message.
Min
Specify the minimum physical 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 15-17 to understand how physical values are
converted to raw values packed into a message.
Max
Specify the maximum physical value of the signal. The default value is inf. You
can specify a number for the maximum value. See Conversion Formula on page
15-17 to understand how physical values are converted to raw values packed into
a message.
Conversion Formula
The conversion formula is
raw_value = (physical_value - Offset) / Factor
where physical_value is the value of the signal after it is saturated using the specified
Min and Max values. raw_value is the packed signal value.
See Also
CAN Unpack
Introduced in R2009a
15-17
15 Block Reference
CAN Receive
Receive CAN messages from specified CAN device
Library
Vehicle Network Toolbox: CAN Communication
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.
The f() output port is a trigger to a Function-Call subsystem. If the block receives
a new message, it triggers a Function-Call from this port. You can then connect to a
Function-Call Subsystem to unpack and process a message.
The CAN Msg output port contains a CAN message received at that particular
timestep.
The CAN Receive block stores CAN messages in a first-in, first-out (FIFO) buffer. The
FIFO buffer delivers the messages to your model in the queued order at every timestep.
Tip You cannot have more than one CAN Receive block in a model using the same NI-
XNET or PEAK-System device channel.
15-18
CAN Receive
The CAN Receive 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 on page 15-7.
Code Generation
Vehicle Network Toolbox Simulink blocks allow you to generate code, enabling models
containing these blocks to run in Accelerator, Rapid Accelerator, External, and Deployed
modes.
To set up packNGo:
set_param(gcs,'PostCodeGenCommand','packNGo(buildInfo)');
In this example, gcs is the current model that you want to build. Building the model
creates a zip file with the same name as model name. You can move this zip file to
15-19
15 Block Reference
another machine and there build the source code in the zip file to create an executable
which can run independent of MATLAB and Simulink. The generated code compiles with
both C and C++ compilers. For more information, see Build Process Customization
(Simulink Coder).
Parameters
Tip Configure your CAN Configuration block before you configure the CAN Receive block
parameters.
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 (default): Allows all standard IDs to pass the filter.
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
positive integers from 0 to 2047. You can also specify hexadecimal values with the
hex2dec function.
Block all: Blocks all standard IDs from passing the filter.
Allow all (default): Allows all extended IDs to pass the filter.
Allow only: Allows only those 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
15-20
CAN Receive
be positive integers from 0 to 536870911. You can also specify hexadecimal values
using the hex2dec function.
Block all: Blocks all extended IDs from passing the filter.
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. Valid
choices are:
all (default): 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 each delivered message. The output port always contains one
CAN message at a time.
1: The CAN Receive block delivers one message per timestep from the FIFO buffer
to the model.
If the block does not receive any messages before the next timestep, it outputs the
last received message.
See Also
CAN Configuration, CAN Unpack
Introduced in R2009a
15-21
15 Block Reference
CAN Replay
Replay logged CAN messages
Library
Vehicle Network Toolbox: CAN Communication
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 Log and Replay CAN Messages 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.
15-22
CAN Replay
The CAN Replay 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 on page 15-7.
Code Generation
Vehicle Network Toolbox Simulink blocks allow you to generate code, enabling models
containing these blocks to run in Accelerator, Rapid Accelerator, External, and Deployed
modes.
To set up packNGo:
set_param(gcs,'PostCodeGenCommand','packNGo(buildInfo)');
In this example, gcs is the current model that you want to build. Building the model
creates a zip file with the same name as model name. You can move this zip file to
15-23
15 Block Reference
another machine and there build the source code in the zip file to create an executable
which can run independent of MATLAB and Simulink. The generated code compiles with
both C and C++ compilers. For more information, see Build Process Customization
(Simulink Coder).
Parameters
Tip: Configure your CAN Configuration block before you configure the CAN Receive block
parameters.
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).
15-24
CAN Replay
See Also
See Also
Blocks
CAN Log
Functions
canMessageReplayBlockStruct
Introduced in R2011b
15-25
15 Block Reference
CAN Transmit
Transmit CAN message to selected CAN device
Library
Vehicle Network Toolbox: CAN Communication
Description
The CAN Transmit block transmits messages to the CAN network using the specified
CAN device. The CAN Transmit block can transmit a single message or an array
of messages during a given timestep. To transmit an array of messages, use a mux
(multiplex) block from the Simulink block library.
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.
15-26
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.
Code Generation
Vehicle Network Toolbox Simulink blocks allow you to generate code, enabling models
containing these blocks to run in Accelerator, Rapid Accelerator, External, and Deployed
modes.
To set up packNGo:
set_param(gcs,'PostCodeGenCommand','packNGo(buildInfo)');
In this example, gcs is the current model that you want 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 there build the source code in the zip file to create an executable
which can run independent of MATLAB and Simulink. The generated code compiles with
both C and C++ compilers. For more information, see Build Process Customization
(Simulink Coder).
15-27
15 Block Reference
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.
Message period (in seconds)
Specify a period in seconds. This value is used to transmit the message in the
specified period. By default this value is 1.000 seconds.
See Also
CAN Configuration, CAN Pack
Introduced in R2009a
15-28
CAN Unpack
CAN Unpack
Unpack individual signals from CAN messages
Library
CAN Communication
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.
The use of Simulink Accelerator Rapid Accelerator mode. Using this feature, you can
speed up the execution of Simulink models.
The use of model referencing. Using this feature, your model can include other
Simulink models as modular components.
15-29
15 Block Reference
Note: Code generation is not supported if your signal information consists of signed or
unsigned integers greater than 32-bits long.
Dialog Box
Use the Function Block Parameters dialog box to select your CAN message unpacking
parameters.
Parameters
Data to be output as
Select your data signal:
raw data: Output data as a uint8 vector array. If you select this option, you only
specify the message fields. The other signal parameter fields are unavailable. This
option opens only one output port on your block.
manually specified signals: Allows you to specify data signals. If you select this
option, use the Signals table to create your signals message manually.
The number of output ports on your block depends on the number of signals you
specify. For example, if you specify four signals, your block has four output ports.
CANdb specified signals: Allows you to specify a CAN database file that
contains data signals. If you select this option, select a CANdb file.
The number of output ports on your block depends on the number of signals
specified in the CANdb file. For example, if 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.
15-30
CAN Unpack
Note: File names that contain non-alphanumeric characters such as equal signs,
ampersands, and so forth are not valid CAN database file names. You can use
periods in your database name. Rename CAN database files with non-alphanumeric
characters before you use them.
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 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 integer from 0 through 2047
for a standard identifier and from 0 through 536870911 for an extended identifier. If
you specify 1, the block unpacks the messages that match the length specified for
the message. You can also specify hexadecimal values using the hex2dec function.
This option is available if you choose to output raw data or manually specify signals.
Length (bytes)
Specify the length of your CAN message from 0 to 8 bytes. If you are using CANdb
specified signals for your output data, the CANdb file defines the length of
your message. If not, this field defaults to 8. This option is available if you choose to
output raw data or manually specify signals.
15-31
15 Block Reference
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.
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.
15-32
CAN Unpack
Little-Endian Byte Order Counted from the Least Significant Bit to the Highest Address
BE: Where the byte order is in big-endian format (Motorola). In this format you
count bits from the start, which is the least significant bit, to the most significant
bit. For example, if you pack one byte of data in big-endian format, with the start
bit at 20, the data bit table resembles this figure.
15-33
15 Block Reference
Big-Endian Byte Order Counted from the Least Significant Bit to the Lowest Address
Data type
Specify how the signal interprets the data in the allocated bits. Choose from:
signed (default)
unsigned
single
double
Multiplex type
Specify how the block unpacks the signals from the CAN message at each timestep:
15-34
CAN Unpack
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.
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 15-37 to understand how
unpacked raw values are converted to physical values.
Offset
15-35
15 Block Reference
Specify the Offset value applied to convert the physical value (signal value) to the
unpacked raw value. See Conversion Formula on page 15-37 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 15-37 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
15-37 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.
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.
15-36
CAN Unpack
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
physical_value = raw_value * Factor + Offset
where raw_value is the unpacked signal value. physical_value is the scaled signal
value which is saturated using the specified Min and Max values.
See Also
CAN Pack
Introduced in R2009a
15-37
15 Block Reference
Library
Vehicle Network Toolbox: J1939 Communication
Description
The J1939 CAN Transport Layer block allows J1939 communication via a CAN bus.
This block associates a user-defined J1939 network configuration with a connected CAN
device. Use one block for each J1939 Network Configuration block in your model.
Note: You need a license for both Vehicle Network Toolbox and Simulink software to use
this block.
The J1939 communication blocks also support code generation with limited deployment
capabilities. Code generation requires the Microsoft C++ compiler.
Parameters
Config name
15-38
J1939 CAN Transport Layer
See Also
See Also
Blocks
J1939 Network Configuration | J1939 Node Configuration | J1939 Receive
| J1939 Transmit
Topics
Basic J1939 Communication over CAN
Introduced in R2015b
15-39
15 Block Reference
Library
Vehicle Network Toolbox: J1939 Communication
Description
The J1939 Network Configuration block is where you define a configuration name and
specify the associated user-supplied J1939 database. You can include more than one
block per model, each corresponding to a unique configuration on the CAN bus.
Note: You need a license for both Vehicle Network Toolbox and Simulink software to use
this block.
The J1939 communication blocks also support code generation with limited deployment
capabilities. Code generation requires the Microsoft C++ compiler.
Parameters
Configuration name
15-40
J1939 Network Configuration
Define a name for this J1939 network configuration. The default is ConfigX, where
the number X automatically increases from 1 based on the number of existing blocks.
Database File
Specify the J1939 database file name relative to the current folder. For example,
enter J1939.dbc if the file is in the current folder; otherwise enter the full path with
the file name, such as C:\work\J1939.dbc.
The database file defines the J1939 parameter groups and nodes, and must be in the
.dbc format defined by Vector Informatik GmbH.
See Also
See Also
Blocks
J1939 CAN Transport Layer | J1939 Node Configuration | J1939 Receive |
J1939 Transmit
Topics
Basic J1939 Communication over CAN
Introduced in R2015b
15-41
15 Block Reference
Library
Vehicle Network Toolbox: J1939 Communication
Description
The J1939 Node Configuration block is where you define a node and associate it with a
specific network configuration. Its Message information is read from the database for
that configuration, unless you are creating and configuring a custom node.
Note: You need a license for both Vehicle Network Toolbox and Simulink software to use
this block.
The J1939 communication blocks also support code generation with limited deployment
capabilities. Code generation requires the Microsoft C++ compiler.
Block Outputs
Address (optional)
15-42
J1939 Node Configuration
This output port exists when you check Output current node address in the dialog
box. It returns the effective address of the node.
AC Status (optional)
This output port exists when you check Output address claim status in the dialog
box. It indicates the success (1) or failure (0) of the nodes address claim.
Parameters
Config name
The ID of the J1939 network configuration to associate this node with. This is used to
access the corresponding J1939 database.
Node name
The name of this J1939 node. The available list shows none if no J1939 network
configuration is found or no node is defined in the associated database. If you are
creating a custom node, the node name must be unique within its J1939 network
configuration.
Message
These are the nine network attributes as defined by the database file consistent with
the J1939 protocol. These parameters are read-only unless you are defining a custom
node.
15-43
15 Block Reference
exists in a network, then this field must be set to 0 to define it as the first
instance. Decimal, 5-bit.
ECU Instance This 3-bit field is used when multiple electronic control units
(ECU) are involved in performing a single function. If only one ECU is used for a
particular controller application (CA), then this field must be set to 0 to define it
as the first instance.
Manufacturer Code Decimal, 11-bit.
Identity Number Decimal, 21-bit.
Sample time
Simulation refresh rate. Specify the sampling time of the block during simulation.
This value defines the frequency at which the J1939 Node Configuration updates
its optional output ports. If the block is inside a triggered subsystem or inherits
a sample time, specify a value of -1. You can also specify a MATLAB variable for
sample time. The default value is 0.01 seconds. For information about simulation
sample timing, see What Is Sample Time? (Simulink)
Output current node address
Enable or disable the Address output port to show the effective address. The
effective address is different from the predefined station address if Allow arbitrary
address is selected, a name conflict occurs, and the current node has lower priority.
The output signal is a double value from 0 to 253. This port is disabled by default.
Output address claim status
Enable or disable the address claim AC Status output port to show the success of an
address claim. The output value is binary, 1 for success or 0 for failure. This port is
disabled by default.
See Also
See Also
Blocks
J1939 CAN Transport Layer | J1939 Network Configuration | J1939
Receive | J1939 Transmit
Topics
Basic J1939 Communication over CAN
15-44
J1939 Node Configuration
Introduced in R2015b
15-45
15 Block Reference
J1939 Receive
Receive J1939 parameter group messages
Library
Vehicle Network Toolbox: J1939 Communication
Description
The J1939 Receive block receives a J1939 message from the configured CAN device.
The J1939 database file defines the nodes and parameter groups. You specify the J1939
database with the J1939 Network Configuration block.
Note: You need a license for both Vehicle Network Toolbox and Simulink software to use
this block.
The J1939 communication blocks also support code generation with limited deployment
capabilities. Code generation requires the Microsoft C++ compiler.
Block Outputs
Data
15-46
J1939 Receive
Depending on the J1939 parameter group defined in the J1939 database file, the
block can have multiple data output signal ports. The block output data type is
double.
Msg Status
When Output New Message Received status is checked in the dialog box, this
port outputs 1 when a new message is received from the CAN bus; otherwise, outputs
0.
Parameters
Config name
The name of the J1939 network configuration to associate with. This is used to
access the corresponding J1939 database. Only the nodes defined in the model and
associated with the specified J1939 network configuration appear in the Node name
list. The option shows none if no J1939 network configuration is found.
Node name
The name of the J1939 node. The drop-down list includes all the nodes in the model,
both custom nodes and nodes from the database.
Parameter Group
The parameter group number (PGN) and name from the database. The contents
of this list vary depending on the parameter groups that the J1939 database file
specifies. The default is the first parameter group for the selected node.
Note If you change any parameter group settings within your J1939 database
file, you must then open the J1939 Receive block dialog box and select the same
Parameter Group, then click OK or Apply to update the parameter group
information in the block.
Signals
Signals defined in the parameter group.
Source Address Filter
Filter messages based on source address:
15-47
15 Block Reference
Allow all Accepts messages from any source address. This is the default.
Sample time
Simulation refresh rate. Specify the sampling time of the block during simulation.
This value defines the frequency at which the J1939 Receive updates its output ports.
If the block is inside a triggered subsystem or inherits a sample time, specify a value
of -1. You can also specify a MATLAB variable for sample time. The default value is
0.01 seconds. For information about simulation sample timing, see What Is Sample
Time? (Simulink)
Output New Message Received status
Select this check box to create a Msg Status output port. Its output signal indicates
a new incoming message, showing 1 for a new message received, or 0 when there is
no new message.
See Also
See Also
Blocks
J1939 CAN Transport Layer | J1939 Network Configuration | J1939 Node
Configuration | J1939 Transmit
Topics
Basic J1939 Communication over CAN
Introduced in R2015b
15-48
J1939 Transmit
J1939 Transmit
Transmit J1939 message
Library
Vehicle Network Toolbox: J1939 Communication
Description
The J1939 Transmit block transmits a J1939 message. The J1939 database file defines
the nodes and parameter groups. You specify the J1939 database with the J1939
Network Configuration block.
Note: You need a license for both Vehicle Network Toolbox and Simulink software to use
this block.
The J1939 communication blocks also support code generation with limited deployment
capabilities. Code generation requires the Microsoft C++ compiler.
Block Inputs
Data
15-49
15 Block Reference
Depending on the J1939 parameter group and signals defined in the J1939 database
file, the block can have multiple data input ports.
Trigger
Enables the transmission of the message for that sample. A value of 1 specifies to
send, a value of 0 specifies not to send.
Parameters
Config name
The name of the J1939 network configuration to associate with. This is used to
access the corresponding J1939 database. Only the nodes defined in the model and
associated with the specified J1939 network configuration appear in the Node name
list. The option shows none if no J1939 network configuration is found.
Node name
The name of the J1939 node. The drop-down list includes all the nodes in the model,
both custom nodes and nodes from the database.
Parameter Group
The parameter group number (PGN) and name from the database. The contents
of this list vary depending on the parameter groups that the J1939 database file
specifies. The default is the first parameter group for the selected node.
Note If you change any parameter group settings within your J1939 database
file, you must then open the J1939 Transmit block dialog box and select the same
Parameter Group, then click OK or Apply to update the parameter group
information in the block.
Signals
Signals defined in the parameter group.
PG Priority
Priority of the parameter group, read from the database. This priority setting
resolves clashes of multiple parameter groups transmitting on the same bus at the
same time. If a conflict occurs, the priority group with lower priority (i.e., higher
15-50
J1939 Transmit
value) will refrain from transmitting. The value can range from 0 (highest priority) to
7 (lowest).
Destination Address
Name of the destination node. The default is the first node defined in the database,
otherwise Custom.
For a custom destination address, you can specify 0253 for the address of the
destination node. For broadcasting to all nodes, use the Custom Destination
Address setting with an address of 255.
See Also
See Also
Blocks
J1939 CAN Transport Layer | J1939 Network Configuration | J1939 Node
Configuration | J1939 Receive
Topics
Basic J1939 Communication over CAN
Introduced in R2015b
15-51
15 Block Reference
XCP Configuration
Configure XCP slave connection
Library
XCP Communication
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.
The XCP communication blocks also support code generation with limited deployment
capabilities. Code generation requires the Microsoft C++ compiler.
Parameters
Config name
15-52
XCP Configuration
See Also
Introduced in R2013a
15-53
15 Block Reference
Library
XCP Communication
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.
Note A model with XCP Data Acquisition blocks does not disconnect from the XCP slave
when the simulation ends. The model continues to acquire measurements until the data
transmission from the XCP slave is terminated.
The XCP communication blocks also support code generation with limited deployment
capabilities. Code generation requires the Microsoft C++ compiler.
15-54
XCP Data Acquisition
Dialog Box
Use the Block Parameters dialog box to select your data acquisition parameters.
15-55
15 Block Reference
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 configurations
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
measurement you want to use and click the add button, to add it to the
selected measurements. Hold the Ctrl key on your keyboard to select multiple
measurements.
Selected Measurements
This list displays selected measurements. To remove a measurement from this list,
15-56
XCP Data Acquisition
Toggle buttons
See Also
See Also
XCP Configuration
Introduced in R2013a
15-57
15 Block Reference
Library
XCP Communication
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.
The XCP communication blocks also support code generation with limited deployment
capabilities. Code generation requires the Microsoft C++ compiler.
Dialog Box
Use the Block Parameters dialog box to select your data stimulation parameters.
15-58
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
15-59
15 Block Reference
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
measurement you want to use and click the add button, to move it to the
selected measurements. Hold the Ctrl key on your keyboard to select multiple
measurements.
Selected Measurements
This list displays selected measurements. To remove a measurement from this list,
15-60
XCP Data Stimulation
See Also
Introduced in R2013a
15-61
15 Block Reference
Library
Vehicle Network Toolbox: CAN Communication
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.
The XCP communication blocks also support code generation with limited deployment
capabilities. Code generation requires the Microsoft C++ compiler.
Parameters
Device
15-62
XCP CAN Transport Layer
Select a CAN device from the list of devices available to your system.
Bus speed
Set the bus speed property for the selected device. The default bus speed is the
default assigned by the selected device.
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 subsystem and the underlying blocks run
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).
See Also
See Also
XCP Data Stimulation | XCP Configuration | XCP Data Acquisition
Introduced in R2013a
15-63
15 Block Reference
Description
The XCP CAN Transport Layer Receive block receives XCP messages from a CAN
Receive block.
The XCP communication blocks also support code generation with limited deployment
capabilities. Code generation requires the Microsoft C++ compiler.
Parameters
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).
15-64
XCP CAN TL Receive
See Also
See Also
XCP CAN TL Transmit
Introduced in R2013a
15-65
15 Block Reference
Description
The XCP CAN Transport Layer Transmit block connects to a CAN Transmit block to
transmit queued XCP messages.
The XCP communication blocks also support code generation with limited deployment
capabilities. Code generation requires the Microsoft C++ compiler.
Parameters
Maximum number of messages
Enter the maximum number of messages the block can transmit. Value must be a
positive integer.
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 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).
15-66
XCP CAN TL Transmit
See Also
See Also
XCP CAN TL Receive
Introduced in R2013a
15-67