Exemple #1
0
 void DeviceManager_PhotoCaptured(object sender, PhotoCapturedEventArgs eventArgs)
 {
     //if (eventArgs.FileName.ToUpper().Contains(eventArgs.CameraDevice.CompressionSetting.Value))
     //{
     PhotoCaptured(eventArgs);
     //}
 }
Exemple #2
0
        private async static Task PhotoCaptured(PhotoCapturedEventArgs e)
        {
            await Task.Run(() =>
            {
                try
                {
                    string tempFile = Path.GetTempFileName();

                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }

                    e.CameraDevice.TransferFile(e.Handle, tempFile);
                    File.Copy(tempFile, Filename, true);

                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }
                }
                finally
                {
                    e.CameraDevice.IsBusy = false;
                }
            });
        }
Exemple #3
0
        private void PhotoCaptured(PhotoCapturedEventArgs eventArgs)
        {
            _tl.LogMessage("Photo captured filename", eventArgs.FileName);

            string fileName = GetFileNameForDownload(eventArgs);

            if (!Directory.Exists(Path.GetDirectoryName(fileName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(fileName));
            }

            eventArgs.CameraDevice.TransferFile(eventArgs.Handle, fileName);

            SensorTemperature = GetSensorTemperature(fileName);

            string newFilePath = RenameFile(fileName, _duration, _startTime);

            ImageReady?.Invoke(this, new ImageReadyEventArgs(newFilePath));

            if ((File.Exists(newFilePath)) && (SaveFile == false))
            {
                File.Delete(newFilePath);
            }

            eventArgs.CameraDevice.IsBusy = false;
        }
        private void DeviceManager_PhotoCaptured(object sender, PhotoCapturedEventArgs eventArgs)
        {
            try
            {
                string tempFile = Path.Combine(Settings.Instance.TempFolder, Path.GetRandomFileName() + Path.GetExtension(eventArgs.FileName));

                Utils.CreateFolder(tempFile);

                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }

                eventArgs.CameraDevice.TransferFile(eventArgs.Handle, tempFile);
                FileItem item = new FileItem()
                {
                    FileName = tempFile, Thumb = Utils.LoadImage(tempFile, 200, 0)
                };
                FileItems.Add(item);
                FileItem       = item;
                item.ThumbFile = Path.GetTempFileName();
                Utils.Save2Jpg(Utils.LoadImage(tempFile, 800, 0), item.ThumbFile);
                OnMessage(new MessageEventArgs(Messages.PhotoDownloaded, FileItem));
            }
            catch (Exception ex)
            {
                Log.Error("Error transfer file", ex);
            }
        }
        public override void CapturePhoto()
        {
            var    json = Initialize(GetExecute(CreateJson("camera.takePicture")));
            string id   = json["id"].Value <string>();
            string url  = null;

            do
            {
                var jsonStatus = Initialize(GetStatus(id));
                if (jsonStatus["state"].Value <string>() == "done")
                {
                    url = jsonStatus["results"]["fileUri"].Value <string>();
                }
                else
                {
                    Thread.Sleep(150);
                }
            } while (string.IsNullOrEmpty(url));
            Log.Debug("Url to process " + url);
            PhotoCapturedEventArgs args = new PhotoCapturedEventArgs
            {
                WiaImageItem = null,
                EventArgs    = null,
                CameraDevice = this,
                FileName     = url.Replace('/', '\\'),
                Handle       = url
            };

            OnPhotoCapture(this, args);
        }
        static void DeviceManager_PhotoCaptured(object sender, PhotoCapturedEventArgs eventArgs)
        {
            Thread thread = new Thread(PhotoCaptured);

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start(eventArgs);
        }
 public void OnPhotoCaptured(object sender, PhotoCapturedEventArgs eventArgs)
 {
     if (PhotoCaptured != null)
     {
         PhotoCaptured(sender, eventArgs);
     }
 }
 private void cameraDevice_PhotoCaptured(object sender, PhotoCapturedEventArgs eventArgs)
 {
     if (PhotoCaptured != null)
     {
         PhotoCaptured(sender, eventArgs);
     }
 }
        void DeviceManager_PhotoCaptured(object sender, PhotoCapturedEventArgs eventArgs)
        {
            // to prevent UI freeze start the transfer process in a new thread
            Thread thread = new Thread(PhotoCaptured);

            thread.Start(eventArgs);
        }
