I have a large piece of C code on top of which i am writing Python Wrappers. I have segregated the code compiled the shared library successfully and able to load it as well from the Python code.
Now I wanted to call a method which takes the pointer to a structure. The code works fine if I dont call the method , which means I am probably correct in converting the c data structure to equivalent ctypes, but when I am calling the method with the pointer i am getting error :
Below is the c data structure :
typedef struct
{
pwm_properties pwm_prop;
uint8_t bytecount;
uint32_t portnum;
uint8_t *return_value;
uint16_t channels;
uint8_t temporrary_buffer[1024];
} pwm_configuration;
typedef struct
{
uint16_t delta_sigma;
uint8_t duty_cycle;
uint32_t sv_m;
uint8_t duty_cycle;
int id;
} pwm_properties;
Below is the python code ;
class pwm_properties(Structure):
_fields_ = [
("delta_sigma",c_uint16),
("duty_cycle", c_uint8),
("sv_m", c_uint32),
("duty_cycle", c_uint8),
("id", c_int)
]
class pwm_configuration(Structure):
_fields_ = [
("pwm_prop",pwm_properties),
("bytecount", c_uint8),
("portnum", c_uint32),
("return_value", POINTER(c_uint8)),
("channels", c_uint16),
("temporrary_buffer", c_uint8*1024)
]
Use #1 :
l = pwm_properties()
p = byref(l)
status = add_lib.__init_(p)
***Segmentation fault (core dumped)***
Anyone know how can I achieve calling below c method : init(&pwm_configuration.pwm_properties)
in python.
EDIT : It worked as @user673679 has suggested.