i'm trying to write a Python DLL Wrapper for a C Project
https://github.com/OpenEtherCATsociety/SOEM -> C Project
The Python DLL Wrapper can be found here: https://github.com/GitHubStefan13/SOEM-for-Python
Original C Code that is important:
char IOmap[4096];
int ec_config_overlap(uint8 usetable, void *pIOmap);
Python Wrapper
IOMap = ctypes.POINTER(ctypes.c_char * 4096)
c_ec_config_overlap = ethercat.ec_config_overlap c_ec_config_overlap.argtypes = [ctypes.c_unit8, IOMap] c_ec_config_overlap.restype = ctypes.c_int
When im trying to define a function in Python
def ec_config_overlap(usetable, PIOMap): return c_ec_config_overlap(usetable, PIOMap
and call it. I receive the error
ctypes.ArgumentError: argument 2: : expected LPc_char_Array_4096 instance instead of _ctypes.PyPointerType.
I understand the Error but how do i go around to actually make the ctype a Array[4096] instead of the PyPointerType?
This syntax creates array instances:
>>> import ctypes
>>> (ctypes.c_char*4096)()
<__main__.c_char_Array_4096 object at 0x0000024D84E2D7C8>
Since it is a char
array, you can also use:
>>> create_string_buffer(4096)
<__main__.c_char_Array_4096 object at 0x0000025AE48FE948>
The type of your function should be:
c_ec_config_overlap.argtypes = [ctypes.c_uint8, ctypes.c_void_p]
But for better type checking you can also use:
c_ec_config_overlap.argtypes = [ctypes.c_uint8, ctypes.c_char_p]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.