[Pyrex] Overlapped I/O

Steve W. Hanawalt Steve.Hanawalt at silabs.com
Tue Jun 24 16:27:28 CEST 2003


> I am trying to make a DLL accessible to python using Pyrex, but I've
> run in= to a problem with overlapped I/O.  Do you have any suggestions
> on how to declare the following in Pyrex?

If the problem is because of the nested union/struct, you'll
have to separate them out and give them explicit type names,
e.g.

  cdef extern from "relevantheader.h":

    cdef struct _OffsetStruct:
      DWORD Offset
      DWORD OffsetHigh

    cdef union _OffsetUnion:
      _OffsetStruct off
      PVOID Pointer

    ctypedef struct OVERLAPPED:
      ULONG_PTR Internal
      ULONG_PTR InternalHigh
      _OffsetUnion u
      HANDLE hEvent

    ctypedef OVERLAPPED *LPOVERLAPPED
[swh] I tried this, but does this give me access from Python to the hEvent member?  Here's an example of how M. Hammond uses this structure in Python:
        if size > 0:
            overlapped = win32file.OVERLAPPED()
            overlapped.hEvent = win32event.CreateEvent(None, 1, 0, None)
            if self.timeout == 0:
                n = min(self.getRxQueueStatus(), size)
                if n > 0:
                    rc, buf = win32file.ReadFile(self._handle, win32file.AllocateReadBuffer(n), overlapped)
                    win32event.WaitForSingleObject(overlapped.hEvent, win32event.INFINITE)
                    read = str(buf)
            else:
                rc, buf = win32file.ReadFile(self._handle, win32file.AllocateReadBuffer(size), overlapped)
                n = win32file.GetOverlappedResult(self._handle, overlapped, 1)
                read = str(buf[:n])
Basically I am implementing the same function, but calling a DLL that allows me to talk serially to a USB device. I can't use the built-in windows COM driver because I need to go through the DLL supplied by the USB device vendor.  I looked through some of the code that M. Hammond has written in C and SWIG, but I already have most of the wrapper done and working with Pyrex(which I love in comparison).  I had originally plodded down the SWIG road without success.  Do you know of anyway to get Pyrex to handle the overlapped structure the same way the M. Hammond's code does?  That would be ideal because then anything written for regular COM ports would be easily portable to this USB COM port.  My USB DLL provides 4 functions that use the overlapped structure: ReadFile, WriteFile, WaitCommEvent and GetOverlappedResult functions.  Ideally I'd still like to use M.Hammonds win32file to create the structure and to assign the event.  Any suggestions?
Thanks for the feedback,
Steve


Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,          | A citizen of NewZealandCorp, a       |
Christchurch, New Zealand          | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz         +--------------------------------------+

This email and any attachments thereto may contain private, confidential, 
and privileged material for the sole use of the intended recipient. Any 
review, copying, or distribution of this email (or any attachments thereto) 
by others is strictly prohibited. If you are not the intended recipient, 
please contact the sender immediately and permanently delete the original 
and any copies of this email and any attachments thereto.



More information about the Pyrex mailing list