VOOZH about

URL: https://www.nuget.org/packages/SocketCANSharp/

⇱ NuGet Gallery | SocketCANSharp 0.13.0




SocketCANSharp 0.13.0

dotnet add package SocketCANSharp --version 0.13.0
 
 
NuGet\Install-Package SocketCANSharp -Version 0.13.0
 
 
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="SocketCANSharp" Version="0.13.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SocketCANSharp" Version="0.13.0" />
 
Directory.Packages.props
<PackageReference Include="SocketCANSharp" />
 
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 SocketCANSharp --version 0.13.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SocketCANSharp, 0.13.0"
 
 
#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 SocketCANSharp@0.13.0
 
 
#: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=SocketCANSharp&version=0.13.0
 
Install as a Cake Addin
#tool nuget:?package=SocketCANSharp&version=0.13.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

SocketCAN# (SocketCANSharp)

SocketCAN# is a .NET managed wrapper for the Linux CAN subsystem (SocketCAN). SocketCAN# enables developers to create either object-oriented or procedural style applications that leverage SocketCAN.

Raw CAN Support

CanNetworkInterface vcan0 = CanNetworkInterface.GetAllInterfaces(true).First(iface => iface.Name.Equals("vcan0"));

using (var rawCanSocket = new RawCanSocket())
{
 rawCanSocket.Bind(vcan0);
 int bytesWritten = rawCanSocket.Write(new CanFrame(0x123, new byte[] { 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }));
 int bytesRead = rawCanSocket.Read(out CanFrame frame);
}

ISO 15765-2 (ISO-TP) Support

CanNetworkInterface vcan0 = CanNetworkInterface.GetAllInterfaces(true).First(iface => iface.Name.Equals("vcan0"));

using (var testerSocket = new IsoTpCanSocket())
{
 testerSocket.BaseOptions = new CanIsoTpOptions()
 {
 Flags = IsoTpFlags.CAN_ISOTP_TX_PADDING | IsoTpFlags.CAN_ISOTP_WAIT_TX_DONE,
 };

 testerSocket.Bind(vcan0, 0x600, 0x700);
 int bytesWritten = testerSocket.Write(new byte[] { 0x3e, 0x00 });
 var receiveBuffer = new byte[4095];
 int bytesRead = testerSocket.Read(receiveBuffer);
}

SAE J1939 Support

var vcan0 = CanNetworkInterface.GetAllInterfaces(true).FirstOrDefault(iface => iface.Name.Equals("vcan0"));

using (var j1939Socket = new J1939CanSocket())
{
 j1939Socket.EnableBroadcast = true;
 j1939Socket.SendPriority = 3;
 j1939Socket.Bind(vcan0, SocketCanConstants.J1939_NO_NAME, 0x0F004, 0x01);
 var destAddr = new SockAddrCanJ1939(vcan0.Index)
 {
 Name = SocketCanConstants.J1939_NO_NAME,
 PGN = 0x0F004,
 Address = SocketCanConstants.J1939_NO_ADDR,
 };
 j1939Socket.WriteTo(new byte[] { 0xFF, 0xFF, 0xFF, 0x6C, 0x50, 0xFF, 0xFF, 0xFF }, MessageFlags.None, destAddr);
}

Broadcast Manager (BCM) Support

CanNetworkInterface vcan0 = CanNetworkInterface.GetAllInterfaces(true).First(iface => iface.Name.Equals("vcan0"));

using (var bcmCanSocket = new BcmCanSocket())
{
 bcmCanSocket.Connect(vcan0);
 var canFrame = new CanFrame(0x333, new byte[] { 0xDE, 0xAD, 0xBE, 0xEF });
 var frames = new CanFrame[] { canFrame };
 var config = new BcmCyclicTxTaskConfiguration()
 {
 Id = 0x333,
 StartTimer = true,
 SetInterval = true,
 InitialIntervalConfiguration = new BcmInitialIntervalConfiguration(10, new BcmTimeval(0, 5000)), // 10 messages at 5 ms
 PostInitialInterval = new BcmTimeval(0, 100000), // Then at 100 ms
 };
 int nBytes = bcmCanSocket.CreateCyclicTransmissionTask(config, frames);
}

CAN Gateway (CGW) Support

var vcan0 = CanNetworkInterface.GetAllInterfaces(true).FirstOrDefault(iface => iface.Name.Equals("vcan0"));
var vcan1 = CanNetworkInterface.GetAllInterfaces(true).FirstOrDefault(iface => iface.Name.Equals("vcan1"));

