无法通过 Python 会跳函数给 C 程序传入参数赋值

2016-12-06 18:36:54 +08:00
 ChemicalBlue

无法通过 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 = []

1815 次点击
所在节点    Python
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/325729

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX