ctypes 传递一个字节数组
ctypes pass an array of byte
我想从 python2.7
中的 DLL 中调用此 C 函数
uint8_t DLL_CONV Mag(uint8_t *t1, uint8_t *t2, uint8_t *t3);
此函数将数据写入通过引用发送的数组。
这是我目前的 python 代码
_mag = hDLL.Mag
#_mag.argtypes =[ctypes.POINTER(ctypes.c_ubyte),ctypes.POINTER(ctypes.c_ubyte),ctypes.POINTER(ctypes.c_ubyte)]
_mag.argtypes =[ctypes.c_ubyte *100,ctypes.c_ubyte *100,ctypes.c_ubyte*100]
_mag.restype = ctypes.c_ubyte
def mag():
t1 = (ctypes.c_ubyte * 100)()
t2 = (ctypes.c_ubyte * 100)()
t3 = (ctypes.c_ubyte * 100)()
s = _mag( (ctypes.c_ubyte *100)(t1), (ctypes.c_ubyte *100)(t2), (ctypes.c_ubyte *100)(t3) )
return t1,t2,t3
我总是在 s = _mag()
处遇到 TypeError
我未定义argtypes
然后像这样发送数组
s = _mag( (t1), (t2), (t3) )
我想从 python2.7
中的 DLL 中调用此 C 函数uint8_t DLL_CONV Mag(uint8_t *t1, uint8_t *t2, uint8_t *t3);
此函数将数据写入通过引用发送的数组。
这是我目前的 python 代码
_mag = hDLL.Mag
#_mag.argtypes =[ctypes.POINTER(ctypes.c_ubyte),ctypes.POINTER(ctypes.c_ubyte),ctypes.POINTER(ctypes.c_ubyte)]
_mag.argtypes =[ctypes.c_ubyte *100,ctypes.c_ubyte *100,ctypes.c_ubyte*100]
_mag.restype = ctypes.c_ubyte
def mag():
t1 = (ctypes.c_ubyte * 100)()
t2 = (ctypes.c_ubyte * 100)()
t3 = (ctypes.c_ubyte * 100)()
s = _mag( (ctypes.c_ubyte *100)(t1), (ctypes.c_ubyte *100)(t2), (ctypes.c_ubyte *100)(t3) )
return t1,t2,t3
我总是在 s = _mag()
我未定义argtypes
然后像这样发送数组
s = _mag( (t1), (t2), (t3) )