Python 通过CAN总线接口的通信不工作
我在基于linux的设备上运行python代码,该设备具有以下操作系统规范:Python 通过CAN总线接口的通信不工作,python,linux,can-bus,buildroot,python-can,Python,Linux,Can Bus,Buildroot,Python Can,我在基于linux的设备上运行python代码,该设备具有以下操作系统规范: NAME=Buildroot VERSION=2020.11.1 该设备通过三线接口(CAN\U H、CAN\U L、GND)连接至PLC 我编写了一个代码,使用CAN总线协议向PLC发送消息。这是通过python can包完成的 我有以下代码: import can def send(): #USB interface #bus = can.interface.Bus(bustype='pcan'
NAME=Buildroot
VERSION=2020.11.1
该设备通过三线接口(CAN\U H、CAN\U L、GND)连接至PLC
我编写了一个代码,使用CAN总线协议向PLC发送消息。这是通过python can
包完成的
我有以下代码:
import can
def send():
#USB interface
#bus = can.interface.Bus(bustype='pcan', channel='PCAN_USBBUS1', bitrate=500000)
#on linux
bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=500000)
#on windows
#bus = can.interface.Bus(bustype='serial', channel='COM1', bitrate=500000)
msg = can.Message(arbitration_id=0x68005,data=[0x10,0x11,0x12],is_extended_id=True)
try:
bus.send(msg)
print("Message sent on {}".format(bus.channel_info))
except can.CanError:
print("Message NOT sent")
if __name__ == '__main__':
send()
所面临的问题是设备没有向PLC发送任何数据。这可能是由于为bustype
和channel
设置的选项不正确所致
有谁能建议为这个带有三根Can线的物理接口提供什么样的
bustype
和channel
?警告:我不熟悉python Can库,但我熟悉socketcan
vcan0是一个虚拟can通道,您可以对其进行设置,以实现应用程序之间的虚拟通信(例如测试)
实际的CAN设备(如PCAN-USB)列为can0、can1、canX。
请注意,在某些嵌入式系统上,这可能不成立(例如,它可以从can1开始)
编辑:我忘了提到,您可以获得所有网络接口的列表,例如,包括can接口:
$ ifconfig -a
参考文档:使用示波器或CAN侦听器检查实际总线。如果有的话,是什么被送到那里的?