>
> > The C prototype is
> > /long ReadTag(LPCTSTR name, float* pBuf, long nOS, long nWords);/
>
> That's not really the COM-approved way to declare that.  Note the
> signature:
>
> > Using MakePy, the signature is
> > /def ReadTag(self, Name=defaultNamedNotOptArg,
> > pBuf=defaultNamedNotOptArg, nOS=defaultNamedNotOptArg,
> > nWords=defaultNamedNotOptArg):
> >      return self._oleobj_.InvokeTypes(9, LCID, 1, (3, 0), ((8, 0),
> > (16388,0), (3, 0), (3, 0)),Name, pBuf, nOS, nWords)/
>
> 16388 means it a single float (VT_R4), passed by reference.  That
> matches your first experience.


Hi Tim:

Thanks for the clarification.  The company that wrote this software is
working with me to identify the best way to fix the COM object but they
don't have much experience with Python (they're a Matlab/C++ shop).  Their
COM objects used to be compatible only with Matlab, but a lot of researchers
protested this so they're working to fix up their code.  What is the
appropriate way to declare passing an array of doubles?

I'll take a look at your other suggestions regarding the ctype schemes/hack.

Thanks,
Brad


>
>
> > Alternatively:
> > /x = numpy.zeros(100)
> > obj.ReadTag('microphone', x.ctypes.data, 0, 100)
> > /returns a tuple and no error is raised:
> > /(1, 4.28, 0, 100)/
> > However, x is not updated with the new data from the hardware buffer.
>
> No, because x is not an array of floats (4-byte).  It's an array of
> doubles (8-byte).  You might try:
>    x = numpy.zeros( 100, numpy.float32 )
> but I'm not hopeful.
>
>
> > The following does not work either:
> > /x = numpy.zeros(100)/
> > /ptr = x.ctypes.data_as(ctypes.POINTER(ctypes.c_double))
> > obj.ReadTag('microphone', ptr, 0, 100)/
>
> No, again, because you're passing a chunk of doubles to an API that
> expects an array of singles.
>
>
> > Although no error is raised for the above two examples where I am
> > attempting to pass a pointer to the array, x remains an array of zeros
> > (the microphone is reading a 1 kHz sinusoid so x should be a sine
> > wave).  I'm a bit confused and not sure what the best way to proceed
> > at this point is.  How do a pass a pointer to my array into the
> > ActiveX method?
>
> Whatever you do is going to be a hack, because it's not declared in a
> COM-safe manner, but I suspect you're on the right track with the ctypes
> scheme.
>
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.
>
> _______________________________________________
> python-win32 mailing list
> python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to