Python 将指针传递到结构中的结构中的数据数组(ctypes)

Python 将指针传递到结构中的结构中的数据数组(ctypes),python,python-2.7,numpy,struct,ctypes,Python,Python 2.7,Numpy,Struct,Ctypes,我有一个ctypes函数,它有一个结构,包含另一个结构,作为它的参数之一。 我创建了如下结构: class ChannelDataBuffers(Structure): _pack_ = PACK _fields_ = [ ("bufferMax", c_void_p), ("bufferMin", c_void_p), ("dataType", c_int32) ] class DataBuf

我有一个ctypes函数,它有一个结构,包含另一个结构,作为它的参数之一。 我创建了如下结构:

class ChannelDataBuffers(Structure):
_pack_ = PACK
_fields_ = [
            ("bufferMax",  c_void_p),
            ("bufferMin", c_void_p),
            ("dataType", c_int32)
            ]


class DataBuffers(Structure):
_pack_ = PACK
_fields_ =  [
                ("channel",               c_int32),
                ("waveform",              c_uint64),
                ("downSampleRatioMode",   c_int32),
                ("read",                  c_int32),
                ("buffers",               ChannelDataBuffers),
                ("nbuffers",              c_uint32),
                ("nDistributionPoints",   c_uint32)
            ]
def __init__(self, channel, waveform, ratiomode, read, ref_buffermax, ref_buffermin, datatype, nbuffers, nDistributionPoints):

    self.channel = c_int32(channel)
    self.waveform = c_uint64(waveform)
    self.downSampleRatioMode = c_int32(ratiomode)
    self.read = c_int32(read)
    self.buffers.bufferMax = (ref_buffermax)
    self.buffers.bufferMin = (ref_buffermin)
    self.buffers.datatype = c_int32(datatype)
    self.nbuffers = c_uint32(nbuffers)
    self.nDistributionPoints = c_uint32(nDistributionPoints)
bufferMax和bufferMin都是numpy数组,使用.ctypes参数-ie传递,定义如下:

bufMax = self._buffers[bufIndex].data.ctypes
这将导致一个对象被传递到的DataBuffers init函数中

numpy.core._internal._ctypes object at 0x08D99D90
这似乎是明智的。 然而,我随后遇到了一个例外

 cannot be converted to pointer <type 'exceptions.TypeError'>

有人知道我能做些什么来解决这个问题吗???

可能你需要使用
ctypes.cast

self.buffers.bufferMax = ctypes.cast(ref_buffermax, c_void_p)

您可能需要使用
ctypes.cast

self.buffers.bufferMax = ctypes.cast(ref_buffermax, c_void_p)

Thank-似乎已经工作(不再例外,尽管驱动程序没有从内部结构获取正确的值)Thank-似乎已经工作(不再例外,尽管驱动程序没有从内部结构获取正确的值)