Two Dimensional Array + ctypes

Sparky Samnsparky at gmail.com
Thu Aug 6 12:40:23 EDT 2009


On Aug 5, 11:19 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Wed, 05 Aug 2009 20:12:09 -0300, Sparky <Samnspa... at gmail.com> escribió:
>
>
>
>
>
> > Hello! I am trying to call this method:
>
> > long _stdcall AIBurst(long *idnum, [...]
> >                     long timeout,
> >                     float (*voltages)[4],
> >                     long *stateIOout,
> >                     long *overVoltage,
> >                     long transferMode);
>
> > I am having some problems with that  float (*voltages)[4].
> >         pointerArray = (ctypes.c_void_p * 4)
> >         voltages = pointerArray(ctypes.cast(ctypes.pointer
> > ((ctypes.c_long * 4096)()), ctypes.c_void_p), ctypes.cast
> > (ctypes.pointer((ctypes.c_long * 4096)()), ctypes.c_void_p),
> > ctypes.cast(ctypes.pointer((ctypes.c_long * 4096)()),
> > ctypes.c_void_p), ctypes.cast(ctypes.pointer((ctypes.c_long * 4096)
>
> Why c_long and not c_float?
> Anyway, this way looks much more clear to me (and doesn't require a cast):
>
> arr4096_type = ctypes.c_float * 4096
> voltages_type = arr4096_type * 4
> voltages = voltages_type()
>
> > The program runs but the values that come back in the array are not
> > right.
>
> Thay might be due to the long/float confusion.
>
> --
> Gabriel Genellina

Brilliant! Your code is much cleaner and the problem must have been
float vs long.

Thanks,
Sam



More information about the Python-list mailing list