我在一个基于linux的设备上运行python代码,该设备具有以下操作系统规范:
NAME=Buildroot
VERSION=2020.11.1该设备使用三线接口(CAN_H、CAN_L、GND)连接到可编程控制器。
我已经编写了使用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提供什么建议?
发布于 2021-05-15 00:59:10
警告:我不熟悉python-can库,但我熟悉socketcan。
vcan0是一个虚拟can通道,您可以对其进行设置,以便启用应用程序之间的虚拟通信(例如测试)。
实际的CAN设备(例如,PCAN-USB)被列为can0、can1、canX。请注意,在某些嵌入式系统上,这可能并不成立(例如,它可以以can1开头)。
编辑:我忘了提一下,您可以像这样获得所有网络接口的列表,从而包括can接口:
$ ifconfig -ahttps://stackoverflow.com/questions/67536526
复制相似问题