I have to control some hardware, which is controlled by a C interface.
The C interface is C++ header file, which contains some functions, one -called set_mirror()- which i need. This C file has also a int array, called voltage, which is used by set_mirror.
I am trying to use cython to build a python function, which implements a set_mir(volt) function. To do that, i have to set the voltage array, but i don’t know how to access it:
My pxy file:
cdef extern from 'mmdm_lin38usb.h':
int voltage[40]
int init_dac()
void close_dac()
void set_mirror()
init_dac()
def set_mir(volt):
for i in range(40):
# Only for testing, how to access to int array.
print voltage[i]
if len(volt)!=40:
raise "Need 40 values"
else:
volt=map(round,volt)
volt=map(int,volt)
voltage=volt
set_mirror()
Is unclear what the final operation is : do you want to set 40 values from a volt python list
into an array of 40 ints ? I would suggest something like the following. If possible
don’t modify the global int array. Watch out the voltage array is local.