From a54b950d6eadf78b6cb2dab475ba39c392c39c1e Mon Sep 17 00:00:00 2001 From: danielhrisca Date: Mon, 2 Dec 2019 14:10:44 +0200 Subject: [PATCH 1/3] fixes #732: add support for VN8900 xlGetChannelTime function --- can/interfaces/vector/canlib.py | 5 ++++- can/interfaces/vector/xldriver.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/can/interfaces/vector/canlib.py b/can/interfaces/vector/canlib.py index ed366b4c8..54e47c94d 100644 --- a/can/interfaces/vector/canlib.py +++ b/can/interfaces/vector/canlib.py @@ -282,7 +282,10 @@ def __init__( # Calculate time offset for absolute timestamps offset = xlclass.XLuint64() - xldriver.xlGetSyncTime(self.port_handle, offset) + try: + xldriver.xlGetSyncTime(self.port_handle, offset) + except: + xldriver.xlGetChannelTime(self.port_handle, self.mask, offset) self._time_offset = time.time() - offset.value * 1e-9 self._is_filtered = False diff --git a/can/interfaces/vector/xldriver.py b/can/interfaces/vector/xldriver.py index 9bb1a1083..a976e8d82 100644 --- a/can/interfaces/vector/xldriver.py +++ b/can/interfaces/vector/xldriver.py @@ -89,6 +89,15 @@ def check_status(result, function, arguments): xlGetSyncTime.restype = xlclass.XLstatus xlGetSyncTime.errcheck = check_status +xlGetChannelTime = _xlapi_dll.xlGetChannelTime +xlGetChannelTime.argtypes = [ + xlclass.XLportHandle, + xlclass.XLaccess, + ctypes.POINTER(xlclass.XLuint64) +] +xlGetChannelTime.restype = xlclass.XLstatus +xlGetChannelTime.errcheck = check_status + xlClosePort = _xlapi_dll.xlClosePort xlClosePort.argtypes = [xlclass.XLportHandle] xlClosePort.restype = xlclass.XLstatus From 460cbb5f0c438fdb01037b9bc8206090f66bdbbf Mon Sep 17 00:00:00 2001 From: danielhrisca Date: Mon, 2 Dec 2019 14:44:37 +0200 Subject: [PATCH 2/3] add another level of try/except according to the review --- can/interfaces/vector/canlib.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/can/interfaces/vector/canlib.py b/can/interfaces/vector/canlib.py index 54e47c94d..cb1858062 100644 --- a/can/interfaces/vector/canlib.py +++ b/can/interfaces/vector/canlib.py @@ -283,10 +283,13 @@ def __init__( # Calculate time offset for absolute timestamps offset = xlclass.XLuint64() try: - xldriver.xlGetSyncTime(self.port_handle, offset) - except: - xldriver.xlGetChannelTime(self.port_handle, self.mask, offset) - self._time_offset = time.time() - offset.value * 1e-9 + try: + xldriver.xlGetSyncTime(self.port_handle, offset) + except VectorError: + xldriver.xlGetChannelTime(self.port_handle, self.mask, offset) + self._time_offset = time.time() - offset.value * 1e-9 + except VectorError: + self._time_offset = 0.0 self._is_filtered = False super().__init__(channel=channel, can_filters=can_filters, **kwargs) From 1b3291809ed2702312876a1a6efc82d76ff3ef75 Mon Sep 17 00:00:00 2001 From: danielhrisca Date: Mon, 2 Dec 2019 15:43:05 +0200 Subject: [PATCH 3/3] format using black --- can/interfaces/vector/xldriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/interfaces/vector/xldriver.py b/can/interfaces/vector/xldriver.py index a976e8d82..337135755 100644 --- a/can/interfaces/vector/xldriver.py +++ b/can/interfaces/vector/xldriver.py @@ -93,7 +93,7 @@ def check_status(result, function, arguments): xlGetChannelTime.argtypes = [ xlclass.XLportHandle, xlclass.XLaccess, - ctypes.POINTER(xlclass.XLuint64) + ctypes.POINTER(xlclass.XLuint64), ] xlGetChannelTime.restype = xlclass.XLstatus xlGetChannelTime.errcheck = check_status