V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ChemicalBlue
V2EX  ›  Python

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

  •  
  •   ChemicalBlue · 2016-12-06 18:36:54 +08:00 · 1804 次点击
    这是一个创建于 2691 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2434 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:59 · PVG 23:59 · LAX 08:59 · JFK 11:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.