I'm trying to control a device (Gamry Interface 5000 Potentiostat) via its COM interface using win32com.
# Imports
import win32com.client as client
# Get device list
devices = client.Dispatch('GamryCOM.GamryDeviceList')
# Iterate through devices
for i in range(devices.Count()):
# Get device (this wors as we only have one connected yet)
device = devices.EnumSections()[i]
print(device)
# Setup potentiostat object
potentiostat = client.Dispatch('GamryCOM.GamryPstat')
When I run this, I got the following error message:
IFC5000-10519
Traceback (most recent call last):
File "c:\Users\Rob\AppData\Local\Programs\Python\Python39-32\lib\site-packages\win32com\client\dynamic.py", line 86, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\[...]\gamry_control_01.py", line 23, in <module>
potentiostat = client.Dispatch('GamryCOM.GamryPstat', clsctx = pythoncom.CLSCTX_LOCAL_SERVER )
File "c:\Users\Rob\AppData\Local\Programs\Python\Python39-32\lib\site-packages\win32com\client\__init__.py", line 117, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch, userName, clsctx)
File "c:\Users\Rob\AppData\Local\Programs\Python\Python39-32\lib\site-packages\win32com\client\dynamic.py", line 106, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "c:\Users\Rob\AppData\Local\Programs\Python\Python39-32\lib\site-packages\win32com\client\dynamic.py", line 88, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(
pywintypes.com_error: (-2147221164, 'Class not registered', None, None)
Funnily enough, the first dispatch-statement just works fine, Just the second one fails.
I'm using a 64 Bit Windows 11 setup and tested different Python environments:
- Python 3.10 64 Bit, win32com-303 64 Bit
- Python 3.9 32 Bit, win32com-303 32 Bit
I also tried using comtypes instead of win32com which resulted in the same error.
Thank you very much for your help!
Regards
oleview.exeto explore all the objects, interfaces and type libraries that are registered on your system. NB you have to run it for the first time with elevated permissions. That has the option to attempt to create an instance of an object, as well as explore what interfaces it provides.