diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 781feef24..d56a151de 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,8 @@ +Version 2.2.1 (2018-07-12) +===== + +* Fix errors and warnings when importing library on Windows +* Fix Vector backend raising ValueError when hardware is not connected Version 2.2.0 (2018-06-30) ===== diff --git a/can/__init__.py b/can/__init__.py index e10968cd7..42c20d2b8 100644 --- a/can/__init__.py +++ b/can/__init__.py @@ -9,7 +9,7 @@ import logging -__version__ = "2.2.0" +__version__ = "2.2.1" log = logging.getLogger('can') diff --git a/can/interface.py b/can/interface.py index 8156f7d08..b0e670942 100644 --- a/can/interface.py +++ b/can/interface.py @@ -20,7 +20,10 @@ from .util import load_config from .interfaces import BACKENDS -from can.interfaces.socketcan.socketcan import CyclicSendTask, MultiRateCyclicSendTask +if 'linux' in sys.platform: + # Deprecated and undocumented access to SocketCAN cyclic tasks + # Will be removed in version 3.0 + from can.interfaces.socketcan import CyclicSendTask, MultiRateCyclicSendTask # Required by "detect_available_configs" for argument interpretation if sys.version_info.major > 2: diff --git a/can/interfaces/vector/canlib.py b/can/interfaces/vector/canlib.py index 3d7f6c119..33551deb9 100644 --- a/can/interfaces/vector/canlib.py +++ b/can/interfaces/vector/canlib.py @@ -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 @@ -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) @@ -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: diff --git a/can/interfaces/vector/vxlapi.py b/can/interfaces/vector/vxlapi.py index fbdf442e9..a5f26f80f 100644 --- a/can/interfaces/vector/vxlapi.py +++ b/can/interfaces/vector/vxlapi.py @@ -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