Exemple #10
0
        async private void CaptureHandler1(
            LowLagPhotoSequenceCapture senders, PhotoCapturedEventArgs args)
        {
            CapturedFrame frame = args.Frame;

            // var is bool
            var result = await frame.FlushAsync();
        }
Exemple #11
0
        private void CaptureHandler2(
            LowLagPhotoSequenceCapture senders, PhotoCapturedEventArgs args)
        {
            CapturedFrame frame = args.Frame;

            // var is IAsyncOperation<TResult>
            var result = frame.FlushAsync();
        }
 private void DeviceManager_PhotoCaptured(object sender, PhotoCapturedEventArgs eventargs)
 {
     _fileStack.Enqueue(eventargs);
     if (!CaptureTransferAfterCapture)
     {
         TransferFiles();
     }
 }
 private void CameraDevice_PhotoCaptured(object sender, PhotoCapturedEventArgs eventArgs)
 {
     if (AutomaticGuiding && PhdType > 0)
     {
         var thread = new Thread(() => PhdGuiding(PhdType));
         thread.Start();
     }
 }
Exemple #14
0
        void Protocol_DataReceiverd(object sender, string data)
        {
            try
            {
                if (data.Contains("msg_id"))
                {
                    dynamic resp = JsonConvert.DeserializeObject(data);
                    switch ((string)resp.msg_id)
                    {
                    case "3":     // allproperties
                        CurrentValues.Clear();
                        foreach (JObject o in resp.param)
                        {
                            var k = o.ToObject <Dictionary <string, string> >();
                            CurrentValues.Add(k.First().Key, k.First().Value);
                        }
                        break;

                    case "7":
                        switch ((string)resp.type)
                        {
                        case "burst_complete":
                        case "photo_taken":
                            string filename             = Path.GetFileName(((string)resp.param).Replace('/', '\\'));
                            PhotoCapturedEventArgs args = new PhotoCapturedEventArgs
                            {
                                WiaImageItem = null,
                                EventArgs    = new PortableDeviceEventArgs(),
                                CameraDevice = this,
                                FileName     = filename,
                                Handle       = filename
                            };
                            OnPhotoCapture(this, args);
                            break;

                        default:
                            SetProperty((string)resp.type, (string)resp.param);
                            break;
                        }
                        break;

                    case "9":
                        SetValues(data);
                        break;
                    }
                    _lastData = data;
                    if (data.Contains("listing"))
                    {
                        _listingEvent.Set();
                    }
                }
            }
            catch (Exception)
            {
            }
            _resetEvent.Set();
        }
 private void DeviceManager_PhotoCaptured(object sender, PhotoCapturedEventArgs eventArgs)
 {
     Dispatcher.Invoke(new Action(delegate
     {
         Activate();
         Focus();
         txt_barcode.Focus();
         txt_barcode.SelectAll();
     }));
 }
        private void PhotoCaptured(PhotoCapturedEventArgs eventArgs)
        {
            if (eventArgs == null)
            {
                throw new ArgumentNullException("eventArgs");
            }

            Debug.Assert(eventArgs.CameraDevice != null, "PhotoCaptured: eventArgs.CameraDevice == null");

            ICameraDevice cameraDev = eventArgs.CameraDevice;

            try
            {
                cameraDev.IsBusy = true;
                CameraProperty property = ServiceProvider.Settings.CameraProperties.Get(cameraDev);
                PhotoSession   session  = (PhotoSession)cameraDev.AttachedPhotoSession ??
                                          ServiceProvider.Settings.DefaultSession;

                if ((property.NoDownload && !eventArgs.CameraDevice.CaptureInSdRam))
                {
                    cameraDev.IsBusy = false;
                    return;
                }

                string   fileName = GetTempFilePathWithExtension(".jpg");
                DateTime testTime = DateTime.Now;
                Debug.WriteLine("Pre transfer: {0}:{1}:{2}:{3}", testTime.Hour, testTime.Minute, testTime.Second, testTime.Millisecond);
                cameraDev.TransferFile(eventArgs.Handle, fileName);
                testTime = DateTime.Now;
                Debug.WriteLine("Post transfer: {0}:{1}:{2}:{3}", testTime.Hour, testTime.Minute, testTime.Second, testTime.Millisecond);

                if (this.DeleteFromDevice)
                {
                    try
                    {
                        AsyncObservableCollection <DeviceObject> devObjs = cameraDev.GetObjects(eventArgs.Handle);
                        if (devObjs.Count == 1)
                        {
                            Debug.WriteLine("delete {0}", devObjs[0].FileName);
                            //cameraDev.DeleteObject(devObjs[0]);
                        }
                    }
                    catch (NotImplementedException) { }
                }
                this.lastImageFile = fileName;
                this.imageCaptured = true;
                cameraDev.IsBusy   = false;
                Debug.WriteLine("Captured image at {0} to {1}{2}", DateTime.Now.ToLongTimeString(), fileName, Environment.NewLine);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("PhotoCaptured exception: {0}", ex);
                eventArgs.CameraDevice.IsBusy = false;
            }
        }
        public override void CapturePhoto()
        {
            IsBusy = true;
            List <string> urls;
            bool          firstRun = true;

            while (true)
            {
                try
                {
                    urls = AsPrimitiveList <string>(firstRun ? Post(CreateJson("actTakePicture")) : Post(CreateJson("awaitTakePicture")));
                    break;
                }
                catch (DeviceException exception)
                {
                    if (exception.ErrorCode == 40403)
                    {
                        firstRun = false;
                    }
                    else
                    {
                        IsBusy = false;
                        Log.Error("Sony capture error ", exception);
                        throw;
                    }
                }
                catch (Exception ex)
                {
                    IsBusy = false;
                    Log.Error("Sony capture error ", ex);
                    throw;
                }
            }

            foreach (var u in urls)
            {
                var url = u;
                if (url.Contains("?"))
                {
                    url = url.Split('?')[0];
                }
                Log.Debug("Url to process " + url);
                PhotoCapturedEventArgs args = new PhotoCapturedEventArgs
                {
                    WiaImageItem = null,
                    EventArgs    = new PortableDeviceEventArgs(),
                    CameraDevice = this,
                    FileName     = url.Replace('/', '\\'),
                    Handle       = url
                };
                OnPhotoCapture(this, args);
            }
        }
        public override void CapturePhoto()
        {
            var url = "http://" + _address + "/snapshot.jpg";
            PhotoCapturedEventArgs args = new PhotoCapturedEventArgs
            {
                WiaImageItem = null,
                EventArgs    = new PortableDeviceEventArgs(),
                CameraDevice = this,
                FileName     = url.Replace('/', '\\'),
                Handle       = url
            };

            OnPhotoCapture(this, args);
        }
