在下面的脚本中,我将数据0x01,0x0a发送到地址0x0050000b,然后在地址0x0790000b搜索答案"01 0a“。消息需要每隔100ms发送一次。
问题是,由于某些原因,我正在发送的消息移动了~1.3ms,这导致我的CAN设备无法接收它。
我在下面添加了一个CAN消息的截图,
如有任何帮助,我们不胜感激!
import can
import time
enable_use_server = True
bus = can.interface.Bus(bustype='neovi', channel='1', bitrate=500000)
# Set Control Mode = Buck and Control Type = V_LOW_I_LIM (new mode)
#send(can_id=0x00500000, ext_id=1, dlc=2, one_shot=1, rtr=0, data=[0x01, 0x0A], wait=100)
msg = can.Message(arbitration_id=0x0050000b, data=[0x01, 0x0a], extended_id=True)
bus.send(msg)
time.sleep(.1)
print('Enter Vlow Ilim Mode sent')
#Verifv
SearchID = str(hex(0x0790000b))
SearchID = SearchID.strip('0x')
found = False
while not found:
mg = str(bus.recv(0.05))
if re.search(SearchID, mg):
print('rcv: ' + mg)
if re.search("01 0a", mg):
print(msg)
print("Vlow Ilim Mode was Successful")
found = True
else:
print("Vlow Ilim Mode was NOT Successful")
msg = can.Message(arbitration_id=0x0050000b, data=[0x01, 0x0a], extended_id=True)
bus.send(msg)
time.sleep(0.1)发布于 2020-12-11 08:11:23
代码本身也需要一些时间来执行。最好在循环中编写睡眠,如下所示:
t = time.time_ns()
while True:
...
time.sleep((100000 - (time.time_ns() - t)) / 1000000)
t = time.time_ns()也许还有一些调整是必要的。
https://stackoverflow.com/questions/65243876
复制相似问题