https://github.com/matzeema/linux_can
Dart implementation of SocketCAN.
https://github.com/matzeema/linux_can
canbus dart ffi
Last synced: 3 months ago
JSON representation
Dart implementation of SocketCAN.
- Host: GitHub
- URL: https://github.com/matzeema/linux_can
- Owner: matzeema
- License: mit
- Created: 2021-04-08T08:47:44.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-09T14:10:19.000Z (about 1 year ago)
- Last Synced: 2025-02-28T08:38:10.227Z (3 months ago)
- Topics: canbus, dart, ffi
- Language: Dart
- Homepage:
- Size: 160 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Linux CAN
Dart implementation of SocketCAN.
Big shout out to [@ardera](https://github.com/ardera) who helped me a lot developing this package.
## Using the package
There are no system dependenices needed, except the `libc.so.6` which probably should be installed on your device.
### Setup
At first create a `CanDevice`. You can set a custom bitrate, default is 500 000. Afterwards call `setup()`. A `SocketException` will be thrown if something goes wrong.
```dart
final canDevice = CanDevice(bitrate: 250000);
await canDevice.setup();
```### Communication
To receive data use `read()`, which returns a `CanFrame`. It contains the id and data of the frame.
```dart
final frame = canDevice.read();
print("Frame id: ${frame.id}");
print("Frame data: ${frame.data}");
```To close the socket use `close()`.
## Limitations
- Because I have no hardware which allows writing CAN data, only reading is supported at the moment.
- For now only `can0` is supported as an interface.
- You can not change the bitrate once it is set. To change the bitrate a reboot of your device is currently needed.