bool Camera_INDIClass::Capture(int duration, usImage& img, int options, const wxRect& subframeArg) { if (Connected) { bool takeSubframe = UseSubframes; wxRect subframe(subframeArg); // we can set the exposure time directly in the camera if (expose_prop) { if (Binning != m_curBinning) { FullSize = wxSize(m_maxSize.x / Binning, m_maxSize.y / Binning); binning_x->value = Binning; binning_y->value = Binning; sendNewNumber(binning_prop); m_curBinning = Binning; } if (subframe.width <= 0 || subframe.height <= 0) { takeSubframe = false; } // Program the size if (!takeSubframe) { subframe = wxRect(0, 0, FullSize.GetWidth(), FullSize.GetHeight()); } if (subframe != m_roi) { frame_x->value = subframe.x*Binning; frame_y->value = subframe.y*Binning; frame_width->value = subframe.width*Binning; frame_height->value = subframe.height*Binning; sendNewNumber(frame_prop); m_roi = subframe; } //printf("Exposing for %d(ms)\n", duration); // set the exposure time, this immediately start the exposure expose_prop->np->value = (double)duration/1000; sendNewNumber(expose_prop); modal = true; // will be reset when the image blob is received unsigned long loopwait = duration > 100 ? 10 : 1; CameraWatchdog watchdog(duration, GetTimeoutMs()); while (modal) { wxMilliSleep(loopwait); if (WorkerThread::TerminateRequested()) return true; if (watchdog.Expired()) { DisconnectWithAlert(CAPT_FAIL_TIMEOUT); return true; } } } // for video camera without exposure time setting else if (video_prop) { takeSubframe = false; //printf("Enabling video capture\n"); ISwitch *v_on = IUFindSwitch(video_prop,"ON"); ISwitch *v_off = IUFindSwitch(video_prop,"OFF"); v_on->s = ISS_ON; v_off->s = ISS_OFF; // start capture, every video frame is received as a blob sendNewSwitch(video_prop); // wait the required time wxMilliSleep(duration); // TODO : add the frames received during exposure //printf("Stop video capture\n"); v_on->s = ISS_OFF; v_off->s = ISS_ON; sendNewSwitch(video_prop); } else { return true; } //printf("Exposure end\n"); if (strcmp(cam_bp->format, ".fits") == 0) { //printf("Processing fits file\n"); // for CCD camera if ( ! ReadFITS(img,takeSubframe,subframe) ) { if (options & CAPTURE_SUBTRACT_DARK) { //printf("Subtracting dark\n"); SubtractDark(img); } if (options & CAPTURE_RECON) { if (PixSizeX != PixSizeY) SquarePixels(img, PixSizeX, PixSizeY); } return false; } else { return true; } } else if (strcmp(cam_bp->format, ".stream") == 0) { //printf("Processing stream file\n"); // for video camera return ReadStream(img); } else { pFrame->Alert(_("Unknown image format: ") + wxString::FromAscii(cam_bp->format)); return true; } } else { // in case the camera is not connected return true; } // we must never go here return true; }
bool Camera_ASCOMLateClass::Capture(int duration, usImage& img, int options, const wxRect& subframeArg) { bool retval = false; bool takeSubframe = UseSubframes; wxRect subframe(subframeArg); if (subframe.width <= 0 || subframe.height <= 0) { takeSubframe = false; } bool binning_changed = false; if (Binning != m_curBin) { FullSize = wxSize(m_maxSize.x / Binning, m_maxSize.y / Binning); binning_changed = true; } // Program the size if (!takeSubframe) { subframe = wxRect(0, 0, FullSize.GetWidth(), FullSize.GetHeight()); } if (img.Init(FullSize)) { pFrame->Alert(_("Cannot allocate memory to download image from camera")); return true; } GITObjRef cam(m_gitEntry); EXCEPINFO excep; if (binning_changed) { if (ASCOM_SetBin(cam.IDisp(), Binning, &excep)) { pFrame->Alert(_("The ASCOM camera failed to set binning. See the debug log for more information.")); return true; } m_curBin = Binning; } if (subframe != m_roi) { ASCOM_SetROI(cam.IDisp(), subframe, &excep); m_roi = subframe; } bool takeDark = HasShutter && ShutterClosed; // Start the exposure if (ASCOM_StartExposure(cam.IDisp(), (double)duration / 1000.0, takeDark, &excep)) { Debug.AddLine(ExcepMsg("ASCOM_StartExposure failed", excep)); pFrame->Alert(ExcepMsg(_("ASCOM error -- Cannot start exposure with given parameters"), excep)); return true; } CameraWatchdog watchdog(duration, GetTimeoutMs()); if (duration > 100) { // wait until near end of exposure if (WorkerThread::MilliSleep(duration - 100, WorkerThread::INT_ANY) && (WorkerThread::TerminateRequested() || AbortExposure())) { return true; } } while (true) // wait for image to finish and d/l { wxMilliSleep(20); bool ready; EXCEPINFO excep; if (ASCOM_ImageReady(cam.IDisp(), &ready, &excep)) { Debug.AddLine(ExcepMsg("ASCOM_ImageReady failed", excep)); pFrame->Alert(ExcepMsg(_("Exception thrown polling camera"), excep)); return true; } if (ready) break; if (WorkerThread::InterruptRequested() && (WorkerThread::TerminateRequested() || AbortExposure())) { return true; } if (watchdog.Expired()) { DisconnectWithAlert(CAPT_FAIL_TIMEOUT); return true; } } // Get the image if (ASCOM_Image(cam.IDisp(), img, takeSubframe, subframe, &excep)) { Debug.AddLine(ExcepMsg(_T("ASCOM_Image failed"), excep)); pFrame->Alert(ExcepMsg(_("Error reading image"), excep)); return true; } if (options & CAPTURE_SUBTRACT_DARK) SubtractDark(img); if (Color && Binning == 1 && (options & CAPTURE_RECON)) QuickLRecon(img); return false; }