Skip to main content

python-can interface plugin for Hirain

Project description

python-can-hirain

Python CAN 接口适配器,用于通过 python-can 库操作 HIRAIN TestBaseVCI 硬件设备。

安装

使用 pip 安装:

pip install python-can-hirain

安装后,hrcan 接口会自动注册到 python-can 中,无需手动复制文件或修改 __init__.py

快速开始

CAN 通信示例

import can
import time

# 初始化 CAN 通道
with can.Bus(interface="hrcan", channel=0, # 激活通道0为CANFD通道
    configs = [{
        'resistance': 1, # 启用终端电阻
        'mode' : TestBaseVCI_ChlMode.CAN, # 设置CAN通道
        'listenFlag' : 0, # 0-正常状态,1-通道为仅监听状态,不给ACK响应
        'baudrate': 500_000,
        'samplePoint': TestBaseVCI_SAMPLEPOINT.SAMPLE_75}]) as bus:
# 初始化 CANFD 通道
with can.Bus(interface="hrcan", channel=0, # 激活通道0为CANFD通道
        configs = [{
            'resistance': 1, # 启用终端电阻
            'mode' : TestBaseVCI_ChlMode.CANFD, # 设置CANFD通道
            'listenFlag' : 0, # 0-正常状态,1-通道为仅监听状态,不给ACK响应
            'abrBaudrate': 500_000,
            'dbrBaudrate': 2000_000,
            'abrSamplePoint': TestBaseVCI_SAMPLEPOINT.SAMPLE_80,
            'dbrSamplePoint': TestBaseVCI_SAMPLEPOINT.SAMPLE_80,}]) as bus:

环境要求

  • 操作系统: Windows 10/11, Ubuntu 20/22
  • 硬件驱动: TestBaseVCI 驱动程序 2.4.1+
  • Python: 64 位 Python 3.7+
  • 依赖库: python-can

更多示例

查看 demo/ 目录获取完整示例:

  • Test_can.py - 经典 CAN 操作示例
  • Test_Canfd.py - CAN FD 操作示例
  • Test_diag.py - 诊断功能示例

注意事项

  • 确保 TestBaseVCI 驱动程序已正确安装
  • Linux 系统上使用 sudo 时,可能需要添加 -E 参数保留环境变量
  • 使用前请确认设备能被系统识别

支持

有关详细配置参数和高级用法,请参考 python-can 官方文档和 HIRAIN 二次开发SDK手册。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_can_hirain-0.1.0.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_can_hirain-0.1.0-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file python_can_hirain-0.1.0.tar.gz.

File metadata

  • Download URL: python_can_hirain-0.1.0.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.7

File hashes

Hashes for python_can_hirain-0.1.0.tar.gz
Algorithm Hash digest
SHA256 74c0afca5c7dadb7fa4dc0f51ca1624970fc49890ad10e323534bd483bd35be6
MD5 396628c8007114c7e554e56d1a93631b
BLAKE2b-256 f7c46bdca01a37f7c8b83a8d17bff0824023f942f7daea728cfe3de10a1b54c0

See more details on using hashes here.

File details

Details for the file python_can_hirain-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_can_hirain-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22f940d20a24682d46ab4313230cdb269feef887746e8c3d9166808c77d01808
MD5 404b7df0a434fb288444ce8f8d5bb09f
BLAKE2b-256 a6182f57c235d56df07cc0393a2e227289a13abac5c1206e8c2488a2551b6227

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page