Thursday 15 July 2010

Using python ctypes and libc to write void pointer to binary file -


I am using Python CTIPs and libc to interface with the DLL file provided by a vendor. The purpose of the DLL file is to get an image from a camera.

Image acquisition seems to run without error; The problem I'm having is accessing data.

Image Acquisition Action takes a CTIPCDC_VID_p as an argument for image data.

Simple: <("Initial_readout", ctypes.c_void_p), ("readout_count") can be used as follows. , Ctypes.c_longlong]] "" Get the prototype (camhandel camera, int64 readout_mount, int readout_timeout, available data available *, exciznors masks * errors); " "" & Gt; & Gt; & Gt; ImageData = Available Data ()> gt; & Gt; & Gt; Acquire.argtypes = CamHandle, ctypes.c_longlong, ctypes.c_int, ctypes.POINTER (available data), ctypes.POINTER (Acquisition errors mask) & gt; & Gt; & Gt; Acquire.restype = ctypes.c_void_p> & Gt; & Gt; Position = get (camera, readout_count, readout_time_out, imageData, errors)

I have not fully understood what the function is doing, because after running the function, imageData .initial_readout It looks like a type 'tall' (not even a CTIPC). However, there is also the value associated with it. I am assuming that this data is the collected data.

  & gt; & Gt; & Gt; Type (imageData.initial_readout) & lt; Type 'Long' & gt; & Gt; & Gt; & Gt; My current approach to accessing data is to use libc.fopen, libc.fwrite, libc.fclose as follows:  
  

& gt; & Gt; & Gt; Libc = ctypes.cdll.msvcrt & gt; & Gt; & Gt; Fopen = libc.fopen & gt; & Gt; & Gt; Fwrite = libc.fwrite & gt; & Gt; & Gt; Fclose = libc.fclose & gt; & Gt; & Gt; Fopen.argtypes = ctypes.c_char_p, ctypes.c_char_p & gt; & Gt; & Gt; Fopen.restype = ctypes.c_void_p> & Gt; & Gt; Fopen.restype = ctypes.c_void_p> & Gt; & Gt; Fwrite.argtypes = ctypes.c_void_p, ctypes.c_size_t, ctypes.c_size_t, ctypes.c_void_p & gt; & Gt; & Gt; Fwrite.restype = ctypes.c_size_t> & Gt; & Gt; Fclose = libc.fclose & gt; & Gt; & Gt; Fclose.argtypes = ctypes.c_void_p, & gt; & Gt; & Gt; Fclose.restype = ctypes.c_int> & Gt; & Gt; Fp = fopen ('output3.raw', 'wb') & gt; & Gt; & Gt; Print 'Fillit Returns:', Eiffel (ctypes.c_void_p (imageData.initial_readout), readoutstride.value, 1, fp) Philhit Returns: 0 & gt; & Gt; & Gt; Fclose (fp)

Where readoutstride = 2,097,152 corresponding to 1024x1024 array of 16-bit pixels.

The file "output3 .raw" appears in the window explorer, however, it has 0 kbytes and when I try to open it (for example, with an image viewer) it says That file is empty.

I see that fwrite returns a value from 0 (but should return the value of 1)

What do you do wrong I'm here to have any ideas, so I appreciate it very much. Thank you in advance.

specify argtypes , restype .

  import ctypes libc = ctypes.windll.msvcrt fopen = libc.fopen fopen.argtypes = ctypes.c_char_p, ctypes.c_char_p, fopen.restype = ctypes.c_void_p fwrite = Libc.fwrite fwrite. Argtypes = ctypes.c_void_p ctypes.c_size_t ctypes.c_void_p fwrite.restype = ctypes.c_size_t fclose = libc.fclose fclose.argtypes = ctypes.c_void_p, fclose.restype = ctypes.c_int fp = fopen ('output3 ('Hello', 5, 1, FP) fclose (FP)    

No comments:

Post a Comment