Python Windows/Linux/Mac CAN driver based on usbfs or WinUSB WCID for Geschwister Schneider USB/CAN devices and candleLight USB CAN interfaces.
Project description
gs_usb
Python Windows/Linux/Mac CAN driver based on usbfs or WinUSB WCID for Geschwister Schneider USB/CAN devices, candleLight USB CAN interfaces, CAN Debugger devices and other interfaces utilising the gs_usb driver.
Getting Started
Install by pip install gs_usb
Below is a basic demo for CAN message sending and receiving.
import time
from gs_usb.gs_usb import GsUsb
from gs_usb.gs_usb_frame import GsUsbFrame
from gs_usb.constants import (
CAN_EFF_FLAG,
CAN_ERR_FLAG,
CAN_RTR_FLAG,
)
def main():
# Find our device
devs = GsUsb.scan()
if len(devs) == 0:
print("Can not find gs_usb device")
return
dev = devs[0]
# Configuration
if not dev.set_bitrate(250000):
print("Can not set bitrate for gs_usb")
return
# Start device
dev.start()
# Prepare frames
data = b"\x12\x34\x56\x78\x9A\xBC\xDE\xF0"
sff_frame = GsUsbFrame(can_id=0x7FF, data=data)
sff_none_data_frame = GsUsbFrame(can_id=0x7FF)
err_frame = GsUsbFrame(can_id=0x7FF | CAN_ERR_FLAG, data=data)
eff_frame = GsUsbFrame(can_id=0x12345678 | CAN_EFF_FLAG, data=data)
eff_none_data_frame = GsUsbFrame(can_id=0x12345678 | CAN_EFF_FLAG)
rtr_frame = GsUsbFrame(can_id=0x7FF | CAN_RTR_FLAG)
rtr_with_eid_frame = GsUsbFrame(can_id=0x12345678 | CAN_RTR_FLAG | CAN_EFF_FLAG)
rtr_with_data_frame = GsUsbFrame(can_id=0x7FF | CAN_RTR_FLAG, data=data)
frames = [
sff_frame,
sff_none_data_frame,
err_frame,
eff_frame,
eff_none_data_frame,
rtr_frame,
rtr_with_eid_frame,
rtr_with_data_frame,
]
# Read all the time and send message in each second
end_time, n = time.time() + 1, -1
while True:
iframe = GsUsbFrame()
if dev.read(iframe, 1):
print("RX {}".format(iframe))
if time.time() - end_time >= 0:
end_time = time.time() + 1
n += 1
n %= len(frames)
if dev.send(frames[n]):
print("TX {}".format(frames[n]))
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gs_usb-0.3.0.tar.gz.
File metadata
- Download URL: gs_usb-0.3.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f488fd7cd09d753dff74b7d05349f07933dc556844e3cd9df02c4e4b746bf8f
|
|
| MD5 |
d624246be44031d914ac25d4f0a5fe96
|
|
| BLAKE2b-256 |
a137a7b1b2d458687a3c9bf90a4d5a299ae5b2d74791ba6516b51bd939857c1d
|
File details
Details for the file gs_usb-0.3.0-py2.py3-none-any.whl.
File metadata
- Download URL: gs_usb-0.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7e5c8a367262fc2ca5f13f33bdc56e3b76b3dc01e0b8eeb82183dfb9b34312f
|
|
| MD5 |
08f08cb8431b806067465861c6b0a122
|
|
| BLAKE2b-256 |
2de1a97e0a2b46f83096e5172ab45dbd7528405b45bfaffd3ceff1bf4b273d9b
|