PEengineersCAN 0.0.8

dotnet add package PEengineersCAN --version 0.0.8
                    
NuGet\Install-Package PEengineersCAN -Version 0.0.8
                    
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="PEengineersCAN" Version="0.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PEengineersCAN" Version="0.0.8" />
                    
Directory.Packages.props
<PackageReference Include="PEengineersCAN" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PEengineersCAN --version 0.0.8
                    
#r "nuget: PEengineersCAN, 0.0.8"
                    
#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.
#:package PEengineersCAN@0.0.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PEengineersCAN&version=0.0.8
                    
Install as a Cake Addin
#tool nuget:?package=PEengineersCAN&version=0.0.8
                    
Install as a Cake Tool

PEengineersCAN

A C# library for parsing and interpreting DBC (CAN database) files, with utilities for CAN message decoding.

Features

  • Parse standard DBC file format
  • Decode CAN messages using signal definitions
  • Support for both Intel (little-endian) and Motorola (big-endian) byte orders
  • Handle signed and unsigned signals
  • Apply scaling factors and offsets to raw values

Usage Examples

Loading a DBC File

// Create a new DBC database and load definitions
var dbcDatabase = new DBCDatabase();
dbcDatabase.Load("path/to/your/file.dbc");

Decoding CAN Messages - Basic Example

// Decode a CAN message with ID 0x100 and 8-byte data
byte[] messageData = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 };
uint canId = 0x100;

// Get a dictionary of signal names and their physical values
Dictionary<string, double> decodedSignals = dbcDatabase.DecodeMessage(canId, messageData);

// Access decoded signal values
foreach (var signal in decodedSignals)
{
    Console.WriteLine($"{signal.Key}: {signal.Value}");
}

Parsing CAN Messages from Text Format

// Parse a CAN message in candump format: "(timestamp) interface id#data"
string inputLine = "(1741954078.324423) can0 00000121#5A0B017805000000";

// Remove the timestamp part
int closingParenIndex = inputLine.IndexOf(')');
string trimmedInput = inputLine.Substring(closingParenIndex + 1).Trim();

// Split to extract interface and message token
string[] tokens = trimmedInput.Split(' ', StringSplitOptions.RemoveEmptyEntries);
string[] canParts = tokens[1].Split('#');

// Parse the CAN id as hex
uint canId = Utils.SafeParse<uint>(canParts[0], hex: true);

// Parse hex string to byte array
byte[] data = Utils.HexToBytes(canParts[1]);

// Decode the message
var decodedSignals = dbcDatabase.DecodeMessage(canId, data);

Converting Hex Strings to Bytes

// Convert hex string to byte array (handles whitespace and odd-length strings)
byte[] bytes = Utils.HexToBytes("12 34 56 78 9A BC DE F0");
// Result: [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]

// With quoted string
byte[] fromQuoted = Utils.HexToBytes("\"12 34 56 78\"");
// Result: [0x12, 0x34, 0x56, 0x78]

// With odd-length string (leading zero added automatically)
byte[] fromOdd = Utils.HexToBytes("1 23 456");
// Result: [0x01, 0x23, 0x04, 0x56]

Safe Number Parsing

// Parse string to various numeric types with error handling
int intValue = Utils.SafeParse<int>("123");
double doubleValue = Utils.SafeParse<double>("45.67");
byte hexByte = Utils.SafeParse<byte>("FF", hex: true);
uint hexUint = Utils.SafeParse<uint>("DEADBEEF", hex: true);

String Extensions

// Split string with delimiter and clean results
string data = "  value1, value2,,  value3  ";
List<string> values = data.Split(',');
// Result: ["value1", "value2", "value3"]

// Null-safe trimming
string nullableString = null;
string result = nullableString.Trim(); // Returns empty string instead of throwing exception

Classes

  • DBCDatabase: Main class for loading and managing DBC definitions
  • DBCMessage: Represents a CAN message with multiple signals
  • DBCSignal: Represents a signal within a CAN message
  • Utils: Helper methods for parsing and data conversion
  • StringExtension: String manipulation utilities
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.8 241 4/1/2025
0.0.7 203 4/1/2025