diff --git a/can/interfaces/ixxat/canlib_vcinpl.py b/can/interfaces/ixxat/canlib_vcinpl.py index 7c4becafd..c6c924d8c 100644 --- a/can/interfaces/ixxat/canlib_vcinpl.py +++ b/can/interfaces/ixxat/canlib_vcinpl.py @@ -706,7 +706,7 @@ def _recv_internal(self, timeout): self._starttickoffset = self._message.dwTime elif self._message.uMsgInfo.Bits.type == constants.CAN_MSGTYPE_ERROR: if self._message.uMsgInfo.Bytes.bFlags & constants.CAN_MSGFLAGS_OVR: - log.warning("CAN error: data overrun") + raise VCIDataOverrunError("Data overrun occurred") else: log.warning( CAN_ERROR_MESSAGES.get( @@ -735,19 +735,17 @@ def _recv_internal(self, timeout): error_byte_1 = status.dwStatus & 0x0F error_byte_2 = status.dwStatus & 0xF0 if error_byte_1 > constants.CAN_STATUS_TXPEND: - # CAN_STATUS_OVRRUN = 0x02 # data overrun occurred - # CAN_STATUS_ERRLIM = 0x04 # error warning limit exceeded - # CAN_STATUS_BUSOFF = 0x08 # bus off status - if error_byte_1 & constants.CAN_STATUS_OVRRUN: - raise VCIError("Data overrun occurred") + # check CAN_STATUS_BUSOFF first because it is more severe than the other ones + if error_byte_1 & constants.CAN_STATUS_BUSOFF: + raise VCIBusOffError("Bus off status") elif error_byte_1 & constants.CAN_STATUS_ERRLIM: - raise VCIError("Error warning limit exceeded") - elif error_byte_1 & constants.CAN_STATUS_BUSOFF: - raise VCIError("Bus off status") + raise VCIErrorLimitExceededError("Error warning limit exceeded") + # Not checking CAN_STATUS_OVRRUN here because it is handled above and would be + # raised every time as the flag is never cleared until a reset. elif error_byte_2 > constants.CAN_STATUS_ININIT: # CAN_STATUS_BUSCERR = 0x20 # bus coupling error if error_byte_2 & constants.CAN_STATUS_BUSCERR: - raise VCIError("Bus coupling error") + raise VCIBusCouplingError("Bus coupling error") if not data_received: # Timed out / can message type is not DATA diff --git a/can/interfaces/ixxat/canlib_vcinpl2.py b/can/interfaces/ixxat/canlib_vcinpl2.py index b6789885a..f74d4cece 100644 --- a/can/interfaces/ixxat/canlib_vcinpl2.py +++ b/can/interfaces/ixxat/canlib_vcinpl2.py @@ -857,7 +857,7 @@ def _recv_internal(self, timeout): ): log.info(_format_can_status(self._message.abData[0])) if self._message.abData[0] & constants.CAN_STATUS_BUSOFF: - raise VCIBusOffError() + raise VCIBusOffError("Controller is in BUSOFF state") elif ( self._message.uMsgInfo.Bits.type diff --git a/can/interfaces/ixxat/exceptions.py b/can/interfaces/ixxat/exceptions.py index 771eec307..ff403b9a0 100644 --- a/can/interfaces/ixxat/exceptions.py +++ b/can/interfaces/ixxat/exceptions.py @@ -12,9 +12,12 @@ ) __all__ = [ + "VCIBusCouplingError", "VCIBusOffError", + "VCIDataOverrunError", "VCIDeviceNotFoundError", "VCIError", + "VCIErrorLimitExceededError", "VCIRxQueueEmptyError", "VCITimeout", ] @@ -36,8 +39,23 @@ def __init__(self): class VCIBusOffError(VCIError): - def __init__(self): - super().__init__("Controller is in BUSOFF state") + """Controller is in BUSOFF state""" + pass + + +class VCIErrorLimitExceededError(VCIError): + """overrun of error counter occurred""" + pass + + +class VCIDataOverrunError(VCIError): + """data overrun in receive buffer occurred""" + pass + + +class VCIBusCouplingError(VCIError): + """Bus coupling error occurred""" + pass class VCIDeviceNotFoundError(CanInitializationError):