我已经为桌面应用程序(PySide2和python-can)编写了一个程序,在这里我可以从选择列表中选择比特率,然后将所需的比特率(例如125000)传递给setIxxatBus方法
from can import Message from can.interfaces.ixxat import IXXATBus, exceptions def setIxxatBus(rate: int): Fetch.rate = rate try: Fetch.bus = IXXATBus(channel=0, can_filters=[{"can_id": 0x000, "can_mask": 0x000}], bitrate=Fetch.rate) except exceptions.VCIDeviceNotFoundError: Fetch.bus = None class Fetch: rate = 500000 try: bus = IXXATBus(channel=0, can_filters=[{"can_id": 0x000, "can_mask": 0x000}], bitrate=rate) except exceptions.VCIDeviceNotFoundError: bus = None def __init__(self): self.bus = Fetch.bus def receive(self, arbitration_id: int) -> list: if self.bus is not None: while True: self.message = self.bus.recv() if self.message.arbitration_id == arbitration_id: break return Fetch.bitValue(self, arbitration_id) else: return Fetch.bitValNC(self, arbitration_id)
[一种不同的方法正在Fetch类中反复调用receive方法。我确定其他所有内容(包括选择列表按钮)都可以正常工作。
类变量rate
更改为传递的值Fetch.rate = rate
,但我无法接收任何消息,
我想的问题是我想在这里...
Fetch.bus = IXXATBus(channel=0, can_filters=[{"can_id": 0x000, "can_mask": 0x000}], bitrate=Fetch.rate)
self.bus = Fetch.bus
这里是can.interfaces.ixxat.canlib的源代码
更新-
我检查了源代码,生成了日志文件,当我选择125000时,可以发现比特率已传递到库中-
2020-05-14 10:02:32 INFO CAN Filters: [{'can_id': 0, 'can_mask': 0}]
2020-05-14 10:02:32 INFO Got configuration of: {'bitrate': 125000}
2020-05-14 10:02:32 INFO Searching for first available device
我已经为桌面应用程序编写了程序(PySide2和python-can),在这里我可以从选择列表中选择比特率,该列表将所需的比特率(例如125000)传递给setIxxatBus方法...
我上次使用CAN已有数年了,但是我记得,主机必须选择与从机相同速度的比特率。不能通过设置一个节点的速度来更改所有设备的比特率速度。请参阅CAN位时序here的说明。