![]() |
VOOZH | about |
dotnet add package SocketCANSharp --version 0.13.0
NuGet\Install-Package SocketCANSharp -Version 0.13.0
<PackageReference Include="SocketCANSharp" Version="0.13.0" />
<PackageVersion Include="SocketCANSharp" Version="0.13.0" />Directory.Packages.props
<PackageReference Include="SocketCANSharp" />Project file
paket add SocketCANSharp --version 0.13.0
#r "nuget: SocketCANSharp, 0.13.0"
#:package SocketCANSharp@0.13.0
#addin nuget:?package=SocketCANSharp&version=0.13.0Install as a Cake Addin
#tool nuget:?package=SocketCANSharp&version=0.13.0Install as a Cake Tool
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.
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);
}
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);
}
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);
}
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);
}
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!");
}
}
}
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}");
| 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. |
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 |
This package is not used by any popular GitHub repositories.