Exemple #19
0
 private void DeviceManager_PhotoCaptured(object sender, PhotoCapturedEventArgs eventArgs)
 {
     if (ServiceProvider.Settings.UseParallelTransfer)
     {
         PhotoCaptured(eventArgs);
     }
     else
     {
         lock (_locker)
         {
             PhotoCaptured(eventArgs);
         }
     }
 }
Exemple #20
0
 private void StillImageDevice_DeviceEvent(object sender, PortableDeviceEventArgs e)
 {
     if (e.EventType.EventGuid == PortableDeviceGuids.WPD_EVENT_OBJECT_ADDED)
     {
         var id = e.EventType.DeviceObject.ID;
         PhotoCapturedEventArgs args = new PhotoCapturedEventArgs
         {
             WiaImageItem = null,
             CameraDevice = this,
             FileName     = e.EventType.DeviceObject.Name,
             Handle       = e.EventType.DeviceObject.ID
         };
         OnPhotoCapture(this, args);
     }
 }
Exemple #21
0
        private void DeviceManager_OnEvent(string eventId, string deviceId, string itemId)
        {
            Item      tem               = Device.GetItem(itemId);
            ImageFile imageFile         = (ImageFile)tem.Transfer("{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}");
            PhotoCapturedEventArgs args = new PhotoCapturedEventArgs
            {
                EventArgs    = imageFile,
                CameraDevice = this,
                FileName     = "00000." + imageFile.FileExtension,
                Handle       = new object[] { imageFile, itemId }
            };

            OnPhotoCapture(this, args);
            OnCaptureCompleted(this, new EventArgs());
        }
        private void Ws_OnMessage(object sender, MessageEventArgs e)
        {
            var json = JObject.Parse(e.Data);

            if (json["result"] != null)
            {
                var values = json["result"].ToObject <Dictionary <string, object> >();
                if (values.ContainsKey("serial_number"))
                {
                    SerialNumber = (string)values["serial_number"];
                }
            }
            if ((string)json["method"] == "status_update")
            {
                if (json["params"]["battery_value"] != null)
                {
                    Battery = json["params"]["battery_value"].Value <int>();
                }
                if (json["params"]["capture_available"] != null)
                {
                    IsBusy = json["params"]["capture_available"].Value <bool>();
                }
            }
            if ((string)json["method"] == "upf_infos_update")
            {
                if (json["params"] != null)
                {
                    var values = json["params"]["upf_infos"][0].ToObject <Dictionary <string, object> >();
                    if (values.ContainsKey("upf_status") && (string)values["upf_status"] == "ready")
                    {
                        string url = (string)values["upf_url"];
                        PhotoCapturedEventArgs args = new PhotoCapturedEventArgs
                        {
                            WiaImageItem = null,
                            EventArgs    = null,
                            CameraDevice = this,
                            FileName     = url.Replace('/', '\\'),
                            Handle       = new List <object>()
                            {
                                url, (long)values["upf_size"]
                            }
                        };
                        OnPhotoCapture(this, args);
                    }
                }
            }
        }
        private void DeviceManager_PhotoCaptured(object sender, PhotoCapturedEventArgs eventArgs)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                string tempFile = Path.Combine(Settings.Instance.TempFolder, Path.GetRandomFileName() + Path.GetExtension(eventArgs.FileName));

                Utils.CreateFolder(tempFile);

                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }

                eventArgs.CameraDevice.TransferFile(eventArgs.Handle, tempFile);
                FileItem item = new FileItem()
                {
                    TempFile  = tempFile,
                    Thumb     = Utils.LoadImage(tempFile, 200),
                    Variables = Context.WorkFlow.Variables.GetItemVariables()
                };
                FileItems.Add(item);
                FileItem         = item;
                Context.FileItem = FileItem;

                Utils.WaitForFile(tempFile);
                using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(tempFile)))
                {
                    Context.FileItem    = item;
                    Context.ImageStream = stream;
                    OnMessage(new MessageEventArgs(Messages.PhotoDownloaded, FileItem)
                    {
                        Context = Context
                    });
                    OnMessage(new MessageEventArgs(Messages.FileTransferred, Context)
                    {
                        Context = Context
                    });
                }
            }
            catch (Exception ex)
            {
                Log.Error("Error transfer file", ex);
            }
        }
        /// <summary>
        /// Method to save captured photos to file
        /// </summary>
        /// <param name="o"></param>
        private void PhotoCaptured(object o)
        {
            PhotoCapturedEventArgs eventArgs = o as PhotoCapturedEventArgs;

            if (eventArgs == null)
            {
                return;
            }

            try
            {
                string fileName = Path.Combine(FolderForPhotos, Path.GetFileName(eventArgs.FileName));
                // If file exist try to generate a new filename to prevent file lost.
                // This is useful when camera is set to record in ram and the all file names are same.
                if (File.Exists(fileName))
                {
                    fileName =
                        StaticHelper.GetUniqueFilename(
                            Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_", 0,
                            Path.GetExtension(fileName));
                }

                // check the folder of filename, if not found create it
                if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                }
                eventArgs.CameraDevice.TransferFile(eventArgs.Handle, fileName);
                // the IsBusy may used internally, if file transfer is done should set to false
                eventArgs.CameraDevice.IsBusy = false;
                // Only display non RAW images
                if (Path.GetExtension(fileName) == ".NEF")
                {
                }
                else
                {
                    pictureBox1.ImageLocation = fileName;
                }
            }
            catch (Exception exception)
            {
                eventArgs.CameraDevice.IsBusy = false;
                MessageBox.Show("Error download photo from camera :\n" + exception.Message);
            }
        }
        /// <summary>
        /// Handles the PhotoCaptured event of the CameraDevice control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PhotoCapturedEventArgs"/> instance containing the event data.</param>
        void CameraDevice_PhotoCaptured(object sender, PhotoCapturedEventArgs e)
        {
            try
            {
                e.CameraDevice.IsBusy = true;
                e.Transfer(e.FileName);
                ImageView.Source = new BitmapImage(new Uri(e.FileName));
            }
            finally
            {
                e.CameraDevice.IsBusy = false;
            }

            if (Captured != null)
            {
                Captured(this, e);
            }
        }
