public uint onCameraAdded(IntPtr inContext) //TODO add Exceptionhandling { IntPtr tmpPtr = IntPtr.Zero; int tmpCount = 0; EDSDKLib.EDSDK.EdsDeviceInfo deviceInfo; char[] tmpName = new char[32]; uint error = 0; /** * First getting cameralist pointer * */ error = EDSDKLib.EDSDK.EdsGetCameraList(out tmpPtr); if (error != EDSDK.EDS_ERR_OK) { //TODO Fehler behandeln } /* * Getting count of cameralist childs to choose the last adding on the list * */ error = EDSDKLib.EDSDK.EdsGetChildCount(tmpPtr, out tmpCount); if (error != EDSDK.EDS_ERR_OK) { //TODO Fehler behandeln } /* * Get the camera pointer of the last object on the cameralist * */ error = EDSDKLib.EDSDK.EdsGetChildAtIndex(tmpPtr, tmpCount - 1, out tmpPtr); if (error != EDSDK.EDS_ERR_OK) { //TODO Fehler behandeln } /* * Getting device info of given camera pointer * */ error = EDSDKLib.EDSDK.EdsGetDeviceInfo(tmpPtr, out deviceInfo); if (error != EDSDK.EDS_ERR_OK) { //TODO Fehler behandeln } string cameraName; EDSDK.EdsOpenSession(tmpPtr); EDSDK.EdsGetPropertyData(tmpPtr, EDSDK.PropID_ProductName, 0, out cameraName); EDSDK.EdsCloseSession(tmpPtr); this.CameraList.Add(new Camera(tmpPtr, cameraName)); error = EDSDK.EdsSetPropertyEventHandler(tmpPtr, EDSDK.PropertyEvent_All, cameraPropertyEventHandler, tmpPtr); error = EDSDK.EdsSetCameraStateEventHandler(tmpPtr, EDSDK.StateEvent_All, this.cameraStateEventHandler, tmpPtr); return(0x0); }
private void btn_connect_click(object sender, RoutedEventArgs e) { IntPtr cameraList = new IntPtr(0); camera = new IntPtr(0); Int32 cameraCount = 0; EDSDK sdk = new EDSDK(); EDSDK.EdsInitializeSDK(); EdsError = EDSDK.EdsGetCameraList(out cameraList); //EdsError = EdsGetCameraList(out cameraList); EDSDK.EdsGetChildCount(cameraList, out cameraCount); label.Content = "Connected camera count : " + cameraCount.ToString(); if (cameraCount != 0) { EdsError = EDSDK.EdsGetChildAtIndex(cameraList, 0, out camera); //MessageBox.Show("EdsGetChildAtIndex err code : " + EdsError.ToString()); } EdsError = EDSDK.EdsOpenSession(camera); if (EdsError == EDSDK.EDS_ERR_OK) { label.Content = "Camera connected"; EDSDK.EdsSetPropertyEventHandler(camera, EDSDK.PropertyEvent_All, propertyEventHandler, IntPtr.Zero); SDKObjectEvnet += new EDSDK.EdsObjectEventHandler(objectEventHandler); //SDKObjectEvent += new SDKObjectEventHandler(objectEventHandler); EdsError = EDSDK.EdsSetObjectEventHandler(camera, EDSDK.ObjectEvent_All, SDKObjectEvnet, IntPtr.Zero); if (EdsError == EDSDK.EDS_ERR_OK) { label.Content = "NO ERROR"; } else { label.Content = "ERROR : " + EdsError; } EDSDK.EdsSetCameraStateEventHandler(camera, EDSDK.StateEvent_All, cameraStateEventHandler, IntPtr.Zero); } else { label.Content = "Camera not connected"; } }
public Camera(IntPtr aPointer, ICameraNotifications aCameraNotifications) { _onCameraEvent = DownloadImage; _onCameraStateChanged = CameraStateChanged; _onCameraPropertyChanged = CameraPropertyChanged; _pointer = aPointer; _cameraNotifications = aCameraNotifications; _eventHandlers = new List <CameraEvent>(); SDKHelper.CheckError(EDSDK.EdsOpenSession(_pointer)); SDKHelper.CheckError(EDSDK.EdsSetObjectEventHandler(_pointer, EDSDK.ObjectEvent_All, _onCameraEvent, IntPtr.Zero)); SDKHelper.CheckError(EDSDK.EdsSetCameraStateEventHandler(_pointer, EDSDK.StateEvent_All, _onCameraStateChanged, IntPtr.Zero)); SDKHelper.CheckError(EDSDK.EdsSetPropertyEventHandler(_pointer, EDSDK.PropertyEvent_All, _onCameraPropertyChanged, IntPtr.Zero)); }
private void scanToCameras() { IntPtr tmpptr; IntPtr tmpCameraPtr; int tmpCount = 0; EDSDK.EdsGetCameraList(out tmpptr); EDSDK.EdsGetChildCount(tmpptr, out tmpCount); for (int i = 0; i < tmpCount; i++) { EDSDK.EdsGetChildAtIndex(tmpptr, i, out tmpCameraPtr); this.CameraList.Add(new Camera(tmpCameraPtr, "")); EDSDK.EdsSetPropertyEventHandler(tmpCameraPtr, EDSDK.PropertyEvent_All, cameraPropertyEventHandler, tmpCameraPtr); EDSDK.EdsSetCameraStateEventHandler(tmpCameraPtr, EDSDK.StateEvent_All, this.cameraStateEventHandler, tmpCameraPtr); } }
public bool Init() { IntPtr camList; int camCount = 0; uint err = 0; //SETUP DELEGATES FOR LATER USE objEventHandlerDelegate = new EDSDK.EdsObjectEventHandler(objEventHandler); propEventHandlerDelegate = new EDSDK.EdsPropertyEventHandler(propEventHandler); stateEventHandlerDelegate = new EDSDK.EdsStateEventHandler(stateEventHandler); //INIT THE SDK THIS MUST BE CALLED BEFORE ANYTHING ELSE CAN BE DONE err = EDSDK.EdsInitializeSDK(); if (err != EDSDK.EDS_ERR_OK) { if (errorEvent != null) { errorEvent("Failed to init SDK"); } return(false); } //GET ALL ATTACHED CAMERAS err = EDSDK.EdsGetCameraList(out camList); if (err != EDSDK.EDS_ERR_OK) { if (errorEvent != null) { errorEvent("Failed to find a camera"); } return(false); } //GET THE NUMBER OF ATTACHED CAMERAS err = EDSDK.EdsGetChildCount(camList, out camCount); if (err != EDSDK.EDS_ERR_OK) { if (errorEvent != null) { errorEvent("Failed to get camera count"); } return(false); } //IF THERE ARE 0 CAMERAS DETECETED THEN THROW AN ERROR if (camCount == 0) { if (errorEvent != null) { errorEvent("No cameras found"); } return(false); } //WE ONLY CARE ABOUT THE FIRST CAMERA WE FIND err = EDSDK.EdsGetChildAtIndex(camList, 0, out camObj); if (err != EDSDK.EDS_ERR_OK) { if (errorEvent != null) { errorEvent("Failed to retrieve camera object"); } return(false); } //SET THE EVENT HANDLERS FOR LATER USE err = EDSDK.EdsSetObjectEventHandler(camObj, EDSDK.ObjectEvent_All, objEventHandlerDelegate, IntPtr.Zero); if (err != EDSDK.EDS_ERR_OK) { if (errorEvent != null) { errorEvent("Failed to set event handler"); } return(false); } err = EDSDK.EdsSetPropertyEventHandler(camObj, EDSDK.PropertyEvent_All, propEventHandlerDelegate, IntPtr.Zero); if (err != EDSDK.EDS_ERR_OK) { if (errorEvent != null) { errorEvent("Failed to set event handler"); } return(false); } err = EDSDK.EdsSetCameraStateEventHandler(camObj, EDSDK.StateEvent_All, stateEventHandlerDelegate, IntPtr.Zero); if (err != EDSDK.EDS_ERR_OK) { if (errorEvent != null) { errorEvent("Failed to set event handler"); } return(false); } //OPEN THE SESSION TO THE CAMERA err = EDSDK.EdsOpenSession(camObj); //LET THE CALLING FUNCTION KNOW THIS ALL WORKED return(true); }