PySocketCAN
The pysocketcan module provides a class to quickly modify Linux SocketCAN parameters directly from Python.
For example, to change the baudrate in Linux you need to run
$ sudo ip link set can0 down
$ sudo ip link set can0 type can bitrate 250000
$ sudo ip link set can0 up
The pysocketcan equivalent is
>>> can0.baud = 250000
Installation
Use pip to install
$ pip install pysocketcan
Usage
import pysocket as pysc
>>> pysc.view_available() # returns available interfaces
'can0'
>>> can0 = pysc.Interface("can0") # instantiate interface object
>>> can0.on() # set interface up
>>> can0.off() # set interface down
>>> can0.state # returns current state of interface
'STOPPED'
>>> can0.baud = 250000 # sets the baudrate
>>> can0.baud # returns current baudrate
'250000'
>>> can0.status # returns currently active modes
'LOOPBACK,LISTEN-ONLY,TRIPLE-SAMPLING'
>>> can0.listen_only = False # turns mode off
>>> can0.status
'LOOPBACK,TRIPLE-SAMPLING'
If can-utils is installed you can also use
>>> can0.receive() # returns bus message
>>> can0.send(100, 12345678) # adds message to bus
Note:
To function correctly Python needs root priveleges
$ sudo python3
# or
$ sudo venv/bin/python3
Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
Metadata
Release files for pysocketcan 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pysocketcan-0.0.2.tar.gz | 3.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pysocketcan-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.9 kB
Release files / pysocketcan-0.0.2.tar.gz
| Download URL | pysocketcan-0.0.2.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7bfb318e9fcb3cb01e968f0cb2d785c31619e16536ba6009cbcb6815f06df25
|
|
BLAKE2b-256 checksum How to use checksums |
d493cebc77730c56166b863fac783e58089764e7393bc7afacaf8643ac3f6135
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|
Release files / pysocketcan-0.0.2-py3-none-any.whl
| Download URL | pysocketcan-0.0.2-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
97a8df75dc62260fde1469d38d92d13ecaa545fd5030c77243a230190c2eff95
|
|
BLAKE2b-256 checksum How to use checksums |
6bd6792dacf3173e927a5c391c53e9132229a0a2b01c6e851b626815a5f5aba8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|