Skip to content

Commit 8ace40b

Browse files
authored
Added keycheck for windows platform (hardbyte#724)
* Added keycheck for windows platform PCANBasic will log an error when the PEAK-Driver key could not be found. * Forgot the import winreg statement * added empty line between imports and rest of code * added finally statement for closing registery
1 parent c92fbc2 commit 8ace40b

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

can/interfaces/pcan/basic.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from string import *
1515
import platform
1616
import logging
17+
import winreg
18+
1719

1820
logger = logging.getLogger("can.pcan")
1921

@@ -498,9 +500,17 @@ class PCANBasic:
498500
"""
499501

500502
def __init__(self):
501-
# Loads the PCANBasic.dll
503+
# Loads the PCANBasic.dll and checks if driver is available
502504
if platform.system() == "Windows":
503505
self.__m_dllBasic = windll.LoadLibrary("PCANBasic")
506+
aReg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
507+
try:
508+
aKey = winreg.OpenKey(aReg, r"SOFTWARE\PEAK-System\PEAK-Drivers")
509+
winreg.CloseKey(aKey)
510+
except WindowsError:
511+
logger.error("Exception: The PEAK-driver couldn't be found!")
512+
finally:
513+
winreg.CloseKey(aReg)
504514
elif platform.system() == "Darwin":
505515
self.__m_dllBasic = cdll.LoadLibrary("libPCBUSB.dylib")
506516
else:

0 commit comments

Comments
 (0)