Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nkh-lab/socketcan-hello-world
https://github.com/nkh-lab/socketcan-hello-world
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/nkh-lab/socketcan-hello-world
- Owner: nkh-lab
- Created: 2024-09-07T07:32:17.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2024-09-07T22:16:11.000Z (2 months ago)
- Last Synced: 2024-09-07T23:26:19.944Z (2 months ago)
- Language: Python
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Intro
Example project for socketCAN usage.## Install dependencies
```
sudo apt install python3-can
```## Check CAN interfaces
1. Using ip link Command```
ip link show
...
4: can0: mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
link/can
5: can1: mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
link/can
```
2. Check the System's dmesg log
```
sudo dmesg | grep can
[261178.980287] peak_usb 1-3.1.1.2:1.0 can0: attached to PCAN-USB FD channel 0 (device 0xFFFFFFFF)
[261463.889381] peak_usb 1-3.1.1.1:1.0 can1: attached to PCAN-USB FD channel 0 (device 0xFFFFFFFF)
```## Bring up the CAN interfaces
```
sudo ip link set can0 up type can bitrate 500000
sudo ip link set can1 up type can bitrate 500000
```## Run scripts
Receiver:
```
python3 receiver.py
Listening for messages on can0...
Received message on can0: ID=0x123, Data=01020304deadbeef
^C
Reception interrupted by user.
Closed can0 interface.
```
Sender:
```
python3 sender.py
Message sent on can1: ID=0x123, Data=01020304deadbeef
Closed can1 interface.
```## Bring down the CAN interfaces
```
sudo ip link set can0 down
sudo ip link set can1 down
```