using (var cgwSocket = new CanGatewaySocket())
{
 cgwSocket.ReceiveTimeout = 1000;
 cgwSocket.SendTimeout = 1000;
 cgwSocket.Bind(new SockAddrNetlink(0, 0));
 var rule = new CgwCanToCanRule(CgwCanFrameType.ClassicalCAN)
 {
 SourceIndex = (uint)vcan0.Index,
 DestinationIndex = (uint)vcan1.Index,
 EnableLocalCanSocketLoopback = true,
 ReceiveFilter = new CanFilter(0x123, 0x7FF),
 SetModifier = new ClassicalCanGatewayModifier(CanGatewayModificationType.CGW_MOD_LEN, new CanFrame(0x000, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00 })),
 ChecksumXorConfiguration = new CgwChecksumXor(0, 3, 4, 0xCC),
 UpdateIdentifier = 0xFFEEEEDD,
 };
 cgwSocket.AddOrUpdateCanToCanRule(rule);
 
 var data = new byte[8192];
 int bytesRead = cgwSocket.Read(data);
 var realData = data.Take(bytesRead).ToArray();
 NetlinkMessageHeader header = NetlinkUtils.PeekAtHeader(realData);
 if (header.MessageType == NetlinkMessageType.NLMSG_ERROR)
 {
 NetlinkMessageError nlMsgErr = NetlinkMessageError.FromBytes(realData);
 if (nlMsgErr.Error == 0)
 {
 Console.WriteLine("Successfully added CGW Rule!");
 }
 }
}

CAN Network Interface Support

CanNetworkInterface can0 = CanNetworkInterface.GetAllInterfaces(false).First(iface => iface.Name.Equals("can0"));

Console.WriteLine("Bringing Link Down...");
can0.SetLinkDown();

Console.WriteLine("Configuring Interface...");
can0.BitTiming = new CanBitTiming() { BitRate = 125000 };
can0.CanControllerModeFlags = CanControllerModeFlags.CAN_CTRLMODE_LOOPBACK | CanControllerModeFlags.CAN_CTRLMODE_ONE_SHOT;
can0.AutoRestartDelay = 5;
can0.MaximumTransmissionUnit = SocketCanConstants.CAN_MTU;

Console.WriteLine("Bringing Link Up...");
can0.SetLinkUp();

Console.WriteLine("Reading Interface Properties...");
Console.WriteLine($"Inteface Device Flags: {can0.DeviceFlags}");
Console.WriteLine($"Inteface Operational Status: {can0.OperationalStatus}");
Console.WriteLine($"Controller State: {can0.CanControllerState}");
Console.WriteLine($"Auto-Restart Delay: {can0.AutoRestartDelay} ms");
Console.WriteLine($"Bit Timing: {can0.BitTiming.BitRate} bit/s");
Console.WriteLine($"Controller Mode Flags: {can0.CanControllerModeFlags}");
Console.WriteLine($"MTU: {can0.MaximumTransmissionUnit}");

Links

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on SocketCANSharp:

Package Downloads
Ahsoka.Extensions.Can

Data Service Extension for OpenPV 5.0 // 60f365e6af3b712659435adb8e2f8c34e4c7c2f5 - OpenPV_Extension_Info { "extensionName": "CAN Service Extension", "packageName": "Ahsoka.Extensions.Can", "uxpackageName": "Ahsoka.Extensions.Can.UX", "uxViewModelName": "CanSetupViewModel", "sdkGeneratorName": "CanCodeGenerator", "serviceConfigurations": [ { "socketType": "TcpSocket", "serviceName": "CanService", "tcpListenAddress": "localhost", "tcpConnectionAddress": "localhost", "dataChannel": 6107, "configurationFile": "CanService.cancalibration.json", "behaviors": "AutoStart" } ], "hasCommands": "true", "hasUx": "true", "hasSdkGenerator": "true" }

Ahsoka.Core.Can

Package Description

Rays.Commlink

仅组织内部使用。提供串口通信、网络通信支持功能的核心库。

Ahsoka.Extensions.Control

Data Service Extension for OpenPV 5.0 // 60f365e6af3b712659435adb8e2f8c34e4c7c2f5 - OpenPV_Extension_Info { "extensionName": "Control Service Extension", "packageName": "Ahsoka.Extensions.Control", "uxpackageName": "Ahsoka.Extensions.Control.UX", "serviceConfigurations": [ { "socketType": "TcpSocket", "serviceName": "CanService", "tcpListenAddress": "localhost", "tcpConnectionAddress": "localhost", "dataChannel": 6107, "configurationFile": "CanService.cancalibration.json", "behaviors": "AutoStart" }, { "socketType": "TcpSocket", "serviceName": "IOService", "tcpListenAddress": "localhost", "tcpConnectionAddress": "localhost", "dataChannel": 6106, "behaviors": "AutoStart" } ] }

ThingSet.Common.Transports.Can

CAN transport for .NET ThingSet client

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.13.0 42,136 2/22/2025
0.12.0 4,824 11/29/2024
0.11.0 134,438 8/4/2023
0.10.0 9,825 2/3/2023
0.9.0 2,386 11/17/2022
0.8.0 3,018 9/21/2022
0.7.0 889 7/28/2022
0.6.0 4,516 5/16/2022
0.5.0 1,969 4/19/2022
0.4.0 814 3/26/2022
0.3.0 886 3/14/2022
0.2.0 955 1/10/2022