Reputation: 237
I have a C function which takes a int and returns by filling up the value in b
typedef uint8_t State;
#define STATE_POWERDOWN ((State) 0x00)
#define STATE_SLEEP ((State) 0x10)
int Val_GetStatus(int a , State *b)
This function alongwith others has been exported from a C DLL.
I call this function from python. While I am able to connect with the DLL I don't understand how to pass a variable to this function in python ?
def Acme_getDeviceStatus(self,DeviceStatus):
# b
self.device.Val_GetStatus(0,b) # how to pass and get value in b
# DeviceStatus = b
# return DeviceStatus somehow
Upvotes: 1
Views: 3221
Reputation: 4058
You can use for example ctypes or swig to call C functions in Python.
from ctypes import *
Val_GetStatus= CDLL('x').Val_GetStatus
Val_GetStatus.argtypes = [c_int,POINTER(c_unit8)]
Val_GetStatus.restype = c_int
deviceStatus = ctypes.c_uint8()
print Val_GetStatus(0, byref(deviceStatus))
print deviceStatus.value
Swig will generate kind of interface for you, so you don't have to do it manually.
Upvotes: 6