CanonCamera::CanonCamera(void)
{
	liveView = false;
	camID = numOfCameras;
	numOfCameras++;

	windowName = "Camera ";
	windowName += '1' + camID;
	windowName += " Window";

	EdsCameraListRef cameraList = NULL;
	
	EdsGetCameraList(&cameraList);

	EdsUInt32	 camCount = 0;
	EdsGetChildCount(cameraList, &camCount);


	if(camCount==0)
	{
		std::cout<<"No Camera Found"<<". Press Any Key to Exit.";
		getch();
		exit(-1);
	}
	else
	{
		std::cout<<camCount<<" Camera(s) found!\n";
	} 

	EdsError err = EDS_ERR_OK;

	err = EdsGetChildAtIndex(cameraList , camID , &camera);

	//Release camera list
	if(cameraList != NULL)
	{
		EdsRelease(cameraList);
	}

	detectedCams=camCount;

	//open sesion
	err=EdsOpenSession(camera);

	if(err!=EDS_ERR_OK)
	{
		std::cout<<"Problem with Camera connection"<<". Press Any Key to Exit";
		getch();
		exit(-1);
	}
	

}
    EdsError Camera::requestOpenSession(const Settings &settings) {
        if (mHasOpenSession) {
            return EDS_ERR_SESSION_ALREADY_OPEN;
        }
        
        EdsError error = EdsOpenSession(mCamera);
        if (error != EDS_ERR_OK) {
            std::cerr << "ERROR - failed to open camera session" << std::endl;
            return error;
        }
        mHasOpenSession = true;
        
        mShouldKeepAlive = settings.getShouldKeepAlive();
        EdsUInt32 saveTo = settings.getPictureSaveLocation();
        error = EdsSetPropertyData(mCamera, kEdsPropID_SaveTo, 0, sizeof(saveTo) , &saveTo);
        if (error != EDS_ERR_OK) {
            std::cerr << "ERROR - failed to set save destination host/device" << std::endl;
            return error;
        }
        

		//UI lock
		if (error == EDS_ERR_OK)
		{
			error = EdsSendStatusCommand(mCamera, kEdsCameraStatusCommand_UILock, 0);
		}

		if (error == EDS_ERR_OK)
		{
			mIsLocked = true;
		}


        if (saveTo == kEdsSaveTo_Host) {
            // ??? - requires UI lock?
            EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
            error = EdsSetCapacity(mCamera, capacity);
            if (error != EDS_ERR_OK) {
                std::cerr << "ERROR - failed to set capacity of host" << std::endl;
                return error;
            }
        }
        
		//It releases it when locked
		if (mIsLocked)
		{
			EdsSendStatusCommand(mCamera, kEdsCameraStatusCommand_UIUnLock, 0);
		}

        return EDS_ERR_OK;
    }
    //---------------------------------------------------------------------
    bool CanonCameraWrapper::openSession(){
        EdsError err = EDS_ERR_OK;

        err = EdsOpenSession( theCamera );
        if(err == EDS_ERR_OK){
            printf("We are opening session!\n");
            state = CAMERA_OPEN;
            return true;
        }
        else{
            printf("We failed at opening session!\n");
        }
        return false;
    }
