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
Release files for gs-usb 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gs_usb-0.3.1.tar.gz | 6.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gs_usb-0.3.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 13.9 kB
Release files / gs_usb-0.3.1.tar.gz
| Download URL | gs_usb-0.3.1.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8a76285fda29b45a5a633cfe232a08058f642441b3d030877dc28ef6e0b7807
|
|
BLAKE2b-256 checksum How to use checksums |
37d8bb03645332d0de656b913cf4ac151aabc5c2c6e3c0c1fa30814fd4c45126
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.17
|
Release files / gs_usb-0.3.1-py2.py3-none-any.whl
| Download URL | gs_usb-0.3.1-py2.py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
1c35d4404427db3f7955a687a1235b5829f94c61ece56eb0cf3f3b23e2d44883
|
|
BLAKE2b-256 checksum How to use checksums |
760813b4e21ff15df9b7017e7e6265282df78098e50275bb99efc26b5d14ce29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.17
|