QHYCCD

Receiving image using Python Ctypes

Receiving image using Python Ctypes
« on: January 07, 2018, 06:11:19 pm »
I'm currently working on using Python ctypes library to control the SDK for a QHY183 camera. Thus far, I've been rewriting the single frame capture cpp example in Python without issues. Except when it comes to capturing the image itself. Below is an example of how I'm calling the particular function; assume all except the imgdata input variable are fine. The same order of functions are called successfully prior to this point in the script.
The issue arises that the GetQHYCCDSingleFrame function never returns.

I've since used the debugging SDK and monitored the messages from both my Python script and the working C++ example. The difference between the two scripts' output debug messages is with "Data in DDR". My Python script continues to output debug messages saying "Data in DDR 0" and does not return. Below are examples of the successful C++ and unsuccessful Python debug messages, respectively.

I'm hoping someone can help explain the difference, or point out where I might have made a mistake.

C++ sample (works)
QHYCCD |  -------------------GetSingleFrame-------------------
QHYCCD |  ++++++++++++++ 5640 3710 12
QHYCCD | QHY5III183BASE.CPP ThreadCountExposureTime beginThe thread 0xf40 has exited with code 0 (0x0).
QHYCCD |  Approx DDR 40867
QHYCCD |  Approx DDR Target 40866 now continous to check the ddr 3408
QHYCCD |  QHY5III183BASE GetSingleFrame  Data In DDR 4248
QHYCCD |  QHY5III183BASE GetSingleFrame  Data In DDR 58220
QHYCCD |  QHY5III183BASE GetSingleFrame wait stable 58220
QHYCCD |  Begin Trasnfer Data From DDR to computer  DDR  58220
QHYCCD |  TotalRead  2911 QHYCCDRD | QUSB.CPP LENGTH 20480


Python script (doesn't work)
QHYCCD |  -------------------GetSingleFrame-------------------
QHYCCD |  ++++++++++++++ 5640 2018 8
QHYCCD |  Approx DDR 22229
QHYCCD |  Approx DDR Target 22228
now continous to check the ddr 0
QHYCCD |  QHY5III183BASE GetSingleFrame  Data In DDR 0
QHYCCD |  QHY5III183BASE GetSingleFrame  Data In DDR 0


Code: [Select]
# GetQHYCCDSingleFrame(qhyccd_handle *handle,uint32_t *w,uint32_t *h,uint32_t *bpp,uint32_t *channels,uint8_t *imgdata);

# Define inputs
imgdata = (ctypes.c_uint8 * image_size)()
width = ctypes.c_uint32(width)
height = ctypes.c_uint32(height)
depth = ctypes.c_uint32(depth)
channels = ctypes.c_uint32(channels)

retval = qhyccd_lib.GetQHYCCDSingleFrame(camhandle,
                                             ctypes.byref(width),
                                             ctypes.byref(height),
                                             ctypes.byref(depth),
                                             ctypes.byref(channels),
                                             imgdata)  #note passing by reference does not alter output

Re: Receiving image using Python Ctypes
« Reply #1 on: January 08, 2018, 08:02:53 pm »
UPDATE
This issue only occurs when calling for an 8bit image; see code below. Using the same function for 16bit or leaving the camera as default 16bit capture returns with image.

Code: [Select]
!# usr/bin/env python
qhyccd.SetQHYCCDBitsMode(camhandle,  ctypes.c_uint32(depth))  # depth = (8 | 16)

LCH

Re: Receiving image using Python Ctypes
« Reply #2 on: January 09, 2018, 08:41:43 pm »
Hello,
       Is it OK to call 8bit mode in C++ sample?
       In fact,in the debug print "QHYCCD |  ++++++++++++++A,B,C" C means the actual chipoutbits . In 183C,the chipoutbits is 12 for 16-bit mode and 8 for 8-bit mode.So in that sample it is 16-bit mode in C++.Maybe you can try 8-bit as well in C++ to see if the problem appears.

Best Regards,
Li Chenghan

LCH

Re: Receiving image using Python Ctypes
« Reply #3 on: January 09, 2018, 09:00:57 pm »
I forgot this...Some camera doesn't support 8bits readout in single frame mode. 183C is one of them .

Re: Receiving image using Python Ctypes
« Reply #4 on: January 09, 2018, 10:36:19 pm »
I forgot this...Some camera doesn't support 8bits readout in single frame mode. 183C is one of them .

That would explain it. And good catch, the C++ script was not returning for 8 bits but 16bits.
You're completely right. I ran C++ with 8bit single capture and it failed to return. I then tried both scripts in live capture at 8 bits and both the C++ and Python scripts returned images.
Thanks for your help.