Skip to content

Commit c469ce9

Browse files
author
Peter Kessen
committed
Implement check for minimum version of pcan library
1 parent b693494 commit c469ce9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

can/interfaces/pcan/pcan.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from typing import Optional
1111

12+
from packaging import version
13+
1214
from ...message import Message
1315
from ...bus import BusABC, BusState
1416
from ...util import len2dlc, dlc2len
@@ -19,13 +21,15 @@
1921
PCAN_BITRATES,
2022
PCAN_FD_PARAMETER_LIST,
2123
PCAN_CHANNEL_NAMES,
24+
PCAN_NONEBUS,
2225
PCAN_BAUD_500K,
2326
PCAN_TYPE_ISA,
2427
PCANBasic,
2528
PCAN_ERROR_OK,
2629
PCAN_ALLOW_ERROR_FRAMES,
2730
PCAN_PARAMETER_ON,
2831
PCAN_RECEIVE_EVENT,
32+
PCAN_API_VERSION,
2933
PCAN_DEVICE_NUMBER,
3034
PCAN_ERROR_QRCVEMPTY,
3135
PCAN_ERROR_BUSLIGHT,
@@ -58,6 +62,8 @@
5862
# Set up logging
5963
log = logging.getLogger("can.pcan")
6064

65+
MIN_PCAN_API_VERSION = version.parse("4.2.0")
66+
6167

6268
try:
6369
# use the "uptime" library if available
@@ -206,6 +212,19 @@ def __init__(
206212
self.m_objPCANBasic = PCANBasic()
207213
self.m_PcanHandle = channel
208214

215+
error, value = self.m_objPCANBasic.GetValue(PCAN_NONEBUS, PCAN_API_VERSION)
216+
if error != PCAN_ERROR_OK:
217+
raise CanInitializationError(
218+
F"Failed to read pcan basic api version"
219+
)
220+
221+
apv = version.parse(value.decode('ascii'))
222+
if apv < MIN_PCAN_API_VERSION:
223+
raise CanInitializationError(
224+
F"Minimum version of pcan api is {MIN_PCAN_API_VERSION}."
225+
F" Installed version is {apv}. Consider upgrade of pcan basic package"
226+
)
227+
209228
if state is BusState.ACTIVE or state is BusState.PASSIVE:
210229
self.state = state
211230
else:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"typing_extensions>=3.10.0.0",
9191
'pywin32;platform_system=="Windows" and platform_python_implementation=="CPython"',
9292
'msgpack~=1.0.0;platform_system!="Windows"',
93+
"packaging",
9394
],
9495
extras_require=extras_require,
9596
)

0 commit comments

Comments
 (0)