C# Ecu API
Collaboration diagram for C# Ecu API:

Modules

 Enumerations
 
 Events related with the Ecu alarms
 

Classes

class  DeepsyEcuManager
 Manager for access the Ecu functionalities and events raised More...
 
interface  IEcu
 Interface for Ecu service More...
 

Detailed Description

To work with Deepsy Ecu service it is necessary to use DeepsyEcuManager located in GMV.ITS.HAL.DEEPSY.Ecu.Facade for getting the initial Ecu object.

DeepsyEcuManager EcuManager = new DeepsyEcuManager("192.168.1.234");


To obtain a list of devices objects:

try
{
DeepsyEcuManager EcuManager = new DeepsyEcuManager("192.168.1.234");
IEcu Ecu = EcuManager.GetEcu().First();
}
catch (NotAvailableException e)
{
Console.WriteLine(e.Message);
}
catch (LowLevelException e)
{
Console.WriteLine(e.Message);
}

Examples

  • Get available EPIDs
    Getting all available EPIDs.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Ecu
    {
    class GetAvailableEPIDs
    {
    static void Main(string[] args)
    {
    Console.WriteLine($"Ecu. Get available EPIDs");
    try
    {
    string deepsyServerIp = args.Length == 0 ? "127.0.0.1" : args[0];
    using (DeepsyEcuManager ccuManager = new DeepsyEcuManager(deepsyServerIp))
    {
    IEcu ecu = ccuManager.GetEcu().First();
    List<string> epids = ecu.GetAvailableEPIDs().ToList();
    Console.WriteLine($"There are {epids.Count()} EPIDs");
    foreach (var e in epids)
    {
    Console.WriteLine($"\t- {e}");
    }
    }
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Error: [{ex.Message}]");
    }
    }
    }
    }


  • Get EPIDs parameters
    Getting EPIDs parameters.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Ecu
    {
    class GetEPIDs
    {
    static void Main(string[] args)
    {
    Console.WriteLine($"Ecu. Get EPIDs");
    try
    {
    string deepsyServerIp = args.Length == 0 ? "127.0.0.1" : args[0];
    using (DeepsyEcuManager ccuManager = new DeepsyEcuManager(deepsyServerIp))
    {
    IEcu ecu = ccuManager.GetEcu().First();
    List<string> epids = new List<string>() { "Engine_Temp" };
    List<IParameterDto> parameters = ecu.GetParameter(epids).ToList();
    parameters.ToList().ForEach(p => PrintParametersInfo(p));
    }
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Error: [{ex.Message}]");
    }
    }
    public static void PrintParametersInfo(IParameterDto p)
    {
    try
    {
    Console.WriteLine($"Timestamp: {p.Timestamp}");
    Console.WriteLine($"Id: {p.Id}");
    Console.WriteLine($"Value: {p.Value}");
    Console.WriteLine($"Units: {p.Units}");
    }
    catch (Exception e)
    {
    Console.WriteLine("ERROR: " + e.Message);
    }
    }
    }
    }


  • Get Protocol in use
    Getting Protocol in use.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Ecu
    {
    class GetProtocol
    {
    static void Main(string[] args)
    {
    Console.WriteLine($"Ecu. Get protocol");
    try
    {
    string deepsyServerIp = args.Length == 0 ? "127.0.0.1" : args[0];
    using (DeepsyEcuManager ccuManager = new DeepsyEcuManager(deepsyServerIp))
    {
    IEcu ecu = ccuManager.GetEcu().First();
    IProtocolDto protocol = ecu.GetCurrentProtocol();
    Console.WriteLine($"Current Protocol: {protocol.Name}");
    }
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Error: [{ex.Message}]");
    }
    }
    }
    }


  • Subscribe to events
    There are 1 type of events in the Ecu system:

    • CanMessageEvent : This event happens when can message is received. To receive this kind of events, it is necessary to subscribe to a Ecu object

    This example subscribes to every event.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Ecu
    {
    class EcuEvents
    {
    static void Main(string[] args)
    {
    Console.WriteLine($"Ecu. Events");
    try
    {
    string deepsyServerIp = args.Length == 0 ? "192.168.0.125" : args[0];
    using (IDeepsyEcuManager EcuManager = new DeepsyEcuManager(deepsyServerIp))
    {
    IEcu Ecu = EcuManager.GetEcu().First();
    Console.WriteLine("Subscribing to ECU events.");
    Ecu.CanMessageEventRaised += Ecu_CanMessageEventRaised;
    Console.WriteLine("Press ESC for exit");
    while (Console.ReadKey().Key != ConsoleKey.Escape)
    {
    }
    }
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Error: [{ex.Message}]");
    }
    }
    private static void Ecu_CanMessageEventRaised(object sender, CanMessageEvent e)
    {
    Console.WriteLine($"Ecu CanMessage event: 0x{e.Id.ToString("X")} [{e.DataSize}] {BitConverter.ToString(e.Data).Replace('-', ' ')}");
    }
    }
    }


  • CAN BUS Filter/B>
    Apply CAN BUS filters and subscribe to see the difference in the incoming messages.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Ecu
    {
    class CanBusFilters
    {
    static void Main(string[] args)
    {
    Console.WriteLine($"Ecu. CanBusFilters");
    try
    {
    string deepsyServerIp = args.Length == 0 ? "192.168.0.125" : args[0];
    using (IDeepsyEcuManager EcuManager = new DeepsyEcuManager(deepsyServerIp))
    {
    IEcu Ecu = EcuManager.GetEcu().First();
    Console.WriteLine("Subscribing to CanMessage events.");
    Ecu.CanMessageEventRaised += Ecu_CanMessageEventRaised;
    System.Threading.Thread.Sleep(1000);
    Console.WriteLine("Adding Standard Can filter. Only ID=0x233 will be received.");
    Ecu.AddStandardCanFilter(0x233);
    System.Threading.Thread.Sleep(1000);
    Console.WriteLine("Adding Extended Can filter. ID=0x18FDA521 will also be received.");
    Ecu.AddExtendedCanFilter(0x18FDA521);
    System.Threading.Thread.Sleep(1000);
    Console.WriteLine("Adding J1939 Can filter. PGN=0xFFA0 will also be received.");
    Ecu.AddJ1939CanFilter(0xFFA0);
    System.Threading.Thread.Sleep(1000);
    Console.WriteLine("Removing Extended Can filter. ID=0x18FDA521 will stop being received.");
    Ecu.RemoveExtendedCanFilter(0x18FDA521);
    System.Threading.Thread.Sleep(1000);
    Console.WriteLine("Removing all Can filter. All Can IDs will be received.");
    Ecu.ResetCanFilter();
    System.Threading.Thread.Sleep(1000);
    Console.WriteLine("Finished.");
    }
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Error: [{ex.Message}]");
    }
    }
    private static void Ecu_CanMessageEventRaised(object sender, CanMessageEvent e)
    {
    Console.WriteLine($"Ecu CanMessage event: 0x{e.Id.ToString("X")} [{e.DataSize}] {BitConverter.ToString(e.Data).Replace('-', ' ')}");
    }
    }
    }


  • Set CAN BUS Configuration/B>
    Apply CAN BUS configuration.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Ecu
    {
    class SetCanBusConfiguration
    {
    static void Main(string[] args)
    {
    Console.WriteLine($"Ecu. SetCanBusConfiguration");
    try
    {
    string deepsyServerIp = args.Length == 0 ? "192.168.1.140" : args[0];
    using (IDeepsyEcuManager EcuManager = new DeepsyEcuManager(deepsyServerIp))
    {
    IEcu Ecu = EcuManager.GetEcu().First();
    Console.WriteLine("Setting CAN BUS configuration.");
    uint BaudRate = 500000;
    if (args.Length > 1 && !UInt32.TryParse(args[1], out BaudRate))
    {
    Console.WriteLine("Error converting BaudRate to UInt.");
    return;
    }
    ICanBusConfigurationDto config = new CanBusConfigurationDto()
    {
    BaudRate = BaudRate
    };
    Ecu.SetCanBusConfiguration(config);
    Console.WriteLine("Finished.");
    }
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Error: [{ex.Message}]");
    }
    }
    private static void Ecu_CanMessageEventRaised(object sender, CanMessageEvent e)
    {
    Console.WriteLine($"Ecu CanMessage event: 0x{e.Id.ToString("X")} [{e.DataSize}] {BitConverter.ToString(e.Data).Replace('-', ' ')}");
    }
    }
    }