QHYCCD

GetQHYCCDLiveFrame() always returns -1 with QHY600M

ega

GetQHYCCDLiveFrame() always returns -1 with QHY600M
« on: December 02, 2020, 11:03:07 PM »
We have two QHY600M cameras in use at the telescope, which in principle are controlled through INDI.
The original problem was that the delay between consecutive single frames was far too large (between 2.5 and 3 seconds, similar to what has been reported in https://www.qhyccd.com/bbs/index.php?topic=7525.0; it would be nice to get that sorted out as well, but one thing at a time).
We've then tried to get the cameras work in live mode, not through INDI but with direct calls to the SDK API.
We tried to follow the suggestions from https://www.qhyccd.com/bbs/index.php?topic=7524.0 but that didn't work either:

The program flow is as follows:
Code: [Select]
    EnableQHYCCDLogFile(true);
    EnableQHYCCDMessage(true);
    SetQHYCCDLogLevel(6);

    InitQHYCCDResource();
    ScanQHYCCD();
    GetQHYCCDId(i, camId);
    OpenQHYCCD(camId);
    SetQHYCCDStreamMode(pCamHandle, 1);
    InitQHYCCD(pCamHandle);
    BeginQHYCCDLive(pCamHandle);
    GetQHYCCDMemLength(pCamHandle);

    GetQHYCCDLiveFrame(...) -> looping in a thread

    StopQHYCCDLive(pCamHandle);
    SetQHYCCDStreamMode(pCamHandle, 0x0);
    CloseQHYCCD(pCamHandle);
    ReleaseQHYCCDResource();

Everything returns QHYCCD_SUCCESS *except* GetQHYCCDLiveFrame(), which always returns -1. We have not managed to read even one single live frame.
We called GetQHYCCDParamMinMaxStep() for CONTROL_USBTRAFFIC and CONTROL_SPEED, and got

Code: [Select]
CONTROL_USBTRAFFIC min=0.000000 max=60.000000 step=1.000000
CONTROL_SPEED min=0.000000 max=1.000000 step=1.000000

Looking at some of the discussions on the forum, we tried to vary these two parameters within their respective min-max range.
The result is always the same: GetQHYCCDLiveFrame() returns -1 without exception.
We have also tried various versions of the SDK: 20.6.26, 20.7.24.2, 20.7.26.2, 20.8.26.1, 20.8.26.3, 20.11.11, 20.11.28, same result each time.
Also tried running the LiveFrameMode testapp directly - same result (it just waits forever for a valid frame).

The output from the various logs is as follows:

qhyccd.log
(the full output is attached to this post as qhyccd-log.txt)
Code: [Select]
...
2020-12-01 11:13:43:904|QHYCCD|QHYCCD.CPP|BeginQHYCCDLive|index=1
2020-12-01 11:13:43:904|QHYCCD|QHYBASE.CPP|GetChipMemoryLength|GetChipMemoryLength ccdIW:9600 * ccdIH:6422 126526800 IsColor 0
2020-12-01 11:13:43:904|QHYCCD|CMOSDLL.CPP| InitAsyQCamLive|InitAsyQCamLive x = 9600 y = 6456 depth = 8 framesize = 61977600
2020-12-01 11:13:43:904|QHYCCD|CMOSDLL.CPP|InitAsyQCamLive|InitAsyQCamLive 8
2020-12-01 11:13:43:904|QHYCCD|CMOSDLL.CPP|InitAsyQCamLive|InitAsyQCamLive before.frameLen=0 cydev[index].frameLen=9600 * 6456 * 8 /8
2020-12-01 11:13:43:904|QHYCCD|CMOSDLL.CPP|InitAsyQCamLive|InitAsyQCamLive after.frameLen=61977600   
2020-12-01 11:13:43:904|QHYCCD|CMOSDLL.CPP|InitAsyQCamLive|InitAsyQCamLive return 0
2020-12-01 11:13:43:904|QHYCCD|CMOSDLL.CPP|BeginAsyQCamLive| START
2020-12-01 11:13:43:905|QHYCCD|QHYCCD.CPP|QHYCCDSeriesMatch|current pid is 0xc601
2020-12-01 11:13:43:936|QHYCCD|QHYCCD.CPP|QHY5IIISeriesMatch|QHY5IIISeriesMatch|mainseries = 4061
2020-12-01 11:13:43:936|QHYCCD|QHYCCD.CPP|QHY5IIISeriesMatch|QHY5IIISeriesMatch|color = 0
2020-12-01 11:13:43:936|QHYCCD|LIBUSBIO.CPP|alloc_transfers|libusb_submit_transfer
2020-12-01 11:13:43:936|QHYCCD|LIBUSBIO.CPP|alloc_transfers|init libusb_submit_transfer failed!!! -1 0
2020-12-01 11:13:43:936|QHYCCD|QHYCCD.CPP|BeginQHYCCDLive|return value=0
2020-12-01 11:13:43:937|QHYCCD|QHYCCD.CPP|GetQHYCCDMemLength|START
2020-12-01 11:13:43:937|QHYCCD|QHYBASE.CPP|GetChipMemoryLength|GetChipMemoryLength ccdIW:9600 * ccdIH:6422 126526800 IsColor 0
2020-12-01 11:13:43:937|QHYCCD|QHYCCD.CPP|GetQHYCCDMemLengt|length=126526800
2020-12-01 11:13:44:015|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |111111111111111111111111111111111
2020-12-01 11:13:44:015|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |222222222222222222222222222222222222
2020-12-01 11:13:44:015|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |333333333333333333333333333333333333
2020-12-01 11:13:44:015|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |4444444444444444444444444444444444444
2020-12-01 11:13:44:035|QHYCCD|CMOSDLL.CPP|ReadAsyQCamLiveFrame 0 < 61977600 
2020-12-01 11:13:44:035|QHYCCD|CMOSDLL.CPP|ReadAsyQCamLiveFrame 61977600 = 9600 * 6456 * 8 /8 = 61977600
2020-12-01 11:13:44:036|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |5555555555555555555555555555555555
2020-12-01 11:13:44:037|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |111111111111111111111111111111111
2020-12-01 11:13:44:037|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |222222222222222222222222222222222222
2020-12-01 11:13:44:037|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |333333333333333333333333333333333333
2020-12-01 11:13:44:037|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |4444444444444444444444444444444444444
2020-12-01 11:13:44:042|QHYCCD|CMOSDLL.CPP|ReadAsyQCamLiveFrame 0 < 61977600 
2020-12-01 11:13:44:042|QHYCCD|CMOSDLL.CPP|ReadAsyQCamLiveFrame 61977600 = 9600 * 6456 * 8 /8 = 61977600
2020-12-01 11:13:44:043|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |5555555555555555555555555555555555
2020-12-01 11:13:44:044|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |111111111111111111111111111111111
2020-12-01 11:13:44:044|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |222222222222222222222222222222222222
2020-12-01 11:13:44:044|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |333333333333333333333333333333333333
2020-12-01 11:13:44:044|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |4444444444444444444444444444444444444

(then the last 7 lines are repeated forever, until the program is stopped).


libusb (using LIBUSB_DEBUG=4) - attached to this post as libusb-log.txt

dmesg
Code: [Select]
[1989027.459204] usb 2-1: reset SuperSpeed Gen 1 USB device number 5 using xhci_hcd
[1989027.733239] usb 2-1: LPM exit latency is zeroed, disabling LPM.
[1989027.863123] usb 2-1: reset SuperSpeed Gen 1 USB device number 5 using xhci_hcd
[1989027.883334] usb 2-1: LPM exit latency is zeroed, disabling LPM.
[1989028.046910] usb 2-1: usbfs: process 444815 (a.out) did not claim interface 0 before use


I believe the problem is with the SDK, possibly in its interaction with libusb, because of these messages:

qhylog:
Code: [Select]
2020-12-01 11:13:43:936|QHYCCD|LIBUSBIO.CPP|alloc_transfers|libusb_submit_transfer
2020-12-01 11:13:43:936|QHYCCD|LIBUSBIO.CPP|alloc_transfers|init libusb_submit_transfer failed!!! -1 0

libusb:
Code: [Select]
[ 3.923863] [0006c98f] libusb: debug [submit_bulk_transfer] need 1 urbs for new transfer with length 16384
[ 3.923915] [0006c98f] libusb: error [submit_bulk_transfer] submiturb failed error -1 errno=16

dmesg:
Code: [Select]
[1989028.046910] usb 2-1: usbfs: process 444815 (a.out) did not claim interface 0 before use

Output of lsusb -vvv is attached to this post as lsusb.txt.

More details about the machine to which the cameras are connected:

Code: [Select]
$ uname -a
Linux 5.4.0-53-generic #59-Ubuntu SMP Wed Oct 21 09:38:44 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal

libusb version is:
Code: [Select]
libusb-1.0-0:
  Installed: 2:1.0.23-2build1
  Candidate: 2:1.0.23-2build1

Any suggestion would be very much appreciated!

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #1 on: December 13, 2020, 07:51:19 PM »
Hi,
    You can try this API list,
Code: [Select]
InitQHYCCDResource();
num = ScanQHYCCD();
ret = GetQHYCCDId(i, id);
camhandle = OpenQHYCCD(id);
ret = SetQHYCCDReadMode(camhandle, 0);
ret = SetQHYCCDStreamMode(camhandle, 1);
ret = InitQHYCCD(camhandle);
ret = SetQHYCCDDebayerOnOff(camhandle, 0);
ret = GetQHYCCDChipInfo(camhandle, &chipw, &chiph, &imagew, &imageh, &pixelw, &pixelh, &imagebit);
ret = SetQHYCCDBinMode(camhandle, 1, 1);
ret = SetQHYCCDResolution(camhandle, 0, 0, imagew, imageh);
ret = SetQHYCCDParam(camhandle, CONTROL_SPEED, 0);
ret = SetQHYCCDParam(camhandle, CONTROL_USBTRAFFIC, 30);
ret = SetQHYCCDParam(camhandle, CONTROL_EXPOSURE, 20*1000);
ret = BeginQHYCCDLiveFrame(camhandle);
while(1)//you can change the conditionof while
{
    ret = QHYCCD_ERROR;
    while(ret != QHYCCD_SUCCESS)
    {
        ret = GetQHYCCDLiveFrame(camhandle, &imagew, &imageh, &channels, &bits, ImgData);
    }
}
ret = StopQHYCCDLive(camhandle);
ret = CloseQHYCCD(camhandle);
ret = ReleaseQHYCCDRsource();

Best Regards,
QinXiaoXu

ega

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #2 on: December 17, 2020, 04:50:12 AM »
Thank you for your answer!
Unfortunately it didn't work:

first, the following two functions return non-zero status:

SetQHYCCDDebayerOnOff() returned 65535
SetQHYCCDParam(CONTROL_SPEED, 0) returned -1

in the log it says:

Code: [Select]
2020-12-17 10:37:08:156|QHYCCD|QHYCCD.CPP|SetQHYCCDDebayerOnOff|   SetQHYCCDDebayerOnOff   START
2020-12-17 10:37:08:156|QHYCCD|QHYBASE.CPP|SetDebayerOnOff|SetDebayerOnOff 0
...
2020-12-17 10:37:08:189|QHYCCD|QHYCCD.CPP|SetQHYCCDResolution|END   ret = 0
2020-12-17 10:37:08:189|QHYCCD|QHY600M.CPP|IsChipHasFunction|controlID 9
2020-12-17 10:37:08:189|QHYCCD|QHY600M.CPP|IsChipHasFunction|controlID 12
2020-12-17 10:37:08:189|QHYCCD|QHY600BASE.CPP|SetChipUSBTraffic|SetChipUSBTraffic 30
2020-12-17 10:37:08:189|QHYCCD|QHYCAM.CPP|vendTXD|req:0xd1
2020-12-17 10:37:08:220|QHYCCD|QHYBASE.H|SetRemainingExposeTime
2020-12-17 10:37:08:221|QHYCCD|QHYCAM.CPP|vendTXD|req:0xd1
2020-12-17 10:37:08:252|QHYCCD|QHYCCD.CPP|BeginQHYCCDLive|index=1

and then, the program hangs in the loop, never receiving a valid frame (just like before):

Code: [Select]
2020-12-17 10:37:08:253|QHYCCD|CMOSDLL.CPP|BeginAsyQCamLive| START
2020-12-17 10:37:08:253|QHYCCD|QHYCCD.CPP|QHYCCDSeriesMatch|current pid is 0xc601
2020-12-17 10:37:08:284|QHYCCD|QHYCCD.CPP|QHY5IIISeriesMatch|QHY5IIISeriesMatch|mainseries = 4061
2020-12-17 10:37:08:284|QHYCCD|QHYCCD.CPP|QHY5IIISeriesMatch|QHY5IIISeriesMatch|color = 0
2020-12-17 10:37:08:284|QHYCCD|LIBUSBIO.CPP|alloc_transfers|libusb_submit_transfer
2020-12-17 10:37:08:284|QHYCCD|LIBUSBIO.CPP|alloc_transfers|init libusb_submit_transfer failed!!! -1 0
2020-12-17 10:37:08:284|QHYCCD|QHYCCD.CPP|BeginQHYCCDLive|return value=0
2020-12-17 10:37:08:284|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |111111111111111111111111111111111
2020-12-17 10:37:08:285|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |222222222222222222222222222222222222
2020-12-17 10:37:08:285|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |333333333333333333333333333333333333
2020-12-17 10:37:08:285|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |4444444444444444444444444444444444444
2020-12-17 10:37:08:309|QHYCCD | QHYCCD.CPP | GetQHYCCDLiveFrame |5555555555555555555555555555555555

etc. If it helps, the id of the camera I'm using for these tests is

QHY600M-e2d54444b54c72717

I am also attaching the C++ source code that I'm using to make the API calls, just in case there's something I'm doing wrong.

If you need any more information please let me know.
Thanks again for your help!

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #3 on: March 09, 2021, 02:20:20 AM »
I confirm this. With sdk_linux64_21.02.01 even the provided LiveFrameSample.cpp hangs after "BeginQHYCCDLive success!". What the hell is going on here?

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #4 on: March 09, 2021, 02:34:29 AM »
Code: [Select]
sdk_linux64_21.02.01/usr/local/testapp/LiveFrameMode$ ./LiveFrameSample &> log

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #5 on: March 11, 2021, 06:53:55 PM »
Hi,
    I checked QHY600M capture live and single frame with 2021.02.01 version SDK on x86_64 ubuntu linux,it can work well.Did you test camera on Windows to make sure camera is OK?And maybe we can do a remote control next week,if so which time is suitable?
Best Regards,
QinXiaoXu

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #6 on: March 14, 2021, 06:26:34 AM »
QinXiaoXu, thanks for your answer at last.

No we have not tested our cameras under windows. We assume that they are sane because we use them in production, taking image in single frame mode. That itself is not a guarantee that live mode is completely ok, though.
On different computers, ubuntu 20 vs ubuntu 18, we get different modes of failure, which is also suspect, and all together the stability is too low for any use. My guess, but it is a complete shot in the dark, is that libusb (different versions of) is also involved, and that your SDK is not capable of recovering gracefully from communication failures. On top of that, your function GetQHYCCDLiveFrame() is only capable of reporting 0 or -1, without differentiating what is going on (like: exposure not yet completed, different types of USB errors), which makes more difficult for our application to cope with them.

I'm not sure about ways of giving you remote control, but yes, we'd definitely appreciate your feedback. Please let us know when that can be arranged.

Enrico
« Last Edit: March 14, 2021, 09:41:14 AM by Enrico Segre »

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #7 on: March 14, 2021, 09:54:00 AM »
Here is a log for you, on a machine where the cameras work normally (so to say, save application crashes on a number of situations already mentioned in other threads) in single frame mode, and where LiveFrameSample seems to work.

I can't make much out of this log, maybe you can. Suffices to say that, in this, a live sequence was attempted and aborted twice (because GetQHYCCDLiveFrame() kept reporting -1), and that finally the application hung and had to be killed.

Enrico

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #8 on: March 14, 2021, 09:32:03 PM »
Hi,
    We can do remote control with Teamviewer.About time,my work time is 9:am ~ 17:30 pm,Mon to Fri,I'm in Beijing,which time is suitable for you?
    And about libusb version and stability issue,we also noticed the problem,libusb version indeed generate influence,we are plan for testing it.
Best Regards,
QinXiaoXu

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #9 on: March 15, 2021, 08:26:06 AM »
email sent through forum interface

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #10 on: March 15, 2021, 08:39:46 PM »
    Well,I didn't receive your email,maybe you can send email to me directly,my email is qxx@qhyccd.com.And now my time is 9:39 am.
Best Regards,
QinXiaoXu

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #11 on: March 16, 2021, 01:44:19 AM »
another thing in this forum which is broken.... Sending a direct email then

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #12 on: March 22, 2021, 11:33:50 AM »
QinXiaoXu, this is the current status, after a number of tests.
  • Last Thursday we communicated, you logged on one of our computers, made some modifications to the LiveFrameMode demo, so that it worked there. I attach the resulting code to this message (I have corrected your computation of fps which was wrong). You did not provide explanations about why certain functions need to be called in certain order or what some parameters do. Already the fact that the supplied demo doesn't work as provided does not make a great impression on us.
  • I took the trouble of compiling and running this code multiple times on five different computers, with either Ubuntu 18LTS or 20LTS as OS. At best, this code runs and takes frames only once, hanging at subsequent runs. I have alternatively used about any of our current seven QHY600. The procedure I adopted is explained in detail in the attached document.
  • In addition to that, I specifically timed the calls to relevant functions in the SDK for single frame exposure. As remarked in other threads, the image transfer times seem consistently one order of magnitude larger than expected. Also this is detailed in the document.
In light of all this, it would seem that the QHY600s are not really capable of providing live feed in Linux, and that they are not up to the frame transfer rates advertised. We therefore doubt if they are really fit for our purposes.
Can you please shed some light?
« Last Edit: March 22, 2021, 11:55:41 AM by Enrico Segre »

Re: GetQHYCCDLiveFrame() always returns -1 with QHY600M
« Reply #13 on: March 22, 2021, 08:30:32 PM »
    OK,I will tested it,please wait for some time.
Best Regards,
QinXiaoXu