This example shows how to use XCP connections to create and use dynamic data acquisition lists. It uses a freely available XCP slave simulator from Vector and Vector virtual CAN channels. For access to virtual channels, Vector device drivers must be installed. It is also recommended to run Vehicle CAN Bus Monitor in conjunction with this example.
This example requires installing a free, third-party XCP implementation from Vector. The package includes an XCP slave simulator and A2L file. To install this driver, please follow these instructions:
Go to www.vector.com and navigate to the "DOWNLOADS" page.
Search for "Demos" under "Categories" and "XCP" under "Standards".
Download and install the available version of "XCP Sample Implementation".
In MATLAB, navigate to where you installed the sample package, and then go to .\Samples\XCPSim\CANape.
The MATLAB XCP examples will use the XCPSIM.a2l file and the XCPsim.exe slave simulator. Run XCPsim.exe.
Establishing a connection to an XCP slave requires using the A2L file that describes the slave module.
a2lObj = xcpA2L('XCPSIM.a2l')
a2lObj = A2L with properties: FileName: 'XCPSIM.a2l' FilePath: '\\central-mi\home\jpyle\documents\MATLAB\examples\vnt-ex33137552\XCPSIM.a2l' SlaveName: 'CPP' ProtocolLayerInfo: [1×1 xcp.ProtocolLayerInfo] DAQInfo: [1×1 xcp.DAQInfo] TransportLayerCANInfo: [1×1 xcp.TransportLayerCANInfo] TransportLayerUDPInfo: [1×1 xcp.TransportLayerUDPInfo] TransportLayerTCPInfo: [] Events: {1×6 cell} Measurements: {1×45 cell} Characteristics: {1×16 cell} EventInfo: [1×6 xcp.Event] MeasurementInfo: [45×1 containers.Map] CharacteristicInfo: [16×1 containers.Map] AxisInfo: [1×1 containers.Map] RecordLayouts: [41×1 containers.Map] CompuMethods: [16×1 containers.Map] CompuTabs: [0×1 containers.Map] CompuVTabs: [2×1 containers.Map]
Create an XCP channel in order to prepare a connection to the slave.
xcpCh = xcpChannel(a2lObj, 'CAN', 'Vector', 'Virtual 1', 1)
xcpCh = Channel with properties: SlaveName: 'CPP' A2LFileName: 'XCPSIM.a2l' TransportLayer: 'CAN' TransportLayerDevice: [1×1 struct] SeedKeyDLL: []
To make communication with the slave active, connect to it.
connect(xcpCh)
Create a DAQ list using one of the events specified in the A2L and assign to it some measurements defined in the A2L file.
createMeasurementList(xcpCh, 'DAQ', '10 ms', {'Triangle', 'PWM', 'channel3'})
Starting measurements begins the transmission of DAQ messages from the slave. After running for a few seconds, stop measurements.
startMeasurement(xcpCh) pause(3); stopMeasurement(xcpCh)
Receive the acquired data from the channel for each measurement.
dataTriangle = readDAQListData(xcpCh, 'Triangle');
plot(dataTriangle)
Receive the acquired data from the channel for each measurement.
dataPWM = readDAQListData(xcpCh, 'PWM');
plot(dataPWM)
Receive the acquired data from the channel for each measurement.
datachannel3 = readDAQListData(xcpCh, 'channel3');
plot(datachannel3)
To make communication with the slave inactive, disconnect from it.
disconnect(xcpCh)