Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Raise meaningful exception for Vector when a channel is not available (
  • Loading branch information
christiansandberg committed Jul 11, 2018
commit ad7d2c09e39dc793a57cc2a17f711ebddba4e5f5
13 changes: 10 additions & 3 deletions can/interfaces/vector/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# Import Modules
# ==============
from can import BusABC, Message
from can import BusABC, Message, CanError
from can.util import len2dlc, dlc2len
from .exceptions import VectorError

Expand Down Expand Up @@ -101,6 +101,14 @@ def __init__(self, channel, can_filters=None, poll_interval=0.01,
LOG.debug('Channel index %d found', channel)
idx = vxlapi.xlGetChannelIndex(hw_type.value, hw_index.value,
hw_channel.value)
if idx < 0:
# Undocumented behavior! See issue #353.
# If hardware is unavailable, this function returns -1.
# Raise an exception as if the driver
# would have signalled XL_ERR_HW_NOT_PRESENT.
raise VectorError(vxlapi.XL_ERR_HW_NOT_PRESENT,
"XL_ERR_HW_NOT_PRESENT",
"xlGetChannelIndex")
mask = 1 << idx
LOG.debug('Channel %d, Type: %d, Mask: 0x%X',
hw_channel.value, hw_type.value, mask)
Expand Down Expand Up @@ -177,8 +185,7 @@ def __init__(self, channel, can_filters=None, poll_interval=0.01,

self._is_filtered = False
super(VectorBus, self).__init__(channel=channel, can_filters=can_filters,
poll_interval=0.01, receive_own_messages=False, bitrate=None,
rx_queue_size=256, app_name="CANalyzer", **config)
**config)

def _apply_filters(self, filters):
if filters:
Expand Down
1 change: 1 addition & 0 deletions can/interfaces/vector/vxlapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
XL_BUS_TYPE_CAN = 0x00000001

XL_ERR_QUEUE_IS_EMPTY = 10
XL_ERR_HW_NOT_PRESENT = 129

XL_RECEIVE_MSG = 1
XL_CAN_EV_TAG_RX_OK = 1024
Expand Down