Two Dimensional Array + ctypes

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Aug 6 01:19:24 EDT 2009


En Wed, 05 Aug 2009 20:12:09 -0300, Sparky <Samnsparky 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




More information about the Python-list mailing list