飞凌嵌入式
直播中

华仔stm32

3年用户 2960经验值
擅长:嵌入式技术
私信 关注
[技术]

【飞凌RK3568开发板试用体验】python CAN调试

安装好python-can 后,接者又安装了can-utils。

can0 = can.interface.Bus(channel = 'can0', bustyp = 'socketcan_ctypes')
就一直报错,后面找到资料用can.rc来配置才成功。创建python代码如下:

#!/usr/bin/env python

"""
This example shows how sending a single message works.
"""
import time
import can
from can.interface import Bus
can.rc['bitrate'] = '500000'
can.rc['interface']='socketcan'

can.rc['channel'] = 'can0'
can.rc['bitrate'] = '500000'

bus = Bus()
def send_one():
	msg = can.Message(
	    arbitration_id=0xC0FFEE, data=[0, 25, 0, 1, 3, 1, 4, 1], is_extended_id=True
	)
	try:
	    bus.send(msg)
	    print(f"Message sent on {bus.channel_info}")
	except can.CanError:
	    print("Message NOT sent")


if __name__ == "__main__":
    while True:
    	send_one()
    	time.sleep(1)

接上can分析仪就可以实现用python发送数据了:

image.png

can发送数据

更多回帖

发帖
×
20
完善资料,
赚取积分