Skip to content

pankajsen29/ECUSimulator

Repository files navigation

Name:

  • ECU Simulator

Scope:

  • Automotive domain
  • Basic simulation of CAN request/response
  • CAN/CANFD tracing

Description:

  • A simple GUI application to configure request/response (CAN), where:
    • request: a CAN message to be received from tester application
    • response: a CAN message typically an ECU would send on the CAN Bus corresponding to a the request message
  • Utilizes Vector Virtual Interface, thereby removing the need of any hardwares.
  • Testable for CANFD communications too, (i.e., with payload higher than 8 bytes)

Motivation:

  • the main idea is to enable automotive tool developers perform testing without the need of physical hardwares (e.g., powerpack/ECU and the ECU interface hardware) - i.e., by simulating the ECU responses.
  • to have a simple UI unlike already available softwares in market (e.g., CANalyzer (link) or BUSMASTER (link)) for configuing the request-response pair for simulation.
  • Unlike CANalyzer:
    • no cost for the license.
    • no new programming language (CAPL (Communication Access Programming Language) is used by CANalyzer) is required to be learnt or used for simulation tests.
    • not similar to any other CAPL solutions, as for these kind of solutions would need physical hardware from Vector, thereby requiring to buy the license.
    • also, no generic CAN tracing (i.e., only the relevant ids are filtered in this tool)
  • Unlike BUSMASTER:
    • no cost for the license (though BUSMASTER is free for testing CAN communication, CANFD test feature is licensed)
    • as mentioned already, no generic CAN tracing (i.e., only the relevant ids are filtered in this tool)

Target Platform:

  • Supported OS Version: Windows 10 Version 20H1 (Build 10.0.19041.0) or above.
  • Tested in: Windows 11 Version 24H2 (OS Build 26100.4061)

Technologies, frameworks, patterns and protocols used :

  • C#. NET (Winform, WPF)
  • MVVM
  • JSON
  • Factory method pattern
  • CAN and CANFD

Prerequisites:

and download the latest version of the followings:

(1). Vector Driver Setup for Windows 10 and 11:

Install only the "Mandatory Components" (note: install the specific driver corresponding to an already available hardware interface from Vector) which include the followings and are enough for performing the tests with this application: a) Virtual CAN Bus b) Vector Hardware Config (legacy) c) Vector Hardware Manager

Note: steps are shown in the "Test Setup" section.

Used version for testing: Vector Driver Setup 25.20.0 for Windows 10 and 11

https://www.vector.com/int/en/download/vector-driver-setup-25-20-0-for-windows-10-and-11/

(2). xl-driver-library:

Install and (optionally) copy the below dlls from "C:\Users\Public\Documents\Vector\XL Driver Library 25.20.14.0\bin" to solution's 'Ref' folder for example: a) vxlapi.dll [XL Driver Library DLL. This file should be present in the folder with the application.] b) vxlapi64.dll [64 Bit version of XL Driver Library DLL. This file should be distributed with the application.] c) vxlapi_NET.dll [.NET Wrapper for .NET applications. This file should be distributed with the application.]

from which "vxlapi_NET.dll" is referenced from the project "VectorXLWrapper" and manually copied the other 2 dlls "vxlapi64.dll" and "vxlapi.dll" to the build "Output" folder.

Note: There are no official C# code samples from Vector specifically targeting .NET 8 or higher for the XL-Driver-Library available on the public Vector website or in their documentation as of now. The official Vector XL-Driver-Library package includes a .NET wrapper (vxlapi_NET) and C# samples (local paths are given below), but these are generally based on older .NET versions (such as .NET Framework or .NET Core 3.x). However, the .NET wrapper is compatible with .NET 3.5 and above, therefore I have used it in this .NET 8 project application.

Referred version: XL Driver Library 25.20.14

API documentations:

Factsheet:

.NET samples can be referred here:

  • CAN: C:\Users\Public\Documents\Vector\XL Driver Library 25.20.14.0\samples\NET\xlCANdemo_Csharp
  • CANFD: C:\Users\Public\Documents\Vector\XL Driver Library 25.20.14.0\samples\NET\xlCANFDdemo_Csharp

Overall Projects Description:

  • ECUSim: The is the main GUI host application. It is a Winform application which also supports addition of WPF projects (notice "True" in ECUSim.csproj file).

    • winforms: used for faster development.
    • wpf: is used for rich GUI (MVVM pattern is followed)
  • CommonHwLib: This is the main layer for hardware communication. It includes the wrapper classes for hardware drivers. handles the driver initialization and communication (sending/receiving of CAN messages)

  • HwSettingsLib: includes definitions of common types used for hardware communication. Also includes the definition of CAN data used for wrapping Tx/Rx CAN message details.

  • HwWrapperFactory: includes the factory classes for returning the concrete object of the hardware wrapper/driver library.

  • HwWrapperInterface: interface for Hardware wrapper library.

  • VectorXLWrapper: vector hardware wrapper/driver library which implements the methods for vector driver initialization, transmitting/receiving messages etc.

  • MessageDesignerLib: includes the types used for defining a message to be transmitted. Also includes the functionalities for configuring messages.

  • MessageProcessorLib: includes the functionalities to process a request message and prepare a response message.

  • WPFHostLib (Windows Forms Class Library): contains an ElementHost control to load a WPF view in winform application. This one library is used for loading all the WPF views created in this whole application. With this approach including multiple ElementHost controls is avoided in the application.

