背景
我有一些用Python编写的分析软件,必须将一个4096字节的列表(看起来像这样 [80, 56, 49, 50, 229, 55, 55, 0, 77, ......]
)传递给一个dll,以便该dll将其写入设备。
- 要写入的字节存储在变量名data中
必须从Python调用的c函数(在dll中)是
int _DLL_BUILD_ IO_DataWrite(HANDLE hDevice, unsigned char* p_pBuff, unsigned char p_nByteCntInBuff);
我无法访问dll代码
尝试的方法
我尝试声明了一个数据类型
data_tx = (ctypes.c_uint8 * len(data))(*data)
并调用该函数
ret = self.sisdll.IO_DataWrite(self.handle, ctypes.byref(data_tx), ctypes.c_uint8(pending_bytes))
问题
没有报错,但是它没有工作。使用 C 和 C++ 调用 API 是可行的。
我是否做得正确?请问有谁可以指出我的错误?
IO_DataWrite.argtypes = [c_void_p, POINTER(c_uint8), c_uint8]
? - David Ranieridata_tx = (ctypes.c_uint8 * len(data))()
,然后将数据复制到数组中,并使用ctypes.byref
调用库。你可以尝试这种方法,而不是从数据构建数组。 - Jens Munk