推荐学习书目
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 · Dec 6, 2016 · 2626 views
    This topic created in 3444 days ago, the information mentioned may be changed or developed.

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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3345 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 13:59 · PVG 21:59 · LAX 06:59 · JFK 09:59
    ♥ Do have faith in what you're doing.