Skip to content

Conversation

@FelixEL
Copy link

@FelixEL FelixEL commented Mar 21, 2025

Important fix to gui_tool not beeing able to detect PCAN (and other interfaces) on windows:
pywintypes.com_error: (-2147221020, 'Nieprawidłowa składnia.', None, None)

Error happens when method detect_available_configs() is executed. It happens when periodic scan of interfaces takes place.

Fix for common error in windows:
https://stackoverflow.com/questions/38860185/python-cant-import-wmi-under-special-circumstance

Platform: win10

2025-03-21 21:22:52,885 WARNING dronecan_gui_tool.setup_window Could not load can interfaces: (-2147221020, 'Nieprawidłowa składnia.', None, None)
Traceback (most recent call last):
  File "D:\setup_window.py", line 120, in list_ifaces
    for interface in detect_available_configs():
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\can\interface.py", line 183, in detect_available_configs
    bus_class._detect_available_configs()  # pylint: disable=protected-access
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\can\interfaces\usb2can\usb2canInterface.py", line 207, in _detect_available_configs
    return Usb2canBus.detect_available_configs()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\can\interfaces\usb2can\usb2canInterface.py", line 218, in detect_available_configs
    channels = find_serial_devices()
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\can\interfaces\usb2can\serial_selector.py", line 55, in find_serial_devices
    wmi = win32com.client.GetObject("winmgmts:")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\win32com\client\__init__.py", line 86, in GetObject
    return Moniker(Pathname, clsctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\win32com\client\__init__.py", line 103, in Moniker
    moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pywintypes.com_error: (-2147221020, 'Nieprawidłowa składnia.', None, None)

Copy link
Member

@tridge tridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for reporting this!


try:
from can import detect_available_configs
import pythoncom
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this either needs a check for windows, or at least a try/except wrapper

pywintypes.com_error -2147221020
@tridge
Copy link
Member

tridge commented Jul 7, 2025

i've fixed the conflict and added try/except

@tridge
Copy link
Member

tridge commented Jul 11, 2025

tested on win10

@tridge tridge merged commit bbab5bd into dronecan:master Jul 11, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants