无法通过 Python 回调函数给 C 程序参数赋值,请帮忙看下 谢谢
Python 给 C 程序提供了一个回调函数,以返回 IMSI
global cbGetIMSI
CB_GET_IMSI = CFUNCTYPE(None, c_char_p)
cbGetIMSI = CB_GET_IMSI(py_getIMSI)
def py_getIMSI(imsi):
global tc
tc = import(mod)
imsi = tc.getIMSI()
print '####### imsi = ' + imsi
#通过 C 程序提供的借口注册回调函数
lib_inf = cdll.LoadLibrary(self.libinf.get())
lib_inf.inf_regCbGetImsi(cbGetIMSI)
#C 程序注册回调
typedef void (*inf_PyCbGetImsi)(char *);
int inf_regCbGetImsi(inf_PyCbGetImsi cbFn)
{
DBG("enter [%s()]", FUNCTION);
if (!cbFn)
{
return -1;
}
g_pyCB.getImsi = cbFn;
return 0;
}
#C 程序调用 Py 回调
unsigned char aIMSI[15];
memset(aIMSI, 0, sizeof(aIMSI));
if (g_pyCB.getImsi)
{
g_pyCB.getImsi(aIMSI);
}
DBG("[%s()] aIMSI = [%s]", FUNCTION, aIMSI);
运行结果
####### imsi = 001010123456789
[gnss_lcsGetIMSI()] aIMSI = []