473,769 Members | 7,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pointers and ctypes

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_ReadPor t
ReadOPort.argty pes = [c_ushort, c_ushort, c_ulong]
ReadOPort.resty pe = 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

Aug 29 '05 #1
3 5005
Le 29 Aug 2005 06:19:17 -0700, ru**********@we b.de 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_ReadPor t
ReadOPort.argty pes = [c_ushort, c_ushort, c_ulong]
ReadOPort.resty pe = 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.argty pes = (c_ushort, c_ushort, ctypes.POINTER( c_ulong) )
ReadOPort.resty pe = c_short
status = c_ulong() # status value to be read
number = c_ushort(1) # CardNumber = 1
port = c_ushort(11)
rc = ReadOPort(numbe r, port, ctypes.byref(st atus))
print rc, ststus
Thanks a lot

Carlo and Pierre

Aug 29 '05 #2
thanks a bunch, i just got the answer myself. next time i think about
it a little longer.
thanks again
carlo

Aug 29 '05 #3
F. Petitjean wrote:
Le 29 Aug 2005 06:19:17 -0700, ru**********@we b.de a écrit :

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

ReadOPort.argty pes = (c_ushort, c_ushort, ctypes.POINTER( c_ulong) )
ReadOPort.resty pe = c_short
status = c_ulong() # status value to be read
number = c_ushort(1) # CardNumber = 1
port = c_ushort(11)
rc = ReadOPort(numbe r, port, ctypes.byref(st atus))
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

Aug 29 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
2502
by: Thomas Heller | last post by:
ctypes 0.9.2 released - Oct 28, 2004 ==================================== Overview ctypes is a ffi (Foreign Function Interface) package for Python 2.3 and higher. ctypes allows to call functions exposed from dlls/shared libraries and has extensive facilities to create, access and manipulate
3
5547
by: Lenard Lindstrom | last post by:
Posted in a previous thread was some Python code for accessing Window's Simple MAPI api using the ctypes module. http://groups-beta.google.com/group/comp.lang.python/msg/56fa74cdba9b7be9 This Simple MAPI module was Ian's completed version of an example I had posted in an earlier message. In it I had to set some pointer fields in a C structure to NULL. I was not happy with the solution I used so I made an inquiry on the ctypes-users...
2
3633
by: Richard Jones | last post by:
Does anyone know how to do the equivalent of this using ctypes? image_data = malloc(width * height * components); row_pointers = png_get_rows(png_ptr, info_ptr); for (y = 0; y < height; y++) memcpy(&image_data, row_pointers, width * components); That is, I need to get the address of a location *within* an allocated
1
4727
by: sjdevnull | last post by:
Hey, I'm trying to wrap GNU readline with ctypes (the Python readline library doesn't support the callback interface), but I can't figure out how to set values to a variable inside the library. This is Python 2.5 on Linux. Here's what I have so far--if you comment out the memmove call (3 lines) it works as expected: # START #!/usr/local/bin/python2.5
2
3412
by: Diez B. Roggisch | last post by:
Hi, I'm working under mac os x with the OpenCV-library that I load via ctypes. From a ObjectiveC-methodcall I get an integer, that "really" is a pointer to an IplImage-structure. I've got a function that takes such a pointer. But I don't find a way to pass it to that very function.
0
989
by: stalex | last post by:
I'm wrapping a C function exists in a shared library. Its prototype looks like as follows int getFileNames(int aSize, char **names); The documentation says that the asSize is the number of entries to be returned and names is output array of character pointers of at least aSize elements. So, I defined a function prototype in python, follow ctypes tutorial, and try to run
6
12925
by: Jack | last post by:
I'm not able to build IP2Location's Python interface so I'm trying to use ctypes to call its C interface. The functions return a pointer to the struct below. I haven't been able to figure out how I should declare the return type of the functions and read the fields. Any hint is appreciated. typedef struct { char *country_short; char *country_long;
9
7350
by: Matt | last post by:
Hi friends, Okay so well, I have quite a problem right now with a file stream. What I am doing is to use the Cannon SDK dlls to get control over my old Cannon A60 Camera for some surveillance useage. By using ctypes it all worked well until now. I am able to load the dlls, use a lot of functions, am able to connect to the camera, read out some params, send commands etc... but now I am stuck with reading the picture data.
3
4807
by: Ron Garret | last post by:
CTypes on a 64-bit machine appears to be truncating pointers to 32 bits: $ uname -a Linux monster1 2.6.18-6-amd64 #1 SMP Mon Jun 16 22:30:01 UTC 2008 x86_64 GNU/Linux $ cat foo.c void* foo(void* x) { return x; } $ gcc -fPIC -shared foo.c -o foo.so $ file foo.so foo.so: ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.