Skip to content

Commit 0f80d25

Browse files
committed
Mover read of api version to separate function
1 parent 56ad81c commit 0f80d25

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

can/interfaces/pcan/pcan.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,7 @@ def __init__(
212212
self.m_objPCANBasic = PCANBasic()
213213
self.m_PcanHandle = channel
214214

215-
error, value = self.m_objPCANBasic.GetValue(PCAN_NONEBUS, PCAN_API_VERSION)
216-
if error != PCAN_ERROR_OK:
217-
raise CanInitializationError(f"Failed to read pcan basic api version")
218-
219-
apv = version.parse(value.decode("ascii"))
215+
apv = self.get_api_version()
220216
if apv < MIN_PCAN_API_VERSION:
221217
raise CanInitializationError(
222218
f"Minimum version of pcan api is {MIN_PCAN_API_VERSION}."
@@ -321,6 +317,13 @@ def bits(n):
321317

322318
return complete_text
323319

320+
def get_api_version(self):
321+
error, value = self.m_objPCANBasic.GetValue(PCAN_NONEBUS, PCAN_API_VERSION)
322+
if error != PCAN_ERROR_OK:
323+
raise CanInitializationError(f"Failed to read pcan basic api version")
324+
325+
return version.parse(value.decode("ascii"))
326+
324327
def status(self):
325328
"""
326329
Query the PCAN bus status.

0 commit comments

Comments
 (0)