PCAN interface: add support for 32bit and 64bit registry views (Windows)

37 views
Skip to first unread message

jaurismo

unread,
Aug 3, 2023, 9:01:51 AM8/3/23
to python-can
Hi there, new guy here!

In short: does it make sense to add support to search for the PCAN driver existence from "the other" bitness windows registry (32bit/64bit) in case the default search fails? In other words: if Python is 32bit and installed drivers are 64bit then it would search from 64bit registry view if default search fails.

Longer version:
When the PCAN interface is instantiated in class "PCANBasic", the PCAN drivers are searched from Windows registry.

            # look for Peak drivers in Windows registry
            with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as reg:
                try:
                    with winreg.OpenKey(reg, r"SOFTWARE\PEAK-System\PEAK-Drivers"):
                        pass
                except OSError:
                    raise OSError("The PEAK-driver could not be found!") from None

However, if the developer is using 32bit Python but the installed drivers are for 64bit Windows, then the above mentioned registry search seems to fail for me with Windows 10 and Python 3.11. The earlier python-can versions (4.1.X and older) only logged "The PEAK-driver could not be found!" error but from python-can 4.2.X, the above-shown OSError is raised. I was wondering about this logged error for long time and now that the exception is raised, I was forced to look further in my problem. Before python-can 4.2.X, the interface seemed to work great although the search failed upon the instantiation (and I got an error in my log file).

My question is would make sense to add a "cross-bitness" search in case the first search fails? Something in lines of this discussion https://stackoverflow.com/a/36041228/21953891 So the fallback would check the other bitness and if driver is still not found, then the OSError could be raised.

I guess the developer can always change the Python to matching bitness but it is not crystal clear from the raised exception message. Then again, developer may have some dependency that requires using 32bit Python.

BR,
Miikka
Reply all
Reply to author
Forward
0 new messages