# gcan-driver **Repository Path**: blockish/gcan-driver ## Basic Information - **Project Name**: gcan-driver - **Description**: 广成USBCAN驱动,python-can集成 - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 1 - **Created**: 2023-12-01 - **Last Updated**: 2026-01-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 广成USBCAN驱动python封装实现 ## 如何使用 ### 不集成在python-can中 ```python from gcan import GCan, DeviceType, CAN_FRAME can = GCan(DeviceType.USBCAN2, 0) can.OpenDevice() can.InitCAN(0, bitrate=500_000) can.StartCAN(0) frames = (CAN_FRAME * 1)() frames[0].ID = 0x00 frames[0].SendType = 0x00 frames[0].RemoteFlag = 0x00 frames[0].ExternFlag = 0x01 frames[0].DataLen = 0x08 for i in range(8): frames[0].Data[i] = i can.Transmit(0, frames) # do other thing can.ResetCAN(0) can.CloseDevice() ``` ### 集成在python-can中 * 移动文件 `gcan.py` python-can安装目录中 `interfaces`文件夹 * 在`interfaces/__init__.py`定义的`__all__`最后添加 `"gcan", ` * 在`interfaces/__init__.py`定义的`BACKENDS`最后添加`"gcan": ("can.interfaces.gcan", "GCanBus"),` ```python import can from gcan import DeviceType with can.Bus(interface="gcan", device_type=DeviceType.USBCAN2, device_index=0, configs=[ {"bitrate": 500_000}, {"bitrate": 1_000_000} ]) as bus: print(bus.recv()) ```