Exemple #26
0
 public void OnPhotoCaptured(LowLagPhotoSequenceCapture s, PhotoCapturedEventArgs e)
 {
     if (_fileIndex < AMOUNT_OF_FRAMES_IN_SEQUENCE)
     {
         if (_saveTask == null)
         {
             _saveTask = Save(e.Frame, _fileIndex++);
         }
         else
         {
             _saveTask = _saveTask.ContinueWith(t => Save(e.Frame, _fileIndex++));
         }
     }
     else
     {
         StopSequenceCapture();
     }
 }
Exemple #27
0
        /// <summary>
        /// Handles the PhotoCaptured event of the CameraDevice control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PhotoCapturedEventArgs"/> instance containing the event data.</param>
        void CameraDevice_PhotoCaptured(object sender, PhotoCapturedEventArgs e)
        {
            try
            {
                e.CameraDevice.IsBusy = true;
                e.Transfer(e.FileName);
                ImageLocation = e.FileName;
            }
            finally
            {
                e.CameraDevice.IsBusy = false;
            }

            if (Captured != null)
            {
                Captured(this, e);
            }
        }
Exemple #28
0
        private string GetFileNameForDownload(PhotoCapturedEventArgs eventArgs)
        {
            string fileName = Path.Combine(StorePath, Path.GetFileName(eventArgs.FileName));

            if (File.Exists(fileName))
            {
                fileName =
                    StaticHelper.GetUniqueFilename(
                        Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_", 0,
                        Path.GetExtension(fileName));
            }

            if (string.IsNullOrEmpty(Path.GetExtension(fileName)))
            {
                fileName = Path.ChangeExtension(fileName, "nef");
            }

            return(fileName);
        }
