comtypes
comtypes copied to clipboard
comtypes ndarray with ASCOM safearray problem
It is says that comtypes safearray_as_ndarray context manager will accelerate the reading speed of large array from COM. I tried it with ASCOM camera classes. The ASCOM can return ImageArray int safearray and ImageArrayVariant variant safearray. When using ImageArrayVariant, it can be done successfully, but the time is far more than normal np.array(tuple) way. When using ImageArray, the libarary always get error
File "C:\ProgramData\Anaconda3\lib\site-packages\comtypes_init_.py", line 280, in getattr raise AttributeError(name)
I don't know why. Thanks. I just want to know some fast procedure to get image array from ASCOM.
see #205 and #178
Hi,
running over the same problem. I used numpy 1.21.1 and com types 1.1.10 ans still see the same problem. Recent bumpy still only shows numpy types:
ASCOM camera needs:
<class 'ctypes.c_long'>
but
npsupport.typecodes.values()
still returns:
<class 'numpy.uint16'>, <class 'numpy.intc'>, <class 'numpy.uint32'>, <class 'numpy.int64'>, <class 'numpy.float64'>, <class 'numpy.int16'>, <class 'numpy.uint64'>, <class 'numpy.int8'>, <class 'numpy.uint8'>, <class 'numpy.bool_'>, <class 'numpy.float32'>
Michel
Addition in analyse so far: in npsupport the types were correctly added to dict typecodes. At the point in time where you compare your SafeArray type against the dict typecodes it contains only the numpy part. So something is going wrong during runtime.
Finally I think I found the cause: in line 311 of SafeArray.py there is a check
self._itemtype_ in list(npsupport.typecodes.values())
as the values are mapped to numpy type, we get always the numpys From my opinion we should check against the keys()
self._itemtype_ in list(npsupport.typecodes.keys())
to make the things right. Any thoughts about this ? Michel
@fockez @jove1 @mworion
If the issue remains, please re-open.