VectorError:xlGetChannelIndex 失败(XL_ERR_HW_NOT_PRESENT)

问题描述 投票:0回答:3

你好,我正在使用 python 和 can analyzer 硬件 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) 作为错误。是什么导致了这个错误?

python can-bus
3个回答
1
投票

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

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

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

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

退出

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


0
投票

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

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

0
投票

好吧,这让我倒退了 6 个小时,相信他们说的图书馆......

我最近才重新发现这个问题,因为有人决定在 canLib.py 的 VectorBus 构造函数中给

app_name
默认值“CANalyzer”,这导致它只通过为该应用程序名称“CANalyzer”配置的通道使用
set_application_config()
当然因为没有设置,它的错误就像没有连接接口一样。

至于我的修复:

bus = can.interface.Bus(interface='vector', channel='0', receive_own_messages=True, bitrate=500000, app_name=None)
© www.soinside.com 2019 - 2024. All rights reserved.