Vehicle Network Toolbox™ User's Guide R2015a
How to Contact MathWorks Latest news: www.mathworks.com Sales and services: www.mathworks.com/sales_and_services User community: www.mathworks.com/matlabcentral Technical support: www.mathworks.com/support/contact_us Phone: 508-647-7000 The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 Vehicle Network Toolbox™ User's Guide © COPYRIGHT 2009–2015 by The MathWorks, Inc. The software described in this document is furnished under a license agreement.
Revision History March 2009 September 2009 March 2010 September 2010 April 2011 September 2011 March 2012 September 2012 March 2013 September 2013 March 2014 October 2014 March 2015 Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only New for Version 1.0 (Release 2009a) Revised for Version 1.1 (Release 2009b) Revised for Version 1.2 (Release 2010a) Revised for Version 1.
Contents 1 Getting Started Vehicle Network Toolbox Product Description . . . . . . . . . . . Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 1-2 Product Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Vehicle Network Toolbox Characteristics . . . . . . . . . . . . . . . Interaction Between the Toolbox and Its Components . . . . . . Expected Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Related Products . .
2 3 4 Filter Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Multiplex Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configure Silent Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Disconnect Channels and Clean Up . . . . . . . . . . . . . . . . . . 1-24 1-25 1-28 1-28 Access the Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Explore the Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Load .dbc Files and Create Messages . . . . . . . . . . . . . . . . . . . Load the CAN Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . Create a CAN Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Access Signals in the Constructed CAN Message . . . . . . . . . Add a Database to a CAN Channel . . . . . . . . . . . . . . . . . . . . Update Database Information . . . . . . . . . . . . . . . . . . . . . . . . Create and Process Messages Using Database Definitions . . .
7 8 9 A2L File A2L File Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Access an A2L File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3 Access Event Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 Inspect the Contents of an A2L File . . . . . . . . . . . . . . . . . . . . Access Measurement Information . . . . . . . . . . . . . . . . . . . . .
10 CAN Communication in Simulink . . . . . . . . . . . . . . . . . . . . . . Message Transmission Workflow . . . . . . . . . . . . . . . . . . . . . . Message Reception Workflow . . . . . . . . . . . . . . . . . . . . . . . . 9-3 9-4 9-6 Open the Vehicle Network Toolbox Block Library . . . . . . . . Using the MATLAB Command Window . . . . . . . . . . . . . . . . Using the Simulink Library Browser . . . . . . . . . . . . . . . . . . 9-8 9-8 9-9 Build CAN Communication Simulink Models . . . . . . . . . .
12 13 14 x Contents Functions — Alphabetical List Properties — Alphabetical List Block Reference
1 Getting Started • “Vehicle Network Toolbox Product Description” on page 1-2 • “Product Capabilities” on page 1-3 • “Install Required Components” on page 1-7 • “Vehicle Network Communication in MATLAB” on page 1-13 • “Vehicle Network Communication Examples” on page 1-16 • “Access the Toolbox” on page 1-31
1 Getting Started Vehicle Network Toolbox Product Description Communicate with in-vehicle networks and access ECUs using CAN and XCP protocols 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 and XCP messages, enabling you to exchange messages between a CAN bus and your programs and models.
Product Capabilities Product Capabilities In this section... “Vehicle Network Toolbox Characteristics” on page 1-3 “Interaction Between the Toolbox and Its Components” on page 1-4 “Expected Background ” on page 1-6 “Related Products” on page 1-6 Vehicle Network Toolbox Characteristics The toolbox is a collection of functions built on the MATLAB technical computing environment.
1 Getting Started See “Supported Hardware” on page 1-10 for more information. Communicate Between MATLAB and CAN Bus 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.
Product Capabilities In this illustration: • Six CAN modules are attached to a CAN bus. • One module, which is a CAN device, is attached to the Vehicle Network Toolbox, built on the MATLAB technical computing environment. Using Vehicle Network Toolbox from MATLAB, you can configure a channel on the CAN device to: • Transmit messages to the CAN bus. • Receive messages from the CAN bus. • Trigger a callback function to run when the channel receives a message.
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 Vehicle CAN Bus” with the CAN Tool. Vehicle Network Toolbox is a comprehensive solution for CAN connectivity in MATLAB and Simulink.
Install Required Components Install Required Components In this section...
1 Getting Started These drivers are available for download from the Vector Web site at: http://vector.com/vi_downloadcenter_en.html Drivers for 32-bit and 64-bit Windows are available in separate packages. Download and install the latest version and select the appropriate check box during installation for the hardware you want to use. Virtual channels are also installed with the hardware drivers. XL Driver Library Download and install the latest version of the XL Driver Library from the Vector Web site.
Install Required Components If you are using an NI-CAN device, install the NI-CAN programming library from the National Instruments Web site. This installs both the drivers and the driver libraries. If you are using an NI-XNET device, install the latest NI-XNET drivers from the National Instruments Web site. This installs both the drivers and the driver libraries. Drivers for 32-bit and 64-bit Windows are available in the same package.
1 Getting Started Install the Toolbox Determine if Vehicle Network Toolbox software is installed on your system by typing the following in the MATLAB Command Window: ver The Command Window displays information about the MATLAB version you are running, including a list of installed add-on products and their version numbers. Check the list to see if the Vehicle Network Toolbox name appears. For information about installing the toolbox, refer to the installation documentation for your platform.
Install Required Components • WLAN • PCMCIA • Leaf • Memorator • PCI • USB You can also use the toolbox with virtual CAN channels available with Kvaser hardware drivers. For a full list of devices, see the Supported Hardware page. Supported National Instruments Devices You can use NI-CAN and NI-XNET devices with Vehicle Network Toolbox. For a complete list of supported NI-CAN devices, see the Supported Hardware page.
1 Getting Started • PCAN-ExpressCard • PCAN-PCI • PCAN-PCI Express • PCAN-cPCI • PCAN-miniPCI • PCAN-minPCIe 1-12
Vehicle Network Communication in MATLAB Vehicle Network Communication in MATLAB Workflows in this section are sequential and will help you understand how the communication works. You can also see code snippets and map them to the examples in the next section.
1 Getting Started Transmit Workflow 1-14
Vehicle Network Communication in MATLAB Receive Workflow 1-15
1 Getting Started Vehicle Network Communication Examples In this section...
Vehicle Network Communication Examples The following examples use the Vector CANcaseXL hardware. You can substitute it with any other supported hardware.
1 Getting Started 1 Create the first CAN channel on an installed CAN device: canch1 = canChannel('Vector','CANcaseXL 1',1) Notes You cannot use the same variable to create multiple channels sequentially. Clear any channel in use before using the same variable to construct a new CAN Channel. You cannot create arrays of CAN channel objects. Each object you create must exist as its own individual variable. 2 Press Enter after you create the connection.
Vehicle Network Communication Examples configBusSpeed(canch1, 250000) 2 To see the changed property value, type: canch1.BusSpeed MATLAB displays all properties on the configured channel as before, with the changed BusSpeed property value: . . . BusSpeed = 250000 3 Change the bus speed of the second channel (canch2) by repeating steps 2 and 3. Start the Channel Start your CAN channels after you configure all properties.
1 Getting Started a message using canch and receive it using canch1. To transmit a message, create a message object and pack the message with the required data. 1 Build a CAN message of ID 500 of standard type and a data length of 8 bytes: messageout = canMessage(500, false, 8) The message object is now: messageout = can.
Vehicle Network Communication Examples 1 Use the pack function to pack your message with these input parameters: pack(messageout, 25, 0, 16, 'LittleEndian') Here you are specifying the data value to be 25, the start bit to be 0, the signal size to be 16, and the byte order to be little-endian format. 2 To see the packed data, type: messageout MATLAB displays your message properties with the specified data: messageout = can.
1 Getting Started canch1 MATLAB displays the updated status of the channel: Summary of CAN Channel using 'Vector' 'CANcaseXL 1' Channel 1. Channel Parameters: Status: Filter History: Bus Speed is 250000. Bus Status is 'ErrorPassive'. Transceiver name is 'CANpiggy 251mag (Highspeed)'. Serial Number of this device is 24811. Initialization access is allowed. No database is attached. Online. 1 messages available to RECEIVE. 1 messages transmitted since last start. 0 messages received since last start.
Vehicle Network Communication Examples can.Message handle Package: can Properties: ID: Extended: Name: Database: Error: Remote: Timestamp: Data: Signals: 500 0 '' [] 0 0 709.0403 [25 0 0 0 0 0 0 0] [] Methods, Events, Superclasses 3 To check if the channel received the message, type: canch2 MATLAB returns the channel properties, and the status indicates that the channel received one message: . . . Status: Online. 0 messages available to RECEIVE. 0 messages transmitted since last start.
1 Getting Started 25 Refer to the unpack function to understand more about its input arguments. Save a CAN Channel You can save a CAN channel object to a file using the save function anytime during the CAN communication session. For example, create a channel object canch1. To save it to the MATLAB file mycanch.mat, type: save mycanch.mat canch1 Load a Saved Channel If you have saved a CAN channel as a MATLAB file, you can load it into a session using the load function. For example, to reload mycanch.
Vehicle Network Communication Examples 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. Channel Parameters: Status: Filter History: Bus Speed is 500000. Bus Status is 'N/A'. Transceiver name is ''. Serial Number of this device is 0. Initialization access is allowed. 'demoVNT_CANdbFiles.dbc' database is attached. Offline - Waiting for start. 0 messages available to receive.
1 Getting Started • SigB: Another multiplexed signal with a multiplex value of 1. • MuxSig: A multiplexor signal, whose value determines which of the two multiplexed signals are active in the message. 1 Create a CAN database: d = canDatabase('Mux.dbc') Note: This is an example database constructed for creating multiplex messages. To try this example, use your own database. 2 Create a CAN message: m = canMessage(d, 'Msg') The message displays all its properties: m = can.
Vehicle Network Communication Examples 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.
1 Getting Started 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. Refer to the canMessage function to learn more about creating messages. Configure Silent Mode The SilentMode property of a CAN channel specifies that the channel can only receive messages and not transmit them.
Vehicle Network Communication Examples stop(canch1) 2 Check the channel status: canch1 MATLAB displays the channel status: . . . Status: 3 Offline - Waiting for START. 1 messages available to RECEIVE. 1 messages transmitted since last start. 0 messages received since last start. Stop the second channel: stop(canch2) 4 Check the channel status: canch2 MATLAB displays the channel status: Status: Offline - Waiting for START. 0 messages available to RECEIVE. 0 messages transmitted since last start.
1 Getting Started clear value 1-30
Access the Toolbox Access the Toolbox In this section... “Explore the Toolbox” on page 1-31 “Get Help” on page 1-31 “View Examples” on page 1-31 Explore the Toolbox You can access Vehicle Network Toolbox from the MATLAB Command Window directly by using any Vehicle Network Toolbox function. To see a list of all the functions available, type: help vnt Get Help The toolbox functions are grouped by usage. Click a specific function for more information.
2 Hardware Support Package Installation • “Vector CAN Device Support” on page 2-2 • “National Instruments NI-CAN Device Support” on page 2-5 • “National Instruments NI-XNET Device Support” on page 2-8 • “Kvaser CAN Device Support” on page 2-11 • “PEAK-System CAN Device Support” on page 2-13
2 Hardware Support Package Installation Vector CAN Device Support Use this process to add support for Vector CAN devices to Vehicle Network Toolbox. After you download and install the Vector driver on your host computer, you can transmit and receive CAN messages with your Vector hardware using Vehicle Network Toolbox. Note: You can use this support package only on a host computer running 32-bit or 64-bit Windows. 2-2 1 Open MATLAB. 2 Click Add-Ons in the MATLAB Home menu.
Vector CAN Device Support 1 Follow the support package installer prompts. When prompted, log into your MathWorks® account. Note: You need write privileges for the Installation folder.
2 Hardware Support Package Installation At any time during this process, you can click Help for more information about downloading support packages.
National Instruments NI-CAN Device Support National Instruments NI-CAN Device Support Use this process to add support for NI-CAN devices to Vehicle Network Toolbox. After you download and install the NI-CAN driver on your host computer, you can transmit and receive CAN messages on your NI-CAN hardware using Vehicle Network Toolbox. Note: You can use this support package only on a host computer running 32-bit Windows. 1 Open MATLAB. 2 Click Add-Ons in the MATLAB Home menu.
2 Hardware Support Package Installation 1 Follow the support package installer prompts. When prompted, log into your MathWorks account. Note: You need write privileges for the Installation folder.
National Instruments NI-CAN Device Support At any time during this process, you can click Help for more information about downloading support packages.
2 Hardware Support Package Installation National Instruments NI-XNET Device Support Use this process to add support for NI-XNET devices to Vehicle Network Toolbox. After you download and install the NI-XNET driver on your host computer, you can transmit and receive CAN messages on your NI-XNET hardware using Vehicle Network Toolbox. Note: You can use this support package only on a host computer running 32-bit Windows. 2-8 1 Open MATLAB. 2 Click Add-Ons in the MATLAB Home menu.
National Instruments NI-XNET Device Support 1 Follow the support package installer prompts. When prompted, log into your MathWorks account. Note: You need write privileges for the Installation folder.
2 Hardware Support Package Installation At any time during this process, you can click Help for more information about downloading support packages.
Kvaser CAN Device Support Kvaser CAN Device Support Use this process to add support for Kvaser devices to Vehicle Network Toolbox. After you download and install the Kvaser driver on your host computer, you can transmit and receive CAN messages on your Kvaser hardware using Vehicle Network Toolbox. Note: You can use this support package only on a host computer running 32-bit or 64-bit Windows. 1 Open MATLAB. 2 Click Add-Ons in the MATLAB Home menu. 3 Select Get Hardware Support Packages.
2 Hardware Support Package Installation 2 Follow the support package installer prompts. When prompted, log into your MathWorks account. Note: You need write privileges for the Installation folder. At any time during this process, you can click Help for more information about downloading support packages.
PEAK-System CAN Device Support PEAK-System CAN Device Support Use this process to add support for PEAK-System CAN devices to Vehicle Network Toolbox. After you download and install the PEAK-System driver on your host computer, you can transmit and receive CAN messages with your PEAK–System hardware using Vehicle Network Toolbox. Note: You can use this support package only on a host computer running 32-bit or 64-bit Windows. 1 Open MATLAB. 2 Click Add-Ons in the MATLAB Home menu.
2 Hardware Support Package Installation 1 Follow the support package installer prompts. When prompted, log into your MathWorks account. Note: You need write privileges for the Installation folder.
PEAK-System CAN Device Support At any time during this process, you can click Help for more information about downloading support packages.
3 CAN Communication Workflows • “CAN Transmit Workflow” on page 3-2 • “CAN Receive Workflow” on page 3-5
3 CAN Communication Workflows CAN Transmit Workflow This workflow helps you create a CAN channel and transmit messages.
CAN Transmit Workflow 3-3
3 CAN Communication Workflows See Also Functions canChannel | canDatabase | canMessage | canMessageImport | configBusSpeed | pack | start | stop | transmit | transmitConfiguration | transmitEvent | transmitPeriodic Properties Data | Database | Error | Extended | ID | Name (Message) | Remote | Signals | Timestamp | UserData Blocks CAN Pack | CAN Replay | CAN Transmit 3-4
CAN Receive Workflow CAN Receive Workflow Use this workflow to receive and unpack CAN messages.
3 3-6 CAN Communication Workflows
CAN Receive Workflow See Also Functions attachDatabase | canDatabase | configBusspeed | extractAll | extractRecent | extractTime | receive | stop | unpack Properties MessageReceivedFcn | MessageReceivedFcnCount | MessagesAvailable | MessagesReceived | MessagesTransmitted ReceiveErrorCount | TransmitErrorCount Blocks CAN Log | CAN Receive | CAN Unpack 3-7
4 Using a CAN Database • “Vector CAN Database Support” on page 4-2 • “Load .
4 Using a CAN Database Vector CAN Database Support A CAN database contains physical message and signal definitions. Using a CAN database, you can represent message and signal information in engineering units and do need not manipulate raw data bytes. You can use a Vector CAN database with Vehicle Network Toolbox. A .dbc file contains definitions of CAN messages and signals. Look up message and signal information and build messages using the information defined in the database file.
Load .dbc Files and Create Messages Load .dbc Files and Create Messages In this section... “Load the CAN Database” on page 4-3 “Create a CAN Message” on page 4-3 “Access Signals in the Constructed CAN Message” on page 4-4 “Add a Database to a CAN Channel” on page 4-4 “Update Database Information” on page 4-5 “Create and Process Messages Using Database Definitions” on page 4-5 Load the CAN Database To use a CAN database file, load the database into your MATLAB session.
4 Using a CAN Database > VNTDemos subfolder in your MATLAB installation folder. This database has a message, EngineMsg. To try this example, create messages and signals using definitions in your own database. 1 Create the CAN database object: d = canDatabase('demoVNT_CANdbFiles.
Load .dbc Files and Create Messages canch.Database = canDatabase('Mux.dbc') For more information, see the Database property. Update Database Information When you make changes to a database file: 1 Reload the database file into your MATLAB session using the canDatabase function. 2 Reattach the database to messages using the attachDatabase function.
4 Using a CAN Database 'DoorControlMsg' 'EngineMsg' 'SunroofControlMsg' 'TransmissionMsg' 'WindowControlMsg' View Message Information Use messageInfo to view message information, including the identifier, data length, and a signal list. messageInfo(db, 'EngineMsg') ans = Name: Comment: ID: Extended: Length: Signals: 'EngineMsg' '' 100 0 8 {2x1 cell} You can also query for information on all messages at once.
Load .dbc Files and Create Messages signalInfo(db, 'EngineMsg', 'EngineRPM') ans = Name: StartBit: SignalSize: ByteOrder: Signed: ValueType: Class: Factor: Offset: Minimum: Maximum: Units: Comment: Multiplexor: Multiplexed: MultiplexMode: 'EngineRPM' 0 32 'LittleEndian' 0 'Integer' 'uint32' 0.1000 250 250 9500 'rpm' '' 0 0 0 You can also query for information on all signals in the message at once.
4 Using a CAN Database Multiplexed MultiplexMode Create a Message Using Database Definitions Specify the name of the message when you create a new message to have the database definition applied. CAN signals in this messages are represented in engineering units in addition to the raw data bytes. msgEngineInfo = canMessage(db, 'EngineMsg') msgEngineInfo = can.
Load .dbc Files and Create Messages Change Signal Information Write directly to the signal to change a value and read its current value back. msgEngineInfo.Signals.EngineRPM = 5500.25 msgEngineInfo.Signals msgEngineInfo = can.Message handle Package: can Properties: ID: Extended: Name: Database: Error: Remote: Timestamp: Data: Signals: UserData: 100 0 'EngineMsg' [1x1 can.Database] 0 0 0 [23 205 0 0 0 0 0 0] [1x1 struct] [] ans = VehicleSpeed: 0 EngineRPM: 5.
4 Using a CAN Database Properties: ID: Extended: Name: Database: Error: Remote: Timestamp: Data: Signals: UserData: 100 0 'EngineMsg' [1x1 can.Database] 0 0 0 [23 205 0 0 71 0 0 0] [1x1 struct] [] ans = VehicleSpeed: 71 EngineRPM: 5.5003e+03 Receive Messages with Database Information 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.
Load .dbc Files and Create Messages 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(); rxMsg = receive(rxCh, Inf) rxMsg = 1x418 can.Message handle Package: can Properties: ID Extended Name Database Error Remote Timestamp Data Signals UserData Stop the channel and clear it from the workspace.
4 Using a CAN Database ans = can.Message handle Package: can Properties: ID: Extended: Name: Database: Error: Remote: Timestamp: Data: Signals: UserData: 100 0 'EngineMsg' [1x1 can.Database] 0 0 0.1746 [88 134 0 0 52 0 0 0] [1x1 struct] [] ans = VehicleSpeed: 52 EngineRPM: 3.6892e+03 Extract Most Recent Message by Name Use extractRecent and specify a message name to extract the most recent occurrence of a message. msgRecentWindows = extractRecent(rxMsg, 'WindowControlMsg') msgRecentWindows = can.
Load .dbc Files and Create Messages Timestamp: Data: Signals: UserData: 5.5749 [64 62 0 0] [1x1 struct] [] Extract All Instances of a Specified Message by Name Use extractAll and specify a message name to extract all instances of a specified message. allMsgEngine = extractAll(rxMsg, 'EngineMsg') allMsgEngine = 1x225 can.
4 Using a CAN Database signals = 1x225 struct array with fields: VehicleSpeed EngineRPM 4-14
Other Uses of the CAN Database Other Uses of the CAN Database In this section... “View Message Information in a CAN Database” on page 4-15 “View Signal Information in a CAN Message” on page 4-16 “Attach a CAN Database to Existing Messages” on page 4-16 View Message Information in a CAN Database You can look up information on message definitions by a single message by name, or a single message by ID.
4 Using a CAN Database ID: Extended: Length: Signals: 100 0 8 {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) This command provides the database name, the message ID, and a Boolean value for the extended value of the ID.
Other Uses of the CAN Database To attach a database to a message, type: attachDatabase(message name, database name) 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.
5 Monitoring Vehicle CAN Bus • “Vehicle CAN Bus Monitor” on page 5-2 • “Using the Vehicle CAN Bus Monitor” on page 5-8
5 Monitoring Vehicle CAN Bus Vehicle CAN Bus Monitor 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 About the Vehicle CAN Bus Monitor Vehicle Network Toolbox provides a graphical user interface that monitors CAN bus traffic on selected channels. Using the CAN Bus Monitor you can: • View live CAN message data. • Configure connection to the CAN bus. • View unique messages.
Vehicle CAN Bus Monitor File Menu • Save Messages — Saves messages to a log file. • Clear Messages — Clears messages in the Vehicle CAN Bus Monitor window.
5 Monitoring Vehicle CAN Bus • Exit CAN Tool — Click to exit the CAN Tool window. 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.
Vehicle CAN Bus Monitor • Block All — Select to block all standard ID messages. • Allow only — Select to set up custom filtering of messages. Type the standard message IDs that you want to allow. • Extended Message ID Filter • Allow All — Select to allow all extended ID messages. • Block All — Select to block all extended ID messages. • Allow only — Select to set up custom filtering of messages. Type the extended message IDs that you want to allow.
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.
Vehicle CAN Bus Monitor Undocking Click this button to undock the Vehicle CAN Bus Monitor from the MATLAB desktop. To dock, click this button. Message Table Timestamp Displays the time, relative to the start time, that the device receives the message. The start time begins at 0 when you click Start. ID Displays the message ID. This field displays a number in hexadecimal format for the ID and: • Displays numbers only for standard IDs. • Appends an x for an extended ID. • Displays an r for a remote frame.
5 Monitoring Vehicle CAN Bus Using the Vehicle CAN Bus Monitor In this section...
Using the Vehicle CAN Bus Monitor Filter CAN Messages in Vehicle CAN Bus Monitor Filter CAN messages to allow or block messages displayed in the Vehicle CAN Bus Monitor. To set up filters: 1 Select Configure > Message Filters. 2 To set filters on standard message IDs, select: 3 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.
5 Monitoring Vehicle CAN Bus 4 5-10 Click the plus (+) sign to see the details of the message.
Using the Vehicle CAN Bus Monitor The tool displays the signal name as defined in the attached database and the signal's physical value. Change the Message Count You can change the maximum number of messages displayed to a value from 100 through 5000. 1 Select View > Maximum Message Count. 2 In the Specify maximum message count dialog box, type the number of messages you want displayed at one time. 3 Click OK. Change the Number Format By default the message data is displayed in hexadecimal format.
5 Monitoring Vehicle CAN Bus Use this feature to get a snapshot of message IDs that the selected channel receives. Use this information to analyze specific messages. When you select Show Unique Messages, the tool continues to receive message actively. This simplified view allows you to focus on specific messages and analyze them. To save messages when Show Unique Messages is selected, click Pause and then click Save. You cannot save just the unique message list.
6 XCP Communication Workflows
6 XCP Communication Workflows XCP Database and Communication Workflow This workflow helps you: • Manage an A2L database • Connect to an XCP device • Create an XCP channel • Acquire and stimulate data • Read and write to memory 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
7 A2L File • “A2L File Support” on page 7-2 • “Access an A2L File” on page 7-3 • “Access Event Information” on page 7-4 • “Inspect the Contents of an A2L File” on page 7-5
7 A2L File A2L File Support An A2L file is a special description file that defines the implementation of an ECU that can communicate with a slave module via an XCP connection. An A2L file is a formatted text file that contains event and measurement definitions as well as other configuration information. You can use this information to connect an XCP channel to a slave module and acquire and stimulate data and perform other functions.
Access an A2L File Access an A2L File To use a A2L file, open the file in your MATLAB session. At the MATLAB command prompt, type: a2lfile = xcpA2L('filename.a2l') Here a2lfile is a variable you chose for your A2L object and filename.a2l is the actual file name of your A2L file. If your A2L file is not in the current working directory, type the path to the file: a2lfile = xcpA2L('path\filename.
7 A2L File Access Event Information This example shows how to open an A2L file and access event information. Open an A2L file: a2lfile = xcpA2L('XCPSIM.a2l'); Display properties of the A2L object: a2lfile A2L with properties: FileName: FilePath: SlaveName: ProtocolLayerInfo: DAQInfo: TransportLayerCANInfo: Events: Measurements: 'XCPSIM.a2l' 'H:\Documents\work\XCPSIM.
Inspect the Contents of an A2L File Inspect the Contents of an A2L File Access Measurement Information This example shows how to open an A2L file and access measurement information. Open an A2L file: a2lfile = xcpA2L('XCPSIM.a2l'); Display properties of the A2L object: a2lfile A2L with properties: FileName: FilePath: SlaveName: ProtocolLayerInfo: DAQInfo: TransportLayerCANInfo: Events: Measurements: 'XCPSIM.a2l' 'H:\Documents\work\XCPSIM.
7 A2L File Get information about the BitSlice measurement: getMeasurementInfo(a2lfile,'Triangle') ans = Name: LongIdentifier: DataType: Conversion: Resolution: Accuracy: LowerLimit: UpperLimit: ECUAddress: ECUAddressExtension: ByteOrder: SizeInBytes: SizeInNibbles: SizeInBits: MATLABType: 7-6 'Triangle' 'Triangle test signal used for PWM output PWM' 'SBYTE' 'BitSlice.
8 Universal Measurement & Calibration Protocol (XCP) • “XCP Interface” on page 8-2 • “XCP Hardware Connection” on page 8-3 • “Read a Single Value” on page 8-7 • “Write a Single Value” on page 8-8 • “Acquire Measurement Data via Dynamic DAQ Lists” on page 8-9 • “Stimulate Measurement Data via Dynamic STIM Lists” on page 8-10
8 Universal Measurement & Calibration Protocol (XCP) 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.
XCP Hardware Connection XCP Hardware Connection You can connect your XCP master to a slave module using the CAN protocol. This allows you to use events and access measurements on the slave module.
8 8-4 Universal Measurement & Calibration Protocol (XCP)
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 Create XCP Channel Using CAN Device This example shows how to create an XCP CAN channel connection and access channel properties. The example also shows how to unlock the slave using seed key security. Access an A2L file that describe the slave module. a2lfile = xcpA2L('C:\work\XCPSIM.
8 Universal Measurement & Calibration Protocol (XCP) SeedKeyDLL: [] Configure the Channel to Unlock the Slave This example shows how to configure the channel to unlock the slave using a dll that contains a seed and key security algorithm when your module is locked for Stimulation operations,. Create your XCP channel and set the channel’s SeedKeyDLL property. xcpch.SeedKeyDLL = ('C:\Work\SeedNKeyXcp.
Read a Single Value Read a Single Value This example shows how to access a single value by name. The value is read directly from memory. Create an XCP channel with access to an A2L file a2lfile = xcpA2L('C:\work\XCPSIM.a2l'); xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1); Connect the slave. connect(xcpch) Read a single value of the Triangle measurement directly from memory.
8 Universal Measurement & Calibration Protocol (XCP) Write a Single Value This example shows how to write a single value by name. The value is written directly to memory. Create an XCP channel linked to an A2L file. a2lfile = xcpA2L('C:\work\XCPSIM.a2l'); xcpch = xcpChannel(a2lfile, 'CAN', 'Vector', 'Virtual 1', 1); Connect the slave. connect(xcpch) Write a single value.
Acquire Measurement Data via Dynamic DAQ Lists Acquire Measurement Data via Dynamic DAQ Lists This example shows how to can create a dynamic data acquisition list and assign measurements to the list. You can acquire data for measurements in this list from the slave. Create an XCP channel linked to an A2L file and connect it to the slave. a2lfile = xcpA2L('C:\work\XCPSIM.
8 Universal Measurement & Calibration Protocol (XCP) Stimulate Measurement Data via Dynamic STIM Lists This example shows how to can create a dynamic data stimulation list and assign measurements to the list. You can stimulate data for specific measurements in this list. Create an XCP channel linked to an A2L file and connect it. a2lfile = xcpA2L('C:\work\XCPSIM.
9 CAN Communications in Simulink • “Vehicle Network Toolbox Simulink Blocks” on page 9-2 • “CAN Communication in Simulink” on page 9-3 • “Open the Vehicle Network Toolbox Block Library” on page 9-8 • “Build CAN Communication Simulink Models” on page 9-11 • “Create Custom Blocks” on page 9-27
9 CAN Communications in Simulink Vehicle Network Toolbox Simulink Blocks This section describes how to use the Vehicle Network Toolbox CAN block library. The library contains these blocks: • CAN Configuration — Configure the settings of a CAN device. • CAN Log— Logs messages to file. • CAN Pack — Pack signals into a CAN message. • CAN Receive — Receive CAN messages from a CAN bus. • CAN Replay— Replays logged messages to CAN bus or output port. • CAN Transmit — Transmit CAN messages to a CAN bus.
CAN Communication in Simulink CAN Communication in Simulink In this section...
9 CAN Communications in Simulink Message Transmission Workflow 9-4
CAN Communication in Simulink This workflow represents the most common CAN Transmit model. Adjust your model as needed. For more workflow examples, see “Build CAN Communication Simulink Models” on page 9-11 and the Vehicle Network Toolbox demos. Using Mux Blocks • Use a Mux block to combine every message from the source if they are transmitted at the same rate. • Use one CAN Transmit block for each configured Mux block.
9 CAN Communications in Simulink Message Reception Workflow For workflow examples, see “Build CAN Communication Simulink Models” on page 9-11 and the Vehicle Network Toolbox demos. Message Filtering Set up filters to process only relevant messages. This ensures optimal simulation performance.
CAN Communication in Simulink Do not set up filters if you need to parse all bus communications. Function-Call Triggered Message Processing Set up your CAN Unpack block: • In a function-call triggered subsystem if you want to unpack every message received by your CAN Receive block. • Without a function-call triggered subsystem if you want to unpack only the most recent message received by your CAN Receive block. Set up this system if your receive block is filtering for a single message.
9 CAN Communications in Simulink Open the Vehicle Network Toolbox Block Library In this section... “Using the MATLAB Command Window” on page 9-8 “Using the Simulink Library Browser” on page 9-9 Using the MATLAB Command Window To open the Vehicle Network Toolbox block library, enter canlib in the MATLAB Command wndow. MATLAB displays the contents of the library in a separate window.
Open the Vehicle Network Toolbox Block Library Using the Simulink Library Browser To open the Vehicle Network Toolbox block library, start the Simulink Library Browser from MATLAB. Then select the library from the list of available block libraries displayed in the browser. To start the Simulink Library Browser, enter simulink in the MATLAB Command Window.
9 CAN Communications in Simulink The Libraries pane lists all available block libraries, with the basic Simulink library listed first, followed by other libraries listed alphabetically under it. To open the Vehicle Network Toolbox block library, click its icon and select CAN Communication for the CAN blocks. Simulink loads and displays the blocks in the library.
Build CAN Communication Simulink Models Build CAN Communication Simulink Models In this section... “Build a Message Transmit Model” on page 9-11 “Build a Message Receive Model” on page 9-15 “Save and Run the Model” on page 9-23 Build a Message Transmit Model This section provides an example that builds a simple model using Vehicle Network Toolbox blocks with other blocks in the Simulink library. This example illustrates how to send data via a CAN network. • Use virtual CAN channels to transmit messages.
9 CAN Communications in Simulink icon. Then click CAN Communication to open the CAN blocks. See Using the Simulink Library Browser for more information. Step 2: Create a New Model To use a block, add it to an existing model or create a model. For this example, create a model by clicking the New model button on the toolbar. You can also select File > New > Model from the Simulink Library Browser. Simulink opens an empty editor. To name the new model, use the Save option.
Build CAN Communication Simulink Models Step 3: Drag Vehicle Network Toolbox Blocks into the Model To use the blocks in a model, click a block in the library and, holding the mouse button down, 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. Step 4: Drag Other Blocks to Complete the Model This example requires a source block that feeds data to the CAN Pack block. Add a Constant block to your model.
9 CAN Communications in Simulink Step 5: Connect the Blocks 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. 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.
Build CAN Communication Simulink Models Configure the Constant Block Double-click the Constant block to open its parameters dialog box. On the Main tab, set the: • Constant value to [1 2 3 4 5 6 7 8] • Sample time to 0.01 seconds On the Signal Attributes tab, set the Output data type to uint8. Click OK. Your model looks like this figure.
9 CAN Communications in Simulink • Use a virtual CAN channel to receive messages. • Use the CAN Configuration block to configure your virtual CAN channels. • Use the CAN Receive block to receive the message sent by the blocks built in “Build a Message Transmit Model” on page 9-11. • Use a Function–Call Subsystem block that contains the CAN Unpack block. This function takes the data from the CAN Receive block and uses the parameters of the CAN Unpack block to unpack your message data.
Build CAN Communication Simulink Models Step 8: Drag Other Blocks to Complete the Model Use the Function–Call Subsystem block from the Simulink Ports & Subsystems block library to build your CAN Message pack subsystem. 1 Drag the Function–Call Subsystem block into the model. 2 Double-click the Function–Call Subsystem block to open the subsystem editor.
9 CAN Communications in Simulink 3 9-18 Drop the CAN Unpack block from the Vehicle Network Toolbox block library in this subsystem.
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. Step 9: Connect the Blocks 1 Connect the CAN Msg output port on the CAN Receive block to the In1 input port on the Function–Call Subsystem block.
9 CAN Communications in Simulink 2 Open the Function–Call Subsystem block and: • Double-click In1 to rename it to CAN Msg. • Double-click Out1 to rename it to data. 3 Rename the Function–Call Subsystem block to CAN Unpack Subsystem. 4 Connect the f() output port on the CAN Receive block to the function() input port on the Function–Call Subsystem block. 5 Connect the CAN Unpack Subsystem output port to the input port on the Scope block. Your model looks like this figure.
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. Step 10: Specify the Block Parameter Values 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.
9 CAN Communications in Simulink • Device to Vector Virtual 1 (Channel 2) • Bus speed to 500000 • Acknowledge Mode to Normal Click OK. Configure the CAN Receive Block Double-click the CAN Receive block to open its Parameters dialog box. Set the: • Device to Vector Virtual 1 (Channel 2) • Sample time to 0.01 • Number of messages received at each timestep to all Click OK. Configure the CAN Unpack Subsystem Double-click the CAN Unpack subsystem to open the Function–Call Subsystem editor.
Build CAN Communication Simulink Models Save and Run the Model This section shows you how to save the models you built, “Build a Message Transmit Model” on page 9-11 and “Build a Message Receive Model” on page 9-15.
9 CAN Communications in Simulink Step 11: Save the Model Before you run the simulation, save your model by clicking the Save icon or selecting File > Save from the menu bar. Step 12: Change Configuration Parameters 1 In your model window, select Simulation > Model Configuration Parameters. The Configuration Parameters dialog box opens. 2 In the Solver Options section, select: • Fixed-step from the Type list. • Discrete (no continuous states) from the Solver list.
Build CAN Communication Simulink Models Step 14: View the Results Double-click the Scope block to view the message transfer on a graph.
9 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.
Create Custom Blocks Create Custom Blocks You can create custom Receive and Transmit blocks to use with hardware currently not supported by the Vehicle Network Toolbox. Vehicle Network Toolbox blocks use a custom CAN data type. To use the blocks you create with other Vehicle Network Toolbox blocks, register this custom CAN data type. To use the custom data type defined in the Vehicle Network Toolbox, write a C++ Sfunction. Note: You must use a C++ file type S-function (.cpp) to create custom blocks.
9 CAN Communications in Simulink • To create a receive block, set output port data type to CAN_MESSAGE: ssSetOutputPortDataType(S, portID, dataTypeID ); • To create a transmit block, set the input port to CAN_MESSAGE: ssSetInputPortDataType(S, portID, dataTypeID ); For more information on S-functions, see “S-Function Basics”.
10 Hardware Limitations This topic describes limitations of using hardware in the Vehicle Network Toolbox based on limitations placed by the hardware vendor:
10 Hardware Limitations Hardware Limitations By Vendor Vector Hardware You cannot have more than 64 physical or 32 virtual simultaneous connections using a Vector CAN device. If you use more than the number of connections Vector allows, you might get an error: • In MATLAB R2013a and later: Unable to query hardware information for the selected CAN channel object. • In MATLAB R2012b: boost thread resource allocation error. • In MATLAB R2012a and earlier: An unhandled error occurred with CAN device.
11 XCP Communications in Simulink • “Vehicle Network Toolbox XCP Simulink Blocks” on page 11-2 • “Open the Vehicle Network Toolbox XCP Block Library” on page 11-3 • “XCP Data Acquisition over CAN” on page 11-5
11 XCP Communications in Simulink Vehicle Network Toolbox XCP Simulink Blocks This section describes how to use the Vehicle Network Toolbox XCP block library. The library contains these blocks: • 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.
Open the Vehicle Network Toolbox XCP Block Library Open the Vehicle Network Toolbox XCP Block Library In this section... “Using the MATLAB Command Window” on page 11-3 “Using the Simulink Library Browser” on page 11-4 Using the MATLAB Command Window To open the Vehicle Network Toolbox block library, enter xcplib in the MATLAB Command wndow. MATLAB displays the contents of the library in a separate window.
11 XCP Communications in Simulink Using the Simulink Library Browser To open the Vehicle Network Toolbox block library, start the Simulink Library Browser from MATLAB. Then select the library from the list of available block libraries displayed in the browser. 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.
XCP Data Acquisition over CAN XCP Data Acquisition over CAN This example shows you how to use XCP blocks to directly acquire measurement values from a slave in Simulink®. It uses an XCP slave simulator available for free download from Vector, and Vector Virtual CAN channels. Vehicle Network Toolbox™ provides Simulink blocks for acquiring measurement values from a slave via Simulink models over Controller Area Networks (CAN).
11 XCP Communications in Simulink 3 Download and install the available version of "XCP Sample Implementation". 4 In MATLAB, navigate to where you installed the sample package, and then go to . \Samples\XCPSim\CANape. 5 The MATLAB XCP examples will use the XCPSIM.a2l file and the XCPsim.exe slave simulator. Run XCPsim.exe. Setting up XCP Block Parameters Create a model to set up XCP data acquisition for the measurements, Triangle and PWM, from the slave.
XCP Data Acquisition over CAN Visualize Measurement Values Received From Slave Plot the results to see the measurement values for Triangle and PWM from the slave. The X-axis corresponds to the simulation timestep.
12 Functions — Alphabetical List
12 Functions — Alphabetical List 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.
attachDatabase More About 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.
12 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 combination of the device type and a device index, such as 'CANCaseXL 1'.
canChannel devicechannelindex An alpha-numeric channel on the specified device. canch The CAN channel object the you create. Properties CAN Channel Properties CAN Device Properties Bit Timing Properties Examples canch canch canch canch = = = = canChannel('Vector','CANCaseXL 1',1) canChannel('Vector','Virtual 1',2) canChannel('NI', 'CAN1') canChannel('PEAK-System', 'PCAN_USBBUS1') Notes You cannot use the same variable to create multiple channels sequentially.
12 Functions — Alphabetical List • Use canHWInfo to obtain a list of available devices.
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.
12 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 Handle that will hold the results of canHWInfo.
canHWInfo See Also canChannel 12-9
12 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. message = canMessage(database, messagename) constructs a message using the message definition of the specified message, in the specified database.
canMessage Output Arguments message The message object returned from the function. Properties Examples To construct a CAN message, type: message = canMessage(2500, true, 4) To construct a message using CAN database message definitions, create a database object using the canDatabase function, and then construct your message: candb = canDatabase('c:\database.
12 Functions — Alphabetical List canMessageImport Import CAN message log file from third-party tool Syntax message = canMessageImport('file', 'vendor') message = canMessageImport('file', 'vendor', database) Description message = canMessageImport('file', 'vendor') allows you to import a CAN message log file, file, from a third-party vendor, vendor, into Vehicle Network Toolbox. All the messages in the log file are imported as CAN messages, compatible with MATLAB and displayed as an array.
canMessageImport Output Arguments message The message object returned by the function. Examples To import a log file, type: message = canMessageImport('MsgLog.asc', 'Vector') To specify a database name, type: database = canDatabase('myDatabase.dbc') message = canMessageImport('MsgLog.txt', 'Kvaser', database) More About Tips • You can import message logs only in certain file formats. You can import only ASCII files from Vector and text files from Kvaser.
12 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.
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. For more information about the Bus Monitor, refer to “Monitor Vehicle CAN Bus”.
12 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.
configBusSpeed tseg2 The length of time at the end of the sample point within a bit time. numberofsamples The specified count of bit samples used.
12 Functions — Alphabetical List 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 CAN channel that you want to discard the messages from. Examples Set up a CAN channel to receive messages and discard the messages received by the channel.
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.
12 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.
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.
12 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.
extractTime extractTime Select messages occurring within specified time range from array of messages Syntax extracted = extractTime(message, starttime, endtime, msgRange) Description extracted = extractTime(message, starttime, endtime, msgRange) 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 An array of CAN message objects.
12 Functions — Alphabetical List Examples msgRange = extractTime(message, 5, 10.5) msgRange = extractTime(message, 0, 60) msgRange = extractTime(message, 150, Inf) More About 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.
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 The CAN channel on which you want to filter messages. type The identifier type by which to filter. CAN messages are 'Standard' and 'Extended'.
12 Functions — Alphabetical List 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. filterAllowOnly(canch,ids,type) configures the filter on the channel canch, to pass only messages of the specified type with the specified identifier.
filterAllowOnly 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: canch = canChannel('Vector','CANCaseXL 1',1); canch.Database = canDatabase('candatabase.
12 Functions — Alphabetical List 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 The CAN channel on which you want to filter messages. type The identifier type by which to filter messages. CAN messages are 'Standard' and 'Extended'.
filterAcceptRange filterAcceptRange Set range of CAN identifiers to pass acceptance filter Note: filterAcceptRange has been removed. Use filterAllowAll, filterAllowOnly, or filterBlockAll instead. Syntax filterAcceptRange(canch, rangestart, rangeend) Note: You cannot set filters on an NI device channel. 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.
12 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.
filterBlockRange filterBlockRange Set range of CAN identifiers to block via acceptance filter Note: filterBlockRange has been removed. Use filterAllowAll, filterAllowOnly, or filterBlockAll instead. Syntax filterBlockRange(canch, rangestart, rangeend) Note: You cannot set filters on an NI device channel. 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.
12 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) More About 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.
filterReset filterReset Open CAN message acceptance filters Note: filterReset has been removed. Use filterAllowAll, filterAllowOnly, or filterBlockAll instead. Syntax filterReset(canch) Note: You cannot set filters on an NI device channel. 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.
12 Functions — Alphabetical List canch = canChannel('Vector','CANCaseXL 1',1) filterBlockRange(canch, 500, 750) filterAcceptRange(canch,600,625) filterAcceptRange(canch,705,710) filterBlockRange(canch,1075,1080) filterSet(canch, 500, 750, 'Standard') filterReset(canch) See Also filterAcceptRange | filterSet | filterBlockRange 12-34
filterSet filterSet Set specific CAN message acceptance filter configuration Note: filterSet has been removed. Use filterAllowAll, filterAllowOnly, or filterBlockAll instead. Syntax filterSet(canch, code, mask, idtype) filterSet(canch, id, idtype) Note: You cannot set filters on an NI device channel. 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.
12 Functions — Alphabetical List mask The bits in the identifier that are relevant to the filter. id Set a filter on the CAN message with the id, range of ids, multiple ranges of ids, or a combination of ids. idtype A string specifying either a standard or an extended CAN message id type.
messageInfo messageInfo Information about CAN messages Syntax msgInfo = messageInfo(candb) msgInfo = messageInfo(candb, msgName) msgInfo = messageInfo(candb, id, extended) Description msgInfo = messageInfo(candb) returns information about CAN messages in the specified database candb. msgInfo = messageInfo(candb, msgName) returns information about the specified message 'msgName' in the specified database candb.
12 Functions — Alphabetical List Output Arguments msgInfo Handle for the returned CAN messages in the specified database. Examples candb = msgInfo msgInfo msgInfo canDatabase('c:\Database.
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 The value of the signal you specify to be packed in the message. startbit The signal's starting bit in the data.
12 Functions — Alphabetical List Examples pack(message, 25, 0, 16, 'LittleEndian') See Also canMessage | extractAll | extractRecent | unpack | extractTime 12-40
receive receive Receive messages from CAN bus Syntax message = receive(canch, messagesrequested) Description message = receive(canch, messagesrequested) returns an array of CAN message objects 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.
12 Functions — Alphabetical List Properties Receive Message Properties Error Log Properties Examples canch = canChannel('Vector','CANCaseXL 1',1) start(canch) message = receive(canch,5) To receive all messages, type: message = receive(canch,Inf) See Also canChannel | canMessage | transmit 12-42
replay 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 To understand the elements of a message, refer to canMessage. Input Arguments canch The CAN channel that you specify to transmit the messages. message An array of message objects to replay.
12 Functions — Alphabetical List ch2 = canChannel('Vector', 'CANcaseXL 1', 2) start(ch1) start(ch2) msgTx1 = canMessage(500, false, 8) msgTx2 = canMessage(750, false, 8) %The first channel transmits messages 2 seconds apart transmit(ch1, msgTx1) pause(2) transmit(ch1, msgTx2) %The second channel receives them msgRx1 = receive(ch2, Inf) %The replay function retransmits the messages with the original delay.
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.
12 Functions — Alphabetical List extended Indicates whether the message ID is in standard or extended type. The Boolean value is true if extended and false if standard. signalName The name of the specific signal that you want information about. Output Arguments SigInfo The signal information object returned from the function.
start 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: • You call stop on this channel. • The channel clears from the workspace.
12 Functions — Alphabetical List 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.
transmit transmit Send CAN messages to CAN bus Syntax transmit(canch, message) Description transmit(canch, message) sends the array of messages onto the bus via the CAN channel. To understand the elements of a message, refer to canMessage. Input Arguments canch The CAN channel that you specify to transmit the message. message The message or an array of messages that you specify to transmit via a CAN channel. Examples message = canMessage (250, false, 8) message.
12 Functions — Alphabetical List To transmit messages on a remote frame, type: message = canMessage(250, false 8, true) message.Data = ([45 213 53 1 3 213 123 43]) message.Remote = true canch = canChannel('Vector','CANCaseXL 1', 1) start(canch) transmit(canch, message) More About Tips The Transmit function ignores the Timestamp property and the Error property.
transmitConfiguration 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. For more information on periodic transmit of messages, refer to transmitPeriodic. For more information on event-based transmit of messages, refer to transmitEvent.
12 Functions — Alphabetical List transmitConfiguration(canch) The function returns information about periodic configuration: Periodic Messages ID Extended Name Data Rate (seconds) --- -------- ---- ---------------- -------------750 false 0 0 0 0 0 0 0 0 1.
transmitEvent 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.
12 Functions — Alphabetical List 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.
transmitPeriodic 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. transmitPeriodic(canch, msg, 'Off') disables periodic transmit of the message, msg, on the channel, canch.
12 Functions — Alphabetical List 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.
unpack 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.
12 Functions — Alphabetical List Output Arguments value The value of the message that you specify to be unpacked.
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 Create an A2L file object. a2lfile = xcpA2L('XCPSIM.a2l') • “Inspect the Contents of an A2L File” Input Arguments filename — A2L file name character string A2L file name, specified as a string. You must provide the file ending .
12 Functions — Alphabetical List See Also getEventInfo | getMeasurementInfo 12-60
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.
12 Functions — Alphabetical List Input Arguments a2lFile — Name of A2L file character string Name of the A2L file object, specified as a string, used in this connection. Create the A2L file handle using xcpA2L. eventName — XCP event name character string XCP event name specified as a string. Event name corresponds to the XCP event defined in your A2L file. Make sure the name matches the name specified in the A2L file.
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.
12 Functions — Alphabetical List SizeInNibbles: 2 SizeInBits: 8 MATLABType: 'uint8' • “Inspect the Contents of an A2L File” Input Arguments a2lFile — Name of A2L file character string Name of the A2L file object, specified as a string, used in this connection. Create the A2L file handle using xcpA2L. measurementName — Name of single XCP measurement character string Name of a single XCP measurement, specified as a string. Measurement name corresponds to the measurement name defined in your A2L file.
xcpChannel 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) create a channel connected to the CAN bus via the specified transport layer, vendor and device and a defined interface number. The XCP channel accesses the slave module via the specified CAN bus and parsing the attached A2L file.
12 Functions — Alphabetical List Create an XCP channel. xcpch = xcpChannel(a2l, 'CAN', 'Vector', 'Virtual 1', 1) xcpch = Channel with properties: SlaveName: A2LFileName: TransportLayer: TransportLayerDevice: SeedKeyCallbackFcn: KeyValue: 'CPP' 'XCPSIM.a2l' 'CAN' [1x1 struct] [] [] Create an XCP Channel on a National Instruments Device Input Arguments a2lFile — Name of A2L file character string Name of the A2L file object, specified as a string, used in this connection.
xcpChannel Device name and defined interface number for the device, specified as a string. 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 — Device to connect to character string Device on the interface you want to connect to, specified as a string. deviceChannelIndex — Index of channel on the device numeric value Index of channel on the device, specified as a number.
12 Functions — Alphabetical List 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. Link an A2L file to use to create an XCP channel a2lfile = xcpA2L('XCPSIM.
connect 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.
12 Functions — Alphabetical List 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. Link an A2L file a2l = xcpA2L('XCPSIM.
disconnect Disconnect the channel and check if connection is active. disconnect(xcpch) isConnected(xcpch) ans = 0 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.
12 Functions — Alphabetical List 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 Create a new XCP channel and see if it is connected. a2l = xcpA2L('XCPSIM.
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.
12 Functions — Alphabetical List Connect the channel to the slave module. connect(xcpch) Setup a data acquisition measurement list with the ‘10 ms’ event and 'Triangle' measurement. createMeasurementList(xcpch, 'DAQ', '10 ms', 'Triangle'); Create a Data Stimulation List 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.
createMeasurementList resource — Measurements list type ‘DAQ’ | ‘STIM’ Measurement list type, specified as a literal string ‘DAQ’ or ‘STIM’. eventName — Name of event character string Name of event, specified as a string. The event is used to trigger the specified measurement list. The list of available events depends on your A2L file.
12 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 two data acquisition lists and remove them. Create an object to parse an A2L file and connect that to an XCP channel. a2lfile = xcpA2L('XCPSIM.
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 Free the measurement lists. freeMeasurementLists(xcpch) Input Arguments xcpch — XCP channel XCP channel object XCP channel, specified as an XCP channel object created using xcpChannel.
12 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.
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. createMeasurementList(xcpch, 'DAQ', '100ms', {'PWMFiltered','Triangle'}); view details of the measurement list. viewMeasurementLists(xcpch) DAQ List #1 using the "10 ms" event @ 0.
12 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.
startMeasurement Setup a data acquisition measurement list with the ‘10 ms’ event and 'Bitslice' measurement. createMeasurementList(xcpch, 'DAQ', '10 ms', 'BitSlice') Start your measurement. startMeasurement(xcpch); Start a STIM 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.
12 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.
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.
12 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); Stop your measurement. stopMeasurement(xcpch); Input Arguments xcpch — XCP channel XCP channel object XCP channel, specified as an XCP channel object created using xcpChannel.
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. Create an XCP channel with a CAN slave module. a2l = xcpA2L('XCPSIM.
12 Functions — Alphabetical List ans = 1 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.
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.
12 Functions — Alphabetical List Create a measurement list with the '100ms' event and 'PMW', 'PWMFiltered', and 'Triangle' measurements. createMeasurementList(xcpch, 'DAQ', '100ms', {'PMW','PWMFiltered','Triangle'}) Start the measurement. startMeasurement(xcpch) Acquire data for the 'Triangle' measurement for 5 counts.
readDAQListData Output Arguments value — Value from specified measurement numeric array Value from the specified measurement, returned as a numeric array.
12 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' event’s 'Triangle' measurement.
writeSTIMListData writeDAQListData(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. measurementName — Name of single XCP measurement character string Name of a single XCP measurement, specified as a string. Measurement name corresponds to the measurement name defined in your A2L file.
12 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.
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. measurementName — Name of single XCP measurement character string Name of a single XCP measurement, specified as a string. Measurement name corresponds to the measurement name defined in your A2L file.
12 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.
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. measurementName — Name of single XCP measurement character string Name of a single XCP measurement, specified as a string. Measurement name corresponds to the measurement name defined in your A2L file.
12 Functions — Alphabetical List CAN.ChannelInfo class Package: CAN Display device channel information 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 Device channel index specified as a numeric value. Properties Device Name of the device. DeviceChannelIndex Index number of the specified device channel.
CAN.ChannelInfo class Examples Examine Kvaser Device Channel Information Get information on installed CAN devices.
12 Functions — Alphabetical List CAN.VendorInfo class Package: CAN Display available device vendor information Syntax info = canHWInfo info.VendorInfo(index) Description info = canHWInfo creates an object with information of all available CAN hardware devices. info.VendorInfo(index) displays available vendor information obtained from canHWInfo for the device with the specified index. Input Arguments index — Device channel index numeric value Device channel index specified as a numeric value.
CAN.VendorInfo class VendorDriverVersion Version of the device driver installed for this vendor. ChannelInfo Information on the device channels available for this vendor. Examples Examine Kvaser Vendor Information Get information on installed CAN devices.
12 Functions — Alphabetical List ChannelInfo See Also Functions CAN.
13 Properties — Alphabetical List
13 Properties — Alphabetical List BusLoad Display 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%.
BusSpeed BusSpeed Display speed of CAN bus Description The BusSpeed property determines the bit rate at which messages are transmitted. You can set BusSpeed to an acceptable bit rate using the configBusSpeed function. Characteristics Usage CAN channel Read only Always Data type Numerical Values The default value is assigned by the vendor driver. To change the bus speed of your channel, use the configBusSpeed function and pass the channel name and the value as input parameters.
13 Properties — Alphabetical List Properties NumOfSamples, SJW, TSEG1, TSEG2 13-4
BusStatus BusStatus Determine status of CAN bus Description The BusStatus property displays information about the state of the CAN bus.
13 Properties — Alphabetical List Data Set CAN message data Description Use the Data property to define your message data in a CAN message. Characteristics Usage CAN message 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 To load data into a message, type: message.
Database 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.
13 Properties — Alphabetical List can use a period sign in your database name. Rename any CAN database files with nonalphanumeric characters before you use them.
Device Device Display CAN 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 channel is connected. Characteristics Usage CAN channel Read only Always Data type String Values Values are automatically defined when you configure the channel with the canChannel function.
13 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 String Values Values are automatically defined when you configure the channel with the canChannel function.
DeviceChannelIndex DeviceChannelIndex Display CAN device channel index Description The DeviceChannelIndex property displays the channel index on which the selected CAN channel is configured. Characteristics Usage CAN channel Read only Always Data type Numeric Values Values are automatically defined when you configure the channel with the canChannel function.
13 Properties — Alphabetical List DeviceSerialNumber Display CAN device serial number Description The DeviceSerialNumber property displays the serial number of the CAN device. Characteristics Usage CAN channel Read only Always Data type • Numeric • Hexadecimal String (NI CAN devices only) Values Values are automatically defined when you configure the channel with the canChannel function.
DeviceVendor DeviceVendor Display device vendor name Description The DeviceVendor property displays the name of the device vendor. Characteristics Usage CAN channel Read only Always Data type String Values Values are automatically defined when you configure the channel with the canChannel function.
13 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.
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).
13 Properties — Alphabetical List Properties ID 13-16
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: • 0 through 2047 for a standard identifier • 0 through 536,870,911 for an extended identifier You can also specify a hexadecimal value using the hex2dec function.
13 Properties — Alphabetical List Properties Extended 13-18
InitializationAccess InitializationAccess Determine control of device channel Description The InitializationAccess property determines if the configured CAN 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.
13 Properties — Alphabetical List MessageReceivedFcn Specify function to run Description Configure MessageReceivedFcn as a callback function to run a string expression, a function handle, or a cell array when a specified number of messages are available. The MessageReceivedFcnCount property defines the number of messages available before the configured MessageReceivedFcn runs. Characteristics Usage CAN channel Read only Never Data type Callback function Values The default value is an empty string.
MessageReceivedFcn Properties MessageReceivedFcnCount, MessagesAvailable 13-21
13 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 Usage CAN channel Read only While channel is online Data type Double Values The default value is 1. You can specify a positive integer for your MessageReceivedFcnCount. Examples canch.
Messages Messages Store message names from CAN database Description The Messages property stores the names of all messages defined in the selected CAN database. Characteristics Usage CAN database Read only Always Data type String Values The Messages property displays a cell array of strings. You cannot edit this property.
13 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.
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.
13 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.
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 String Values Name is a string value. This value is acquired from the name of the database file. You cannot edit this property.
13 Properties — Alphabetical List Name (Message) CAN message name Description The Name (Message) property displays the name of the message. Characteristics Usage CAN message Read only Always Data type String Values Name is a string value. This value is acquired from the name of the message you defined in the database. You cannot edit this property if you are defining raw messages.
NumOfSamples 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.
13 Properties — Alphabetical List Path Display CAN database directory path Description The Path property displays the path to the CAN database. Characteristics Usage CAN database Read only Always Data type String Values The path name is a string value, pointing to the CAN database in your directory structure.
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.
13 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.
Running Running Determine status of CAN channel Description The Running property displays information about the state of the CAN channel. Characteristics Usage CAN channel Read only Always Data type Boolean Values • {false} — The channel is offline. • true — The channel is online. Use the start function to set your channel online.
13 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.
SilentMode See Also Functions canChannel 13-35
13 Properties — Alphabetical List Signals Display physical signals defined in CAN message Description The Signals property allows you to view and edit signal values defined for a CAN message. This property displays an empty structure if the message has no defined signals or a CAN database is not attached to the message. The input values for this property depends on the signal type.
Signals See Also Functions canMessage, canDatabase 13-37
13 Properties — Alphabetical List SJW Display synchronization jump width (SJW) of bit time segment Description In order to adjust the on-chip bus clock, the CAN controller may shorten or prolong the length of a bit by an integral number of time segments. The maximum value of these bit time adjustments are termed the synchronization jump width or SJW. Note: This property is not available for National Instruments CAN devices. The channel displays NaN for the value.
Timestamp Timestamp 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.
13 Properties — Alphabetical List TransceiverName Display name of CAN transceiver Description The CAN transceiver translates the digital bit stream going to and coming from the CAN bus into the real electrical signals present on the bus. Characteristics Usage CAN channel Read only Always Data type String Values Values are automatically defined when you configure the channel with the canChannel function.
TransceiverState TransceiverState Display state or mode of CAN transceiver Description If your CAN transceiver allows you to control its mode, you can use the TransceiverState property to set the mode. Characteristics Usage 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.
13 Properties — Alphabetical List Properties TransceiverName 13-42
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.
13 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.
TSEG2 TSEG2 Display amount that channel can shorten sample time Description The TSEG2 property displays the amount 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 Read only Always Data type Double Values The value is inherited when you configure the bus speed of your CAN channel.
13 Properties — Alphabetical List UserData Enter custom data Description Use the UserData property to enter custom data to be stored in your CAN channel, message, or database object. When you save an object with UserData specified, you automatically save the custom data. When you load an object with UserData specified, you automatically load the custom data. Note: To avoid unexpected results when you save and load an object with UserData, specify your custom data in simple data types and constructs.
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 strings that correspond to the names of events in the A2L file. To use the A2L file events, see “Access Event Information”.
13 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 strings that correspond to the names of measurements in the A2L file. To use the A2L file measurements see “Access Measurement Information”.
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.
13 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 string.
FileName FileName Name of referenced A2L file Description The FileName property displays the name of the referenced A2L file as a string.
13 Properties — Alphabetical List FilePath Path of A2L file Description The FileName property displays the full file path to the A2L file as a string.
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.
13 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.
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.
13 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.
TransportLayer TransportLayer Transport layer type Description The TransportLayer property displays the type of transport layer used in the XCP connection.
13 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 Block Reference CAN Configuration CAN Log CAN Pack CAN Receive CAN Replay CAN Transmit CAN Unpack XCP Configuration XCP Data Acquisition XCP Data Stimulation XCP CAN Transport Layer XCP CAN TL Receive XCP CAN TL Transmit
14 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.
CAN Configuration Dialog Box Use the Block Parameters dialog box to select your CAN device configuration. Device Select the CAN device and a channel on the device that you want to use from the list. Use this device to transmit and/or receive messages. The device driver determines the default bus speed. Bus speed Set the bus speed property for the selected device. The default bus speed is the default assigned by the selected device.
14 Block Reference Synchronization jump width, Time segment 1, Time segment 2, and Number of samples. If you do not select this option, the device automatically assigns the bit parameters depending on the bus speed setting. Tip Use the default bit parameter settings unless you have specific timing requirements for your CAN connection. Synchronization jump width Specify the maximum value of the bit time adjustments. The specified value must be a positive integer.
CAN Configuration 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.
14 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.
CAN Log Other Supported Features The CAN Log block supports the use of Simulink Accelerator and Rapid Accelerator mode. Using this feature, you can speed up the execution of Simulink models. For more information on this feature, see the Simulink documentation. 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 14-7.
14 Block Reference another machine and the source code in the zip file can be built to create an executable which can be run independent of MATLAB and Simulink. The generated code compiles with both C and C++ compilers. For more information on packNGo, see packNGo. Dialog Box Use the Block Parameters dialog box to configure your message logging. Tip If you are logging from the network, you need to configure your CAN channel with a CAN Configuration block.
CAN Log The model appends the log file name with the current date and time in the YYYYMMM-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.
14 Block Reference CAN Pack Pack individual signals into CAN message Library CAN Communication Embedded Coder/ Embedded Targets/ Host 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.
CAN Pack • The use of model referencing. Using this feature, your model can include other Simulink models as modular components. • Code generation using Simulink Coder to deploy models to targets. Note: Code generation is not supported if your signal information consists of signed or unsigned integers greater than 32-bits long. For more information on these features, see the Simulink documentation. Dialog Box Use the Function Block Parameters dialog box to select your CAN Pack block parameters.
14 Block Reference 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.
CAN Pack CANdb file This option is available if you specify that your data is input via a CANdb file in the Data is input as list. Click Browse to find the CANdb file on your system. The message list specified in the CANdb file populates the Message section of the dialog box. The CANdb file also populates the Signals table for the selected message. Note: File names that contain non-alphanumeric characters such as equal signs, ampersands, and so forth are not valid CAN database file names.
14 Block Reference 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.
CAN Pack 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.
14 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.
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.
14 Block Reference • Standard: The signal is packed at each timestep. • Multiplexor: The Multiplexor signal, or the mode signal is packed. You can specify only one Multiplexor signal per message. • Multiplexed: The signal is packed if the value of the Multiplexor signal (mode signal) at run time matches the configured Multiplex value of this signal. For example, a message has four signals with the following types and values.
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 14-19 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.
14 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.
CAN Receive Other Supported Feature The CAN Receive block supports the use of Simulink Accelerator mode. Using this feature, you can speed up the execution of Simulink models. For more information on this feature, see the Simulink documentation. 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 14-7.
14 Block Reference which can be run independent of MATLAB and Simulink. The generated code compiles with both C and C++ compilers. For more information on packNGo, see packNGo. Dialog Box Use the Source Block Parameters dialog box to select your CAN Receive block 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.
CAN Receive • Allow all: allows all standard IDs to pass the filter. This is the default filter state of the CAN Receive block • Allow only: Allows only ID or range of IDs specified in the text field. You can specify a single ID or an array of IDs. You can also specify disjointed IDs or arrays separated by a comma. For example, to accept IDs from 400 through 500 and 600 through 650, enter [[400:500] [600:650]]. Standard IDs must be a positive integer from 0 through 2047.
14 Block Reference for every message delivered to the model for that particular timestep. The output port always contains one CAN message at a time.
CAN Replay 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 Basic CAN Message Replay and Logging example for information.
14 Block Reference Other Supported Features The CAN Replay block supports the use of Simulink Accelerator Rapid Accelerator mode. Using this feature, you can speed up the execution of Simulink models. For more information on this feature, see the Simulink documentation. 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 14-7.
CAN Replay another machine and the source code in the zip file can be built to create an executable which can be run independent of MATLAB and Simulink. The generated code compiles with both C and C++ compilers. For more information on packNGo, see packNGo. Dialog Box Use the Source Block Parameters dialog box to select your message replay options. Tip Configure your CAN Configuration block before you configure the CAN Receive block parameters.
14 Block Reference 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.
CAN Transmit 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.
14 Block Reference 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 successfully in Accelerator, Rapid Accelerator, External, and Deployed modes.
CAN Transmit Dialog Box Use the Sink Block Parameters dialog box to select your CAN Transmit block parameters. Tip Configure your CAN Configuration block before you configure the CAN Transmit block parameters. Device Select the CAN device and a channel on the device to use to transmit CAN messages to the network. This list shows all the devices installed on the system. It displays the vendor name, the device name, and the channel ID. The default is the first available device on your system.
14 Block Reference See Also CAN Configuration, CAN Pack 14-32
CAN Unpack CAN Unpack Unpack individual signals from CAN messages Library CAN Communication Embedded Coder/ Embedded Targets/ Host 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.
14 Block Reference • The use of model referencing. Using this feature, your model can include other Simulink models as modular components. • Code generation using Simulink Coder to deploy models to targets. Note: Code generation is not supported if your signal information consists of signed or unsigned integers greater than 32-bits long. For more information on these features, see the Simulink documentation.
CAN Unpack 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.
14 Block Reference 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.
CAN Unpack 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. Note: File names that contain non-alphanumeric characters such as equal signs, ampersands, and so forth are not valid CAN database file names.
14 Block Reference 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. Signals Table This table appears if you choose to specify signals manually or define signals using a CANdb file.
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.
14 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.
CAN Unpack • Standard: The signal is unpacked at each timestep. • Multiplexor: The Multiplexor signal, or the mode signal is unpacked. You can specify only one Multiplexor signal per message. • Multiplexed: The signal is unpacked if the value of the Multiplexor signal (mode signal) at run time matches the configured Multiplex value of this signal. For example, a message has four signals with the following values.
14 Block Reference Specify the Offset value applied to convert the physical value (signal value) to the unpacked raw value. See “Conversion Formula” on page 14-43 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 14-43 to understand how unpacked raw values are converted to physical values.
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.
14 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.
XCP Configuration Config name Specify a unique name for your XCP session. A2L File Click Browse to select an A2L file for your XCP session. Enable seed/key security Select this option if your slave requires a secure key to establish connection. You need to select a file that contains the seed/key definition to enable the security. File (*.DLL) This field is enabled if you select Enable seed/key security.
14 Block Reference XCP Data Acquisition Acquire selected measurements from configured slave 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.
XCP Data Acquisition 14-47
14 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 configuration’s A2L file. Note: You can acquire measurements for only one event using an XCP Data Acquisition block. Use one block each for each event whose measurements you want to acquire.
XCP Data Acquisition Toggle buttons Use the toggle buttons to reorder the selected measurements. 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 Data Acquisition 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.
14 Block Reference XCP Data Stimulation Perform data stimulation on selected measurements 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.
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.
14 Block Reference a configuration displays events and measurements available in this configuration’s A2L file. Note: You can stimulate measurements for only one event using an XCP Data Stimulation block. Use one block each for each event whose measurements you want to stimulate. Event name Select an event from the available list of events. The XCP Configuration block uses the specified A2L file to populate the events list. Measurements Search Type the name of the measurement you want to use.
XCP CAN Transport Layer XCP CAN Transport Layer Transport XCP messages via CAN Library Vehicle Network Toolbox: CAN Communication Vehicle Network Toolbox: XCP 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.
14 Block Reference Device + 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.
XCP CAN TL Receive XCP CAN TL Receive Receive XCP messages via CAN device Description The XCP CAN Transport Layer Receive block receives XCP messages from a CAN Receive block. Other Supported Features The XCP CAN TL Receive block supports the use of Simulink Accelerator and Rapid Accelerator mode. Using this feature, you can speed up the execution of Simulink models. For more information on this feature, see the Simulink documentation.
14 Block Reference 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).
XCP CAN TL Transmit XCP CAN TL Transmit Transmit queued XCP Messages Description The XCP CAN Transport Layer Transmit block connects to a CAN Transmit block to transmit queued XCP messages. Other Supported Features The XCP CAN TL Transmit block supports the use of Simulink Accelerator and Rapid Accelerator mode. Using this feature, you can speed up the execution of Simulink models. For more information on this feature, see the Simulink documentation.
14 Block Reference 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.