繁体   English   中英

Python使用ctypes传递参数,参数无效

[英]Python passing parameters with ctypes, invalid parameter

我是python中的新手,最近使用python编程CCD相机拍照。 我想使用ctypes调用.so文件中的函数。 该函数的原型是:

INT is_ImageFile (HIDS hCam, UINT nCommand, void* pParam, UINT cbSizeOfParam)

HIDS是uint类型。 正式给出c代码的例子是:

is_ImageFile(m_hCam, IS_IMAGE_FILE_CMD_SAVE, (void*)&ImageFileParams,
                   sizeof(ImageFileParams));

其中ImageFileParams是结构类型:

typedef struct{
wchar_t* pwchFileName;
UINT     nFileType;
UINT     nQuality;
char**   ppcImageMem;
UINT*    pnImageID;
BYTE     reserved[32];}IMAGE_FILE_PARAMS;

在我的.py文件中,我尝试以这种方式定义结构:

class IMAGE_FILE_PARAMS(Structure):
_fields_=[("pwchFileNmae",c_wchar_p),("nFileType",c_uint),("nQuality",c_uint),("ppcImageMem",POINTER(c_char_p)),("pnImageID",POINTER(c_char_p)),("reserved",c_byte*32)]

并以这种方式定义一些成员:

ImageFileParams.pwchFileName = c_wchar_p("/home/user/aa.jpg")
ImageFileParams.nQuality=c_uint(80)
ImageFileParams.nFileType=c_uint(1)

然后调用函数:

is_ImageFile(hCam, IS_IMAGE_FILE_CMD_SAVE, cast(pointer(ImageFileParams),c_void_p),c_uint(sizeof(ImageFileParams)))

但我总是得到一个指示无效参数的错误。 有什么问题?

我相信你因为最后一个参数而得到无效参数错误:

c_uint(sizeof(ImageFileParams))

我检查了他们的IDS网站上的文档和一些示例代码 ,我认为你需要像这样调用它(假设你导入他们的ueye库:

is_ImageFile(hCam, ueye.IS_IMAGE_FILE_CMD_SAVE, ImageFileParams,ueye.sizeof(ImageFileParams))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM