def __vciFormatError(library_instance: CLibrary, function: Callable, vret: int): """Format a VCI error and attach failed function and decoded HRESULT :param CLibrary library_instance: Mapped instance of IXXAT vcinpl library :param callable function: Failed function :param HRESULT vret: HRESULT returned by vcinpl call :return: Formatted string """ buf = ctypes.create_string_buffer(constants.VCI_MAX_ERRSTRLEN) ctypes.memset(buf, 0, constants.VCI_MAX_ERRSTRLEN) library_instance.vciFormatError(vret, buf, constants.VCI_MAX_ERRSTRLEN) return "function {} failed ({})".format( function._name, buf.value.decode("utf-8", "replace") )
log = logging.getLogger('can.ixxat') try: # since Python 3.3 from time import perf_counter as _timer_function except ImportError: from time import clock as _timer_function # Hack to have vciFormatError as a free function, see below vciFormatError = None # main ctypes instance _canlib = None if sys.platform == "win32": try: _canlib = CLibrary("vcinpl") except Exception as e: log.warning("Cannot load IXXAT vcinpl library: %s", e) elif sys.platform == "cygwin": try: _canlib = CLibrary("vcinpl.dll") except Exception as e: log.warning("Cannot load IXXAT vcinpl library: %s", e) else: # Will not work on other systems, but have it importable anyway for # tests/sphinx log.warning("IXXAT VCI library does not work on %s platform", sys.platform) def __vciFormatErrorExtended(library_instance, function, HRESULT, arguments): """ Format a VCI error and attach failed function, decoded HRESULT and arguments