[Pyrex] Pointers

Javier Correa javier.correa at gmail.com
Tue Nov 9 18:16:53 CET 2010


I-m new to pyrex and I'm trying to use it to have access to a library
(MesaSR, http://www.mesa-imaging.ch/drivers.php), but I can't make use of
pointers.

I can't seem to define a function that one of its arguments it's a pointer
(a function that initialize the structure). I'm also having troubles with
using the SR_GetImage that returns a void* pointer.

My code is as follows:

import numpy

cdef extern from "libMesaSR.h":
   ctypedef SRCAM
   int SR_OpenUSB(SRCAM * cam, unsigned int serial)
   int SR_ReadSerial(SRCAM cam)
   int SR_GetRows(SRCAM cam)
   int SR_GetCols(SRCAM cam)
   void * SR_GetImage(SRCAM cam, unsigned int i)

cdef class MesaSR:
   cdef SRCAM cam
   cdef int cols
   cdef int rows
   cdef object range_image

   def __init__(self, serial):
      status = SR_OpenUSB(&self.cam, serial)
      self.cols = SR_GetCols(self.cam)
      self.rows = SR_GetRows(self.cam)
      self.range_image = numpy.empty([self.rows, self.cols], 'H')

   def get_image(self):
      cdef void * images
      cdef unsigned int value
      image = SR_GetImage(self.cam, 0)
      for 0 <= i < self.cols:
         for 0 <= j <self.rows:
            value = image[i + j*self.cols]
            self.range_image[j][i] = value

And I'm getting:
mesasr.pyx:5:22: Pointer base type cannot be a Python object
mesasr.pyx:18:22: Cannot take address of Python variable
mesasr.pyx:26:21: Cannot convert 'void *' to Python object

Am I missing something?
-- 
Javier Correa

Por favor, no imprimas este e-mail si realmente no lo necesitas... Conservar
el medio ambiente es nuestra tarea...
Please, don't print this e-mail if it's not needed... preserve the
environment is our task...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.copyleft.no/pipermail/pyrex/attachments/20101109/ffb6828c/attachment.html>


More information about the Pyrex mailing list