Example: 50-OpenMV-Boards/50-IMXRT-Boards/50-Board-Control/can.py
# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2024 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# CAN Shield Example
#
# 此示例演示了两台相机之间的CAN通信。
# 注意:运行此示例需要两个CAN收发器扩展板和DB9电缆。
import time
from machine import CAN
# 注意:在接收节点上设置为False。
TRANSMITTER = True
can = CAN(0, CAN.NORMAL, baudrate=1000000, auto_restart=True)
if TRANSMITTER:
while True:
# 发送ID为1的消息
can.send("Hello", 1, timeout=100, extframe=False)
time.sleep_ms(1000)
else:
# 在接收节点上运行。
# 设置过滤器以接收ID为1和2的消息
# 过滤器索引、模式(DUAL等)、FIFO(0)、参数
can.setfilter(0, CAN.DUAL, 0, [1, 2])
while True:
# 在FIFO 0上接收消息 (there's only one fifo)
print(can.recv(0, timeout=10000))