can-debug

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CAN 总线调试

CAN Bus Debugging

适用场景

Application Scenarios

  • 嵌入式设备实现了 CAN 通信,需要验证收发是否正常。
  • 需要监听 CAN 总线上的所有帧或过滤特定 ID。
  • 需要向 CAN 总线发送测试帧并等待响应。
  • 需要扫描总线上的活跃节点。
  • Embedded devices that implement CAN communication need to verify whether sending and receiving are functioning properly.
  • Need to monitor all frames on the CAN bus or filter specific IDs.
  • Need to send test frames to the CAN bus and wait for responses.
  • Need to scan active nodes on the bus.

必要输入

Required Inputs

  • CAN 接口类型(pcan、kvaser、slcan、socketcan、virtual 等)。
  • 通道名(取决于接口类型,如 PCAN_USBBUS1、COM3、can0)。
  • 波特率(默认 500000)。
  • CAN interface type (pcan, kvaser, slcan, socketcan, virtual, etc.).
  • Channel name (depends on the interface type, e.g., PCAN_USBBUS1, COM3, can0).
  • Baud rate (default 500000).

依赖

Dependencies

  • python-can
    (pip install python-can)
  • 对应适配器的驱动(如 PCAN 需要 PCAN-Basic API)
  • python-can
    (pip install python-can)
  • Drivers for the corresponding adapter (e.g., PCAN requires PCAN-Basic API)

执行步骤

Execution Steps

  1. 先阅读 references/usage.md,确认操作参数。
  2. 探测环境:
    bash
    python scripts/can_tool.py --detect
  3. 根据需求执行操作:
    bash
    # 监听总线
    python scripts/can_tool.py --interface pcan --channel PCAN_USBBUS1 --listen --duration 10
    
    # 发送帧
    python scripts/can_tool.py --interface pcan --channel PCAN_USBBUS1 --send --id 0x123 --data 01,02,03
    
    # 扫描节点
    python scripts/can_tool.py --interface pcan --channel PCAN_USBBUS1 --scan --scan-range 0x001-0x0FF
  1. First read references/usage.md to confirm operation parameters.
  2. Detect the environment:
    bash
    python scripts/can_tool.py --detect
  3. Perform operations according to requirements:
    bash
    # Listen to the bus
    python scripts/can_tool.py --interface pcan --channel PCAN_USBBUS1 --listen --duration 10
    
    # Send frames
    python scripts/can_tool.py --interface pcan --channel PCAN_USBBUS1 --send --id 0x123 --data 01,02,03
    
    # Scan nodes
    python scripts/can_tool.py --interface pcan --channel PCAN_USBBUS1 --scan --scan-range 0x001-0x0FF

失败分流

Failure Diversion

  • connection-failure
    :适配器未连接或驱动未安装。
  • bus-error
    :CAN 总线错误(如未接终端电阻)。
  • timeout
    :发送后无响应。
  • connection-failure
    : Adapter not connected or driver not installed.
  • bus-error
    : CAN bus error (e.g., no terminal resistor connected).
  • timeout
    : No response after sending.

输出约定

Output Convention

示例输出格式:
结果: ✅ 监听完成,收到 15 帧
  连接: pcan PCAN_USBBUS1 500000

  [14:30:01] 0x123  [8]  01 02 03 04 05 06 07 08
  [14:30:01] 0x456  [4]  AA BB CC DD
Example output format:
Result: ✅ Listening completed, received 15 frames
  Connection: pcan PCAN_USBBUS1 500000

  [14:30:01] 0x123  [8]  01 02 03 04 05 06 07 08
  [14:30:01] 0x456  [4]  AA BB CC DD

交接关系

Handover Relationships

  • build-keil
    /
    build-platformio
    烧录固件后,用此 skill 验证 CAN 通信。
  • serial-monitor
    互补:serial-monitor 查看串口调试输出,can-debug 进行 CAN 协议级调试。
  • After burning firmware with
    build-keil
    /
    build-platformio
    , use this skill to verify CAN communication.
  • Complementary to
    serial-monitor
    : serial-monitor views serial port debugging output, can-debug performs CAN protocol-level debugging.