To include and use ElementHost in this .NET 8 WinForms class library project: 1) Added the following properties to .csproj file to enable WPF interop:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<UseWindowsForms>true</UseWindowsForms>
		<UseWPF>true</UseWPF>
	</PropertyGroup>
</Project>

This is required for the project to reference both WinForms and WPF assemblies, including WindowsFormsIntegration.dll that contains ElementHost.

Below references are supposed to be automatically included when "true" was included in the project file:

WindowsFormsIntegration.dll

PresentationCore.dll

PresentationFramework.dll

WindowsBase.dll

But, these didn't get added automatically.

Therefore, below additional properties are added to .csproj file, to explicitly add the framework references:

<ItemGroup>
  <FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" />
  <FrameworkReference Include="Microsoft.WindowsDesktop.App.WPF" />
</ItemGroup>

2) And then add the below using:

using System.Windows.Forms.Integration; // For ElementHost
  • WPFLibBase (WPF Class Library): Library containing the interface usercontrol for all the wpf view to implement, which will be used by WPFHostLib to initialize and load the view.

  • WPFComSettingsViewLib (WPF Class Library): this is the WPF UI implementation of the "Communication Setup" tab. It includes the view for modifying the communication settings and initialization of the CAN communication.

  • WPFTraceViewLib (WPF Class Library): this is the WPF UI implementation of the "Trace" tab. It includes the view for showing the CAN trace of the communication.

  • UtilityLib: includes utility methods, e.g., json serialization/deserialization methods, HighPrecisionTimer defintion etc.

  • LoggerLib: Logger library which provides logging functionality to the application using Serilog.

Overall Projects layout:

projects_layout

Functailities:

  • todo: sequence diagram to be included

UI Screenshots:

"Request/Response Setup" tab: request-response setup tab

"Communication Setup" tab:

CAN Initialization of Vector Virtual CAN Interface: CAN_init

CANFD Initialization of Vector Virtual CAN Interface: CANFD_init

"Trace" tab: 2025-07-29_13h05_47

Test Setup:

  • Step 1: hardware setup for Vector Virtual CAN Driver (define the parameters as seen in the 'Communication Setup' screenshot above)
  • Step 2: Message setup (define the messages as seen in the 'Request/Response Setup' screenshot above)
  • Step 3: Run ECU Simulator (INSTANCE 1)
  • Step 4: Run another instance of ECU Simulator (INSTANCE 2) (this is required only for testing purpose, not required when there is an actual test client which can send Tx CAN messages on the BUS. INSTANCE 1 can then simulate the responses corresponding to the Tx messages received from the BUS)

Testing and demo screens:

  • Step 1: Follow steps as described in Test Setup, ensure "INIT/RE-INIT CAN" is green indicating the communication is set up for both the instances.

  • Step 2: In "INSTANCE 1" of the ECU Simulator, start the Transmission by clicking on "START" and stay in the Trace tab.

  • Step 3: Enable logging by clicking on "Logging" checkbox in the Trace tab.

  • Step 4: (OPTIONAL) choose Overwrite if only the unique and latest messages are to be seen on the trace.

    at this point: test_1

  • Step 5: Now in "INSTANCE 2" of the ECU Simulator, start the Transmission by clicking on "START" and stay in the Trace tab. (hint: required ONLY for testing the ECU Simulator - which is actually the INSTANCE 1)

    at this point: test_2

  • Step 6: And then in this "INSTANCE 2", enable the Test Mode by enabling the checkbox at the top: "Switch it to a Test Sender? (TX only?)" (hint: required ONLY for testing the ECU Simulator - which is actually the INSTANCE 1)

  • Notice: all CAN Tx messages configured in messagesConfig.json are sent on the CAN BUS.

    at this point: test_3

  • Also notice: in the Trace tab of "INSTANCE 1, "these Tx and the corresponding responses (i.e., the Rx) from the messagesConfig.json are seen too.

    at this point: test_4

  • with this a test cycle is complete.

  • Note: configure more messages to test.

Limitation:

  • the hardware communication code supports only Vector interfaces at the moment, hence can't be used with any other hardware interfaces (e.g., PEAK, DCI, ETAS etc.). But have plan to support in case the planned primary purpose of this tool is observed. Design is done considering this point.
  • sending of longer CAN data is possible, i.e., in terms of multiple CAN/CANFD frames using the payload parameter for the length of each frame.
  • but, currently receiving is supported for only single CAN/CANFD frame.
  • Currently each request-response pair is to be configured, responses based on a certian pattern of the request is planned to be implemented in future.

Logging:

CMD-line execution:

  • todo: for the purpose of automation

Installer:

  • todo: installer msi project to be created

About

A GUI application where a response can be configured for a specific request on the CAN BUS, thereby actually simulating the responses from an ECU on the BUS corresponding to a CAN request from an tester application.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors