Pointers and ctypes

R

rubbishemail

Hello,
i've got a problem with pointers in the following function which i want
to use:

I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value)

The function is supposed to read out the status of a digital port of
analog digital interface card.
I got this function from Dask.h which came with the card. The relevant
lines concerning this function are the following:

typedef short I16;
typedef unsigned short U16;
typedef unsigned long U32;

I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value)

I tried to implement this function into python:
# I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value);
ReadOPort = dask.DO_ReadPort
ReadOPort.argtypes = [c_ushort, c_ushort, c_ulong]
ReadOPort.restype = c_short

I can't handle the pointer "Value" which should be an unsigned long
pointer. I'd be very happy, if u could give me a hint how to implement
this pointer into python.

Thanks a lot

Carlo and Pierre
 
F

F. Petitjean

Le 29 Aug 2005 06:19:17 -0700, (e-mail address removed) a écrit :
Hello,
i've got a problem with pointers in the following function which i want
to use:

I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value)

The function is supposed to read out the status of a digital port of
analog digital interface card.
I got this function from Dask.h which came with the card. The relevant
lines concerning this function are the following:

typedef short I16;
typedef unsigned short U16;
typedef unsigned long U32;

I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value)

I tried to implement this function into python:
# I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value);
ReadOPort = dask.DO_ReadPort
ReadOPort.argtypes = [c_ushort, c_ushort, c_ulong]
ReadOPort.restype = c_short

I can't handle the pointer "Value" which should be an unsigned long
pointer. I'd be very happy, if u could give me a hint how to implement
this pointer into python.

You can use the ctypes.byref() function (as it is in an argulent list):

ReadOPort.argtypes = (c_ushort, c_ushort, ctypes.POINTER(c_ulong) )
ReadOPort.restype = c_short
status = c_ulong() # status value to be read
number = c_ushort(1) # CardNumber = 1
port = c_ushort(11)
rc = ReadOPort(number, port, ctypes.byref(status))
print rc, ststus
 
R

rubbishemail

thanks a bunch, i just got the answer myself. next time i think about
it a little longer.
thanks again
carlo
 
M

Mike C. Fletcher

F. Petitjean said:
Le 29 Aug 2005 06:19:17 -0700, (e-mail address removed) a écrit :

....

You can use the ctypes.byref() function (as it is in an argulent list):

ReadOPort.argtypes = (c_ushort, c_ushort, ctypes.POINTER(c_ulong) )
ReadOPort.restype = c_short
status = c_ulong() # status value to be read
number = c_ushort(1) # CardNumber = 1
port = c_ushort(11)
rc = ReadOPort(number, port, ctypes.byref(status))
print rc, ststus
Just as an FYI, Thomas has recently added code which does the byref
automatically. The version of ctypes in CVS HEAD will allow you to pass
in a c_ulong where the argtype is ctypes.POINTER(c_ulong).

Have fun,
Mike

--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top