bool CanonTaskOpenSession::execute() {

  if(canon->isLegacy()) {
    RX_ERROR("We did not implement and tested the canon video capture implementation for legacy devices (<30D)");
    ::exit(EXIT_FAILURE);
  }

  if(canon->getState() != Canon::STATE_NONE) {
    RX_ERROR("The device hasn't been opened so we cannot open the session either");
    return false;
  }

  EdsError err = EdsOpenSession(canon->getCameraRef());
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    return false;
  }  
  
  EdsUInt32 save_to = kEdsSaveTo_Host;
  err = EdsSetPropertyData(canon->getCameraRef(), kEdsPropID_SaveTo, 0, sizeof(save_to), &save_to);
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    return false;
  }
  
  if(!canon->lockUI()) {
    return false;
  }

  EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
  err = EdsSetCapacity(canon->getCameraRef(), capacity);
  if(err != EDS_ERR_OK) {
    CANON_ERROR(err);
    return false;
  }

  if(!canon->unlockUI()) {
    return false;
  }

  canon->setStateOpened();

  return true;
}
Exemple #5
0
EdsCameraRef openCamera() {
	EdsCameraListRef cameraList = NULL;
	// Get camera list
	EdsError err = EdsGetCameraList(&cameraList);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	EdsUInt32 numCameras = 0;
	// Get number of cameras
	err = EdsGetChildCount(cameraList, &numCameras);
	if (err == EDS_ERR_OK) {
		handleErrorCode(err);
	}

	if (numCameras > 1) {
		mexWarnMsgTxt("Warning: more than one available cameras found. Multiple cameras are not well supported.");
	} else if (numCameras <= 0) {
		mexErrMsgIdAndTxt(ERROR_ID, "No available camera found.");
		return NULL;
	}

	EdsCameraRef handle;
	// Get first camera retrieved
	err = EdsGetChildAtIndex(cameraList , 0 , &handle);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Release camera list
	if (cameraList != NULL) {
		EdsRelease(cameraList);
		cameraList = NULL;
	}

	// Set object event handler
	err = EdsSetObjectEventHandler(handle, kEdsObjectEvent_All, handleObjectEvent, NULL);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Set property event handler
	err = EdsSetPropertyEventHandler(handle, kEdsPropertyEvent_All, handlePropertyEvent, NULL);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Set camera state event handler
	err = EdsSetCameraStateEventHandler(handle, kEdsStateEvent_All, handleStateEvent, NULL);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	// Open session with camera
	err = EdsOpenSession(handle);
	if (err != EDS_ERR_OK) {
		handleErrorCode(err);
	}

	return handle;
}
int CanonEDCamera::Initialize()
{
   EdsError err = EDS_ERR_OK; 
    
   // Initialize SDK 
   err = EdsInitializeSDK(); 
   if(err == EDS_ERR_OK) 
   { 
     isSDKLoaded_ = true; 
   } 
    
   // Get first camera 
   if(err == EDS_ERR_OK) 
   { 
      err = getFirstCamera (&camera_); 
   } 

   if (err == EDS_ERR_DEVICE_NOT_FOUND)
      return ERR_NO_CAMERA;
    

   // event handlers are static functions that need a reference to this camera object to function
   // provide that static ref here.  This approach will fail with multiple cameras.  In that case, 
   // consider making a map with cameras and references to our CanonEDCamera objects
   g_Self = this;

   // Set event handler 
   if(err == EDS_ERR_OK) 
   { 
      err = EdsSetObjectEventHandler(camera_,  kEdsObjectEvent_All, &CanonEDCamera::handleObjectEvent,  NULL); 
   } 
    
   // Set event handler 
   if(err == EDS_ERR_OK) 
   { 
      err = EdsSetPropertyEventHandler(camera_,  kEdsPropertyEvent_All, &CanonEDCamera::handlePropertyEvent,  NULL); 
   } 
    
   // Set event handler 
   if(err == EDS_ERR_OK) 
   { 
      err = EdsSetCameraStateEventHandler(camera_,  kEdsStateEvent_All, &CanonEDCamera::handleStateEvent,  NULL); 
   } 

   if(err == EDS_ERR_OK) 
   { 
      err = EdsOpenSession(camera_); 
   } 
     
   // Camera name
   if (err == EDS_ERR_OK)
   {
      EdsDeviceInfo  deviceInfo;
      err = EdsGetDeviceInfo(camera_, &deviceInfo);
      if (err == EDS_ERR_OK)
      {
         std::ostringstream os;
         os << "Canon SLR device subtype: " << deviceInfo.deviceSubType;
         LogMessage(os.str().c_str());
         if (deviceInfo.deviceSubType == 0)
            isLegacy_ = true;
         cameraModel_ = deviceInfo.szDeviceDescription;
         int nRet = CreateProperty("Model", cameraModel_.c_str(), MM::String, true);
         if (nRet != DEVICE_OK)
            return nRet;
      }

      // Set and Get various camera properties

      // lock the UI before setting properties - only needed on legacy cameras
      if (isLegacy_)
         EdsSendStatusCommand (camera_,  kEdsCameraStatusCommand_UILock, 0);
      EdsSaveTo toPC = kEdsSaveTo_Host;
      err = EdsSetPropertyData(camera_,  kEdsPropID_SaveTo, 0 , sizeof(EdsSaveTo),  &toPC);
      if (isLegacy_)
         EdsSendStatusCommand (camera_, kEdsCameraStatusCommand_UIUnLock, 0);
   }

   if (err == EDS_ERR_OK)
   {
      CPropertyAction* pAct = new CPropertyAction(this, &CanonEDCamera::OnBinning);
      int nRet = CreateProperty(MM::g_Keyword_Binning, "1", MM::Integer, false, pAct);
      if (nRet != DEVICE_OK)
         return nRet;
   }

   if (err == EDS_ERR_OK)
   {
      return DEVICE_OK;
   }

   std::ostringstream os;
   os << "Error during initialization: " << std::hex << err;
   LogMessage(os.str().c_str());

   return err;
}
boolean connectToFirstCamera(){
	
	EdsError err = EDS_ERR_OK;

	// Initialize SDK
	err = EdsInitializeSDK();
	if ( err == EDS_ERR_OK )
		isSDKLoaded = true;


/*	// Get first camera
	if(err == EDS_ERR_OK)
	{
		err = getFirstCamera();
	}*/

	EdsCameraListRef cameraList = NULL;
	EdsUInt32 count = 0;

	// Get camera list
	err = EdsGetCameraList(&cameraList);

	// Get number of cameras
	if(err == EDS_ERR_OK)
	{
		err = EdsGetChildCount(cameraList, &count);
		if(count == 0)
		{
			err = EDS_ERR_DEVICE_NOT_FOUND;
		}
	}

	// Get first camera retrieved
	if(err == EDS_ERR_OK)
	{
		err = EdsGetChildAtIndex(cameraList , 0 , &camera);
	}

	// Release camera list
	if(cameraList != NULL)
	{
		EdsRelease(cameraList);
		cameraList = NULL;
	}

	//Open Session
	if(err == EDS_ERR_OK)
	{
		err = EdsOpenSession(camera);
	}

	//Set save to host
	if (err == EDS_ERR_OK ) {
		EdsUInt32 wkSaveTo = kEdsSaveTo_Host ;
		do {
			err = EdsSetPropertyData ( camera, kEdsPropID_SaveTo, 
				0, 4, (void*)&wkSaveTo ) ;
			if (err != EDS_ERR_OK) {
				std::cout << "warning: camera busy, waiting..." << std::endl;
				std::flush(std::cout);
				Sleep(100);
			}
		} while (err != EDS_ERR_OK);
	}

	// Set host capacity
	EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
	err = EdsSetCapacity ( camera, capacity );

	return err == EDS_ERR_OK;
}