VectorError: xlGetChannelIndex failed (XL_ERR_HW_NOT_PRESENT)

VectorError: xlGetChannelIndex failed (XL_ERR_HW_NOT_PRESENT)

您好,我正在使用 python 罐头分析仪硬件 vn1610

import time
import can
count=0
a=0
for i in range(1,1000):  # zero to max range ( 0 - 2048 )
  a=a+1
  print(a)       #code stops running at a=64[enter image description here][1]
  bus = can.interface.Bus(bustype='vector', app_name=None, channel=0,bitrate=500000)
  msg = can.Message(arbitration_id=i, data=[0x02,0x11,0x02,0x00 ,0x00 ,0x00, 0x00, 0x00],dlc=3, extended_id=False)
  bus.send(msg)
  print ("Request msg:",msg)
  response=bus.recv(0.02) 
  print ("Response msg:",response)

我收到 can.interfaces.vector.exceptions.VectorError: xlGetChannelIndex failed (XL_ERR_HW_NOT_PRESENT) 作为错误。是什么导致了这个错误?

它正在停止,因为您每次都在创建一个新界面。

可能 CANalyzer 最多支持 64 个接口[需要引用],这就是它在 a = 64 后停止的原因。

您不必每次都创建界面。 移动

bus = can.interface.Bus(bustype='vector', app_name=None, channel=0,bitrate=500000)

for 循环之外,您的代码应该可以工作。因为您不必一次又一次地创建界面。

在代码中创建一次总线,您还可以为各种通道创建信号总线,如:

    can.interface.Bus(interface='vector', channel='0,1,2,3',receive_own_messages=True,bitrate=500000)