{"id":17255311,"url":"https://github.com/crozone/socketcannet","last_synced_at":"2025-07-29T21:32:24.055Z","repository":{"id":163306798,"uuid":"637400872","full_name":"crozone/SocketCanNet","owner":"crozone","description":"SocketCAN library for working with Controller Area Network (CAN bus) sockets on Linux with .NET.","archived":false,"fork":false,"pushed_at":"2023-05-10T08:19:41.000Z","size":19,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-15T07:11:25.017Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crozone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-07T12:55:19.000Z","updated_at":"2024-07-16T14:53:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"1cb241b8-d1ce-4632-8ced-5778f193e136","html_url":"https://github.com/crozone/SocketCanNet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crozone%2FSocketCanNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crozone%2FSocketCanNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crozone%2FSocketCanNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crozone%2FSocketCanNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crozone","download_url":"https://codeload.github.com/crozone/SocketCanNet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228048971,"owners_count":17861474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T07:11:16.607Z","updated_at":"2024-12-04T05:23:27.228Z","avatar_url":"https://github.com/crozone.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SocketCanNet\n\nSmall SocketCAN library for working with Controller Area Network (CAN bus) sockets on Linux with .NET.\n\n## Overview\n\nThis library assists with the creation and usage of the [Controller Area Network Protocol Family (aka SocketCAN)](https://www.kernel.org/doc/Documentation/networking/can.txt) sockets available in Linux, on .NET 6 and above.\n\nIt allows for easy creation of CAN sockets, binding of CAN sockets by interface name, and sending and receiving of CAN messages using a helper class for serialization and deserialization.\n\nBoth CAN and CAN-FD are supported.\n\n## Example\n\n```csharp\n// Create the CAN socket\nSocket socket = CanSocket.CreateRawCanSocket();\n\n// (Optional) Enable CAN FD\nsocket.SetCanFdEnabled(true);\n\n// Bind the socket to the CAN interface \"can0\"\nsocket.BindToCanInterface(\"can0\");\n\n// Block until a CAN frame is received\nCanFrame canFrame = socket.ReceiveCanFrame();\n\n// (An async implementation is also available)\n// CanFrame canFrame = socket.ReceiveCanFrameAsync(cancellationToken);\n\n// Print the CAN frame ID and Payload as hex\nConsole.WriteLine($\"[{canFrame.Id}]: ({canFrame.DataLength}) {Convert.ToHexString(canFrame.PayloadSpan)}\");\n\n```\n\n## Helper methods\n\n### `CanSocket.CreateRawCanSocket()`\n\nCreates a raw `Controller Area Network` socket.\n\nEquivalent to:\n\n```csharp\nnew Socket(AddressFamily.ControllerAreaNetwork, SocketType.Raw, ProtocolType.Raw);\n```\n\n## Extension methods\n\n### `void Socket.BindToCanInterface(string interfaceName)`\n\nBinds the socket to the SocketCAN interface with the name `interfaceName`\n\n### `void Socket.SendCanFrame(CanFrame canFrame)` and `Task Socket.SendCanFrameAsync(CanFrame canFrame, CancellationToken cancellationToken)`\n\nSends the serialized `CanFrame` over the socket.\n\n### `CanFrame Socket.ReceiveCanFrame` and `Task\u003cCanFrame\u003e Socket.ReceiveCanFrameAsync(CancellationToken cancellationToken`\n\nReceives a `CanFrame` from the socket.\n\n### `void Socket.SetCanFdEnabled(bool enable)`\n\nEnables or disables CAN FD MTU frames, using the RAW socket option CAN_RAW_FD_FRAMES.\n\nThis option is disabled by default.\n\nWhen enabled, CAN_MTU and CANFD_MTU frames are allowed.\nWhen disabled, only CAN_MTU frames are allowed.\n\nOnce CAN_RAW_FD_FRAMES is enabled the application can send both CAN frames and CAN FD frames.\n\n### `void Socket.SetCanLoopback(bool enable)`\n\nEnables or disables local loopback of CAN messages on the socket, using the RAW socket option CAN_RAW_LOOPBACK.\n\nThis is enabled by default.\n\nWhen enabled, all the sent CAN frames are looped back to the open CAN sockets that registered for the CAN frames' CAN-ID on this given interface.\n\n### `void SetCanReceiveOwnMessages(bool enable)`\n\nEnables or disables receiving looped back CAN messages that originated from this socket, using the RAW socket option CAN_RAW_RECV_OWN_MSGS.\n\nThis is disabled by default.\n\n### `int Socket.GetUnixInterfaceIndex(string adapterName)`\n\nGets the index of the network interface with name `adapterName`, using the SIOCGIFINDEX `ioctl()`.\n\nThis allows the manual creation of an `EndPoint` for the given interface:\n\n```csharp\nint interfaceIndex = socket.GetUnixInterfaceIndex(interfaceName);\nCanSocketEndPoint canSocketEndPoint = new CanSocketEndPoint(interfaceIndex);\n```\n\n## Helper classes\n\n### `CanSocketEndPoint`\n\nRepresents a SocketCAN interface endpoint. This class facilitiates binding a socket to a SocketCAN interface, using its interface index.\n\nInternally, it serializes the interface index into an `sockaddr_can` structure for use by `Bind()`.\n\n### `CanFrame`\n\nWraps a raw CAN frame stored as a byte array and allows easy serialization and deserialization of the various CAN frame fields.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrozone%2Fsocketcannet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrozone%2Fsocketcannet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrozone%2Fsocketcannet/lists"}