【发布时间】:2014-11-01 19:49:59
【问题描述】:
我尝试通过带有 python 的 c dll 与 HV-Supply 进行通信。我开始工作的最简单的功能。但是,如果我调用更复杂的函数 CAENHVInitSystem,我会得到一个错误:OSError:异常:访问冲突读取 0x00000001。我对 Python 中的 ctypes 很陌生。据我所知,这个错误可能是因为我的一些论点类型错误。但是我如何才能更多地调试它以确切地知道哪个参数是错误的?有人看到我的错误吗?
提前致谢
import os
from ctypes import *
bib = CDLL("CAENHVWrapper")
ret = bib.CAENHVLibSwRel() # This call works
print(c_char_p(ret))
sysType = c_int(1) #SY2527
link = c_int(0) #TCP/IP
#arg = c_char_p(b'149.217.10.241') #i change it for test to c_void_p but later the arg should be the ip adress
arg = c_void_p()
user = c_char_p(b'admin')
passwd = c_char_p(b'admin')
sysHndl = c_int()
# c function definition in the header file
#CAENHVLIB_API CAENHVRESULT CAENHV_InitSystem(
# CAENHV_SYSTEM_TYPE_t system,
# int LinkType,
# void *Arg,
# const char *UserName,
# const char *Passwd,
# int *handle);
# definition of the enum of the first argument
#typedef enum {
# SY1527 = 0,
# SY2527 = 1
#} CAENHV_SYSTEM_TYPE_t;
bib.CAENHVInitSystem.argtypes = [c_int, c_int, c_void_p, c_char_p, c_char_p, POINTER(c_int)]
ret = bib.CAENHVInitSystem(sysType, link, arg, user, passwd, byref(sysHndl))
print(ret)
print(bib.CAENHV_GetError(sysHndl))
【问题讨论】: