DbcParserLib 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package DbcParserLib --version 1.0.6                
NuGet\Install-Package DbcParserLib -Version 1.0.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DbcParserLib" Version="1.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DbcParserLib --version 1.0.6                
#r "nuget: DbcParserLib, 1.0.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DbcParserLib as a Cake Addin
#addin nuget:?package=DbcParserLib&version=1.0.6

// Install DbcParserLib as a Cake Tool
#tool nuget:?package=DbcParserLib&version=1.0.6                

DbcParser

alternate text is missing from this package README image alternate text is missing from this package README image GitHub

Probably the first .NET DBC file parser. Includes packing and unpacking functionality for sending and receiving CAN signals.

Below is a quick preview of the extracted data using a Tesla dbc file taken from commaai/opendbc project:

Preview

Quickstart

Install the library via Nuget Packages and add at the top of your file:

using DbcParserLib;
using DbcParserLib.Model;

Parsing

Then to parse a dbc file use the static class Parser, using one oth the parsing flavours:

Dbc dbc = Parser.ParseFromPath("C:\\your_dbc_file.dbc");
Dbc dbc = Parser.ParseFromStream(File.OpenRead("C:\\your_dbc_file.dbc")); // Or a stream from network
Dbc dbc = Parser.Parse("a dbc as string");

Handling Dbc object

The Dbc object contains two collections, Messages and Nodes, both are IEnumerable<T> so can be accessed, iterated and queried using standard LINQ.

As an example, take all messages with id > 100 and more than 2 signals:

var filteredSelection = dbc
							.Messages
							.Where(m => m.ID > 100 && m.Signals.Count > 2)
							.ToArray();

Packing/Unpacking signals

Simple scenario

To pack and unpack signals you can use static class Packer Example for packing/unpacking a signal: 14 bits, Min: -61.92, Max: 101.91

Signal sig = new Signal
{
  sig.Length = 14,
  sig.StartBit = 2,
  sig.IsSigned = 1,
  sig.ByteOrder = 1, // 0 = Big Endian (Motorola), 1 = Little Endian (Intel)
  sig.Factor = 0.01,
  sig.Offset = 20
};

// This packs the signal for sending
ulong TxMsg = Packer.TxSignalPack(-34.3, sig);

// This unpacks a received signal and calculates the corresponding engineering value
double val = Packer.RxSignalUnpack(TxMsg, sig);

Multiple signals can be packed before CAN transmission using:

ulong TxMsg = 0;
TxMsg |= dbc.TxSignalPack(value1, sig1);
TxMsg |= dbc.TxSignalPack(value2, sig2);
TxMsg |= dbc.TxSignalPack(value3, sig3);
// ...
// Send TxMsg on CAN

The user needs to make sure that the signals do not overlap with each other by properly specifying the Length and StartBit.

Multiplexing

A message can contain multiplexed data, i.e. layout can change depending on a multiplexor value. The Packer class is unaware of multiplexing, so it's up to the user to check that the given message actually contains the signal. As an example, consider the following dbc lines:

BO_ 568 UI_driverAssistRoadSign: 8 GTW
 SG_ UI_roadSign M : 0|8@1+ (1,0) [0|0] ""  DAS
 SG_ UI_dummyData m0 : 8|1@1+ (1,0) [0|0] "" Vector__XXX
 SG_ UI_stopSignStopLineDist m1 : 8|10@1+ (0.25,-8) [-8|247.5] "m" Vector__XXX

Signal UI_dummyData will only be available when UI_roadSign value is 0 while UI_stopSignStopLineDist will only be available when UI_roadSign value is 1. You can access multiplexing information calling

var multiplexingInfo = signal.MultiplexingInfo();
if(multiplexingInfo.Role == MultiplexingRole.Multiplexor)
{
	// This is a multiplexor!
}
else if(multiplexingInfo.Role == MultiplexingRole.Multiplexed)
{
	Console.WriteLine($"This signal is multiplexed and will be available when multiplexor value is {multiplexingInfo.Group}");
}

You can also check is a message does contain multiplexed signals by calling the extension method

if(message.IsMultiplexed())
{
	// ...
}

Contributions

Contributions are appreciated! Feel free to create pull requests to improve this library.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.1

    • No dependencies.
  • net5.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on DbcParserLib:

Package Downloads
Ahsoka.Core.Can

Package Description

Ahsoka.Extensions.Can

Package Description

RegnoDecoder.CAN

This package facilitates the conversion of CAN dbc and trace files

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.7.0 1,266 9/6/2024
1.6.1 1,257 7/26/2024
1.6.0 2,475 4/15/2024
1.5.0 5,033 11/6/2023
1.4.2 287 10/19/2023
1.4.1 138 10/19/2023
1.4.0 439 9/27/2023
1.3.3 239 9/15/2023
1.3.2 177 9/11/2023
1.3.1 6,191 4/14/2023
1.3.0 1,304 3/25/2023
1.2.0 3,553 10/28/2022
1.0.7 595 9/30/2022
1.0.6 593 8/31/2022
1.0.5 699 3/8/2022
1.0.4 462 1/17/2022
1.0.3 241 1/3/2022
1.0.2 264 12/30/2021
1.0.1 252 12/30/2021
1.0.0 360 12/30/2021

Added Culture invariant