1

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 
3
  • How is State defined in C? Commented Oct 14, 2014 at 14:54
  • @wenzul updated with definition of State Commented Oct 14, 2014 at 14:59
  • Maybe this could help: docs.python.org/2/library/… Commented Oct 14, 2014 at 15:01

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.