Exemple #29
0
        public override void CapturePhoto()
        {
            var url = AsPrimitiveList <string>(Post(CreateJson("actTakePicture")))[0];

            if (url.Contains("?"))
            {
                url = url.Split('?')[0];
            }
            PhotoCapturedEventArgs args = new PhotoCapturedEventArgs
            {
                WiaImageItem = null,
                EventArgs    = new PortableDeviceEventArgs(),
                CameraDevice = this,
                FileName     = url.Replace('/', '\\'),
                Handle       = url
            };

            OnPhotoCapture(this, args);
        }
 private void PhotoCaptureEvent(byte[] data)
 {
     try
     {
         PhotoCapturedEventArgs args = new PhotoCapturedEventArgs
         {
             WiaImageItem = null,
             EventArgs    = null,
             CameraDevice = this,
             FileName     = "img0000.jpg",
             Handle       = data
         };
         OnPhotoCapture(this, args);
     }
     catch (Exception e)
     {
         Log.Error("Photo capture error", e);
     }
 }
 public void OnPhotoCaptured(LowLagPhotoSequenceCapture s, PhotoCapturedEventArgs e)
 {
     if (_fileIndex < AMOUNT_OF_FRAMES_IN_SEQUENCE)
     {
         if (_saveTask == null)
         {
             _saveTask = Save(e.Frame, _fileIndex++);
         }
         else
         {
             _saveTask = _saveTask.ContinueWith(t => Save(e.Frame, _fileIndex++));
         }
     }
     else
     {
         StopSequenceCapture();
     }
 }
Exemple #32
0
        private async void photoCapturedEventHandler(LowLagPhotoSequenceCapture senders, PhotoCapturedEventArgs args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {

                try
                {
                    if (m_frameNum == (m_pastFrame + m_futureFrame))
                    {
                        btnStartStopPhotoSequence.IsEnabled = false;

                        await m_photoSequenceCapture.StopAsync();

                        btnStartStopPhotoSequence.IsEnabled = true;
                        btnSaveToFile.IsEnabled = true;
                        ThumbnailGrid.SelectedIndex = m_selectedIndex;
                    }
                    else if (m_frameNum < (m_pastFrame + m_futureFrame))
                    {
                        var bitmap = new BitmapImage();

                        m_framePtr[m_frameNum] = args.Frame;
               
                        bitmap.SetSource(args.Thumbnail);

                        var image = new Image();
                        image.Source = bitmap;

                        image.Width = 160;
                        image.Height = 120;

                        var ThumbnailItem = new Windows.UI.Xaml.Controls.GridViewItem();
                        ThumbnailItem.Content = image;
                        ThumbnailGrid.Items.Add(ThumbnailItem);

                        if ((!m_highLighted) && (args.CaptureTimeOffset.Ticks > 0))
                        {
                            //first picture with timeSpam > 0 get highlighted 
                            m_highLighted = true;

                            ThumbnailItem.BorderThickness = new Thickness(1);
                            ThumbnailItem.BorderBrush = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Red);
                            m_selectedIndex = (int)m_ThumbnailNum;
                        }
                        m_ThumbnailNum++;
                    }
                    m_frameNum++;
                }
                catch (Exception ex)
                {
                    ShowExceptionMessage(ex);
                }
            });

        }