Skip to content

Commit ad7d2c0

Browse files
Raise meaningful exception for Vector when a channel is not available (#355)
1 parent ab30b36 commit ad7d2c0

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

can/interfaces/vector/canlib.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Import Modules
3131
# ==============
32-
from can import BusABC, Message
32+
from can import BusABC, Message, CanError
3333
from can.util import len2dlc, dlc2len
3434
from .exceptions import VectorError
3535

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

178186
self._is_filtered = False
179187
super(VectorBus, self).__init__(channel=channel, can_filters=can_filters,
180-
poll_interval=0.01, receive_own_messages=False, bitrate=None,
181-
rx_queue_size=256, app_name="CANalyzer", **config)
188+
**config)
182189

183190
def _apply_filters(self, filters):
184191
if filters:

can/interfaces/vector/vxlapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
XL_BUS_TYPE_CAN = 0x00000001
2828

2929
XL_ERR_QUEUE_IS_EMPTY = 10
30+
XL_ERR_HW_NOT_PRESENT = 129
3031

3132
XL_RECEIVE_MSG = 1
3233
XL_CAN_EV_TAG_RX_OK = 1024

0 commit comments

Comments
 (0)