ctypes, function pointers and a lot of trouble

Matt mr.edel at gmx.at
Wed May 28 09:42:22 EDT 2008


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.

In C the code looks as follows (found in an supplemental *.h SDK file:

------------------------------CODE-----------------------------------------

#define cdSTDCALL __stdcall

typedef void    cdSTDCALL cdSOpen(cdContext contextH, cdPermission, 
cdError* err);
typedef void    cdSTDCALL cdSClose(cdContext contextH, cdError* err);
typedef void    cdSTDCALL cdSRead(cdContext contextH, void* buf, 
cdUInt32* bufsize, cdError* err);
typedef void    cdSTDCALL cdSWrite(cdContext contextH, const void *buf, 
cdUInt32* bufsize, cdError *err);
typedef void    cdSTDCALL cdSSeek(cdContext contextH, cdWhence, cdInt32 
offset, cdError* err);
typedef cdInt32 cdSTDCALL cdSTell(cdContext contextH, cdError* err);
typedef void    cdSTDCALL cdSProgress(cdContext contextH, cdUInt16 
percentDone, cdError* err);

/* cdStream
*/
typedef struct {
    cdContext contextH;
    /* stream I/O function pointers */
    cdSOpen*      open;
    cdSClose*      close;
    cdSRead*      read;
    cdSWrite*      write;
    cdSSeek*      seek;
    cdSTell*      tell;
} cdStream;

/* cdStgMedium
*/
typedef struct {
      cdMemType      Type;   /* Type of the medium (u). */
      union {
       cdChar*      lpszFileName;
       cdStream*   pStream;
       #ifdef   macintosh
       cdFSSpec*   pFSSpec;
       #endif
      }u;                  /* Union of all transfer medium */
} cdStgMedium;

------------------------------\CODE----------------------------------------

and this is the function definition that should give me access to the 
data stream (available via DLL):

------------------------------CODE-----------------------------------------

cdCAPI CDGetReleasedData(
           cdHSource hSource,
           cdProgressCallbackFunction * pCallbackFunc,
           cdContext Context,
           cdProgressOption ProgressOption,
           cdReleaseImageInfo* pInfo,
           cdStgMedium* pStgMedium
);

------------------------------\CODE----------------------------------------

So, since I'm no C-Professional, I can only guess what that code does. 
With some previous commands I tell the camera to make a picture. This 
picture is then automatically moved to the PCs RAM and with the function 
above (CDGetReleasedData) I should be able to access this stream. Now I 
havn't accessed any stream with ctypes yet so I have only a rough idea 
how it could work.

The following are the relevant parts of my code that don't work:

------------------------------CODE-----------------------------------------

# Definitions:

class cdReleaseImageInfo(Structure):
     _fields_ = [("SequenceID", c_uint),
                      ("DataType", c_uint),
                      ("Format", c_ubyte),
                      ("DataSize", c_uint),
                      ("Filename", c_char * 2)]


class cdStream(Structure):
     _fields_ = [("contextH", c_uint),
                      ("open", c_uint),
                      ("close", c_uint),
                      ("read", c_uint),
                      ("write", c_uint),
                      ("seek", c_uint),
                      ("tell", c_uint)]

class memunion(Union):
     _fields_ = [("lpszFileName", c_char),
                      ("pStream", cdStream)]


class cdStgMedium(Structure):
     _fields_ = [("Type", c_uint),
                      ("u", memunion)]




# command:

datainfo = cdReleaseImageInfo()
data = cdStgMedium()
errorcode = cdsdk.CDGetReleasedData(devicehandle, byref(cbfunct), 
c_uint(1), c_uint(1), byref(datainfo), byref(data))

------------------------------\CODE----------------------------------------


The function "cdsdk.CDGetReleasedData" itself gets executed correctly, 
but returns an "Invalid Parameter" errorcode. there's also no useful 
data whereas datainfo gets written correctly. I know that my cdStream 
can't work, facing the C-code, but what'd be the right cdStream class? 
What can I do? Any ideas?

Best regards and thanks,
Matt




More information about the Python-list mailing list