Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

SeeedBus: Allow setting hardware filter/mask during Bus Init

未关闭
#1,995 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
停滞
技术栈
python

调研方向

从 SeeedBus.init 和 issue 中描述的内部 init_frame() 路径开始。跟踪 filter_id 和 mask_id 当前是如何初始化并发送到硬件的,然后验证可选值会在构造期间配置过滤器,而省略的值会保留当前未过滤的行为。

由索引模型根据 Issue 内容生成。

描述

enhancement

Main Problem

I don't like that the SeeedBus interface does not allow for the configuration of the hardware acceptance filter and mask during the bus initialization.

My use case involves a bootloader flasher client that communicates with a device over the CAN bus. The client sends a message with one CAN ID and needs to listen only for a response on another specific CAN ID. To achieve this efficiently, I need to use the hardware filter. The current implementation forces me to create the bus object, then manually change its internal attributes (filter_id, mask_id), and then re-call the internal init_frame() method. This workflow is not intuitive and feels like a workaround.

Current Alternative

The only alternative at the moment is to manually re-configure the bus after it has been created. This involves the following steps:


import struct

# 1. Create the bus with default (disabled) filters
bus = can.interface.Bus(interface='seeedstudio', channel='/dev/ttyUSB0')

# 2. Manually overwrite the internal attributes
bus.filter_id = struct.pack('<I', 0x456 << 21)
bus.mask_id = struct.pack('<I', 0xFFFFFFFF)

# 3. Call the internal init_frame() method again to send the new config to the hardware
bus.init_frame()

This is not an ideal solution because it is recalling init_frame() method again after it is called in init, and is little more complicated.

Want to change Like this

I would like to have filter_id and mask_id added as optional keyword arguments to the SeeedBus.init method. This would allow the hardware filter to be configured cleanly and directly when the bus is created.

Example of the desired usage:

Python

# Initialize the bus to only accept messages with ID 0x456
bus = can.interface.Bus(
    interface='seeedstudio',
    channel='/dev/ttyUSB0',
    bitrate=500000,
    frame_type='STD',
    filter_id=0x456, 
    mask_id=0xFFFFFFFF
)

# The bus is now ready to use with the hardware filter active.
msg = bus.recv()

Note: If the filter_id and mask_id arguments are not provided, they will default to 0x00. This maintains the current behavior where the filter is disabled and all CAN IDs are received, ensuring the change is fully backward-compatible.

# Initialize the bus 
# Filter ID, Mask ID here defaults to 0x00 so no filtering of can messages
bus = can.interface.Bus(
    interface='seeedstudio',
    channel='/dev/ttyUSB0',
    bitrate=500000,
    frame_type='STD',
)

# The bus is now ready to use with the hardware filter active.
msg = bus.recv()

This feature request originated from my work on a project using a Waveshare USB to CAN Adapter (Model A). This device works perfectly with the seeedstudio interface as it uses the same serial protocol. The lack of an initial filtering mechanism was the primary challenge I faced.

Adding this feature would be a significant improvement for any application that needs to use hardware filtering with Seeed Studio or compatible devices. I am currently working on this feature by cloning the repo, making the changes, and am prepared to submit a pull request to resolve this issue.

主要语言
Python
星标
1.6k
派生
697
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

hardbyte/python-can 的其他 Issue

查看 hardbyte/python-can 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。