can_socket 0.1.3 copy "can_socket: ^0.1.3" to clipboard
can_socket: ^0.1.3 copied to clipboard

Pure Dart FFI bindings for Linux SocketCAN. Raw CAN, CAN FD, BCM, ISO-TP, and J1939.

example/example.dart

// Copyright 2026 Joel Winarske
// SPDX-License-Identifier: Apache-2.0

/// Minimal SocketCAN example -- send and receive a CAN frame on vcan0.
///
/// Setup:
///   sudo modprobe vcan
///   sudo ip link add dev vcan0 type vcan
///   sudo ip link set up vcan0
library;

import 'dart:typed_data';

import 'package:can_socket/can_socket.dart';

void main() {
  final socket = CanSocket('vcan0');

  // Send a standard CAN frame.
  socket.send(
    CanFrame(id: 0x123, data: Uint8List.fromList([0xDE, 0xAD, 0xBE, 0xEF])),
  );

  // Blocking receive with 1-second timeout.
  final frame = socket.receive(timeoutMs: 1000);
  if (frame != null) {
    print('Received: $frame');
  } else {
    print('No frame received within timeout.');
  }

  socket.close();
}
0
likes
150
points
31
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Pure Dart FFI bindings for Linux SocketCAN. Raw CAN, CAN FD, BCM, ISO-TP, and J1939.

Homepage
Repository (GitHub)
View/report issues

Topics

#can-bus #socketcan #ffi

License

unknown (license)

Dependencies

ffi

More

Packages that depend on can_socket