Call C function inside a C extension in Python[solved] -


I have tried to make Python a C extension. My problem is that I have the C function inside the call C function, I have created the C extension. For example, I am using C function, which is inside PMDH and usb1024LS.h inside these C functions. When I try to run my script, I get errors such as "Undefined Icons: HID_Inte", where hid_init is a function, I tried to run the program in C main program, and it works.

Thank you!

My code: test.py - test script:

  

code> import Sitiaipi Import myTest_1024LS ctypes_findInterface = ctypes.CDLL ( '/ home / oysmith / NetBeansProjects / MCCDAQ / usb1024LS_with_py_my/Test_1024LS.So '). FindInterface ctypes_findInterface.restype = ctypes.c_void_p ctypes_findInterface.argtypes = [ctypes.c_void_p] ctypes_findInterface () Distutils.core import setup extension setup (name = "myTest_1024LS", version = "0.0", ext_modules = [/ code>

setup.py:

  extensions ( "myTest_1024LS", [ "myTest_1024LS.c"]))   

myTest_1024LS.c:

  #include & lt; Stdlib.h & gt; # Include & lt; Stdio.h & gt; #include & lt; String.h & gt; # Include & lt; Unistd.h & gt; # Include & lt; Fcntl.h & gt; # Include & lt; Ctype.h & gt; # Include & lt; Sys / types.h & gt; #include & lt; Asm / types.h & gt; #include & lt; Python2.7 / Python.h & gt; #include "pmd.h" #include "usb-1024LS.h" #include "myTest_1024LS.h" Zero Search Interface (zero) {int interface; Hid_return ret; Ret = hid_init (); If (ret! = HID_RET_SUCCESS) {fprintf (stderr, "hid_init failed code% d \ n", ret retains); Exit (1); } If ((interface = Pimdi_fnd_intrfes (& amp; hidden, 0, USB 1024 Elsaipiaidi)) & gt; = 0) {printf ( "USB 1024 LS device has been found! Interface =% d \ n", interface); } Else if ((interface = Pimdi_fnnd_intrfes (and Acaiad, 0, USB 1024 Acelsaipiaidi)) gt; = 0) {Printf ( "USB 1024 Acelels device has been found! Interface =% d \ n", interfaces); } And {fprintf (stderr, "USB 1024 LS and USB 1024 HLLs have not been found. \ N"); Exit (1); }} PyDoc_STRVAR (myTest_1024LS__doc__, "myTes_1024LS point evaluation kernel"); PyDoc_STRVAR (findInterface__doc__, "Locate Device"); Fixed PyObject * py_findInterface (PyObject * self, PyObject * args); High PyMethodDef wrapper_methods [] = {{ "search interface", py_findInterface, METH_VARARGS, findInterface__doc__}, {NULL, NULL}}; PyMODINIT_FUNC initwrapper (zero) {Py_InitModule3 ("wrapper", wrapper_methods, myTest_1024LS__doc__); } Fixed PyObject * py_findInterface (PyObject * self, PyObject * args) {if (! PyArg_ParseTuple (Args, "")) {return tap; } FindInterface (); Return 0; While creating the C extension, the extension that requires itself to be linked to other shared libraries, you have to tell the linking between the  setup.py  that at least the library in this case < Code> hid_init ()  export functions For more information and examples see Python documentation: The second example argues to link an additional library in the extension module.  

ctypes One of the announcements is incorrect: zero is not equal to zero pointer ( zero * ). There is no logic in the findInterface () C function, nor the return value, which is "declared". As:

  ctypes_findInterface.argtypes = [] ctypes_findInterface.restype = any    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -