Main Content

Perform XCP Data Acquisition in Simulink

This example shows you how to use XCP blocks to acquire measurement values in Simulink® from the XCP Sample server. The XCP Sample Server is specially designed for XCP examples only.

Vehicle Network Toolbox™ provides XCP blocks for interfacing with a server over multiple transport layers including Controller Area Networks (CAN), Controller Area Network Flexible Data-Rate (CAN FD) and User Datagram Protocol (UDP). This example uses the XCP CAN Configuration, XCP CAN Data Acquisition, and XCP CAN Transport Layer blocks to perform data transfer over the CAN protocol.

XCP is a high-level protocol used for accessing and modifying internal parameters and variables of a model, algorithm, or ECU. For more information, refer to the ASAM standards.

Open the A2L File

An A2L file is required to establish a connection to the XCP server. The A2L file describes all of the functionality and capability that the XCP server provides, as well as the details of how to connect to the server. Use the xcpA2L function to open the A2L file that describes the server model.

a2LInfo = xcpA2L("SampleECU.a2l")
a2LInfo = 
  A2L with properties:

   File Details
                 FileName: 'SampleECU.a2l'
                 FilePath: '/tmp/Bdoc24b_2679053_3933560/tpa5e3c087/vnt-ex11419635/SampleECU.a2l'
               ServerName: 'SampleServer'
                 Warnings: [0x0 string]

   Parameter Details
                   Events: {'Event DAQ 100ms'}
                EventInfo: [1x1 xcp.a2l.Event]
             Measurements: {'Line'  'PWM'  'Sine'}
          MeasurementInfo: [3x1 containers.Map]
          Characteristics: {'Gain'  'yData'}
       CharacteristicInfo: [2x1 containers.Map]
                 AxisInfo: [1x1 containers.Map]
            RecordLayouts: [3x1 containers.Map]
             CompuMethods: [1x1 containers.Map]
                CompuTabs: [0x1 containers.Map]
               CompuVTabs: [0x1 containers.Map]

   XCP Protocol Details
        ProtocolLayerInfo: [1x1 xcp.a2l.ProtocolLayer]
                  DAQInfo: [1x1 xcp.a2l.DAQ]
    TransportLayerCANInfo: [1x1 xcp.a2l.XCPonCAN]
    TransportLayerUDPInfo: [0x0 xcp.a2l.XCPonIP]
    TransportLayerTCPInfo: [1x1 xcp.a2l.XCPonIP]

Start the XCP Sample Server

The XCP Sample server mimics the behavior of a real XCP server in a controlled way. In this case, it serves ONLY for examples with limited functionalities. Use local SampleECU class to create the sampleServer object. A sampleServer will be created in the MATLAB® Workspace.

sampleServer = SampleECU(a2LInfo,"CAN","MathWorks","Virtual 1",1);

Open the Example Model

open_system("XCPDataAcquisitionInSimulinkExample.slx")

Setting Up XCP Block Parameters

Create a model to set up XCP data acquisition for the measurements, PWM, Sine and Line, from the Sample server.

  • Use an XCP Configuration block and select the A2L file, SampleECU.a2l.

  • Use an XCP CAN Transport Layer block and set the Device to Mathworks Virtual 1 Channel 2. The transport layer is configured to transfer XCP messages over CAN via the specified virtual channel.

  • Use XCP Data Acquisition blocks to receive selected measurements at specified events. For this example, we have selected an XCP Data Acquisition block for all three measurements.

Visualize Measurement Values Received from Server

Run the model and plot the results to see the measurement values for PWM, Sine and Line from the server. The X-axis corresponds to the simulation timestep. Initially the scope has no data output as the Sample server requires time to initialize.

demoVNTSL_XCPCANCommunication_Scope.PNG

Close the Model and Clean Up

close_system("XCPDataAcquisitionInSimulinkExample.slx")
clear sampleServer a2LInfo