Пример #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            api = new CanonAPI();

            btnDeviceRefresh_Click(sender, e);
            btnRefreshCameras_Click(sender, e);
        }
Пример #2
0
        public MainForm()
        {
            try
            {
                InitializeComponent();

                var ports = SerialPort.GetPortNames();
                cBoxCOMPORT.DataSource = ports;

                mySerialPort = new SerialPort(cBoxCOMPORT.Text, 115200, Parity.None, 8, StopBits.One);

                APIHandler                           = new CanonAPI();
                APIHandler.CameraAdded              += APIHandler_CameraAdded;
                ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;
                ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;
                SavePathTextBox.Text                 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Merijumi/2020_05_31");
                SaveFolderBrowser.Description        = "Save Images To...";
                LiveViewPicBox.Paint                += LiveViewPicBox_Paint;
                LVBw = LiveViewPicBox.Width;
                LVBh = LiveViewPicBox.Height;
                RefreshCamera();
                IsInit = true;
            }
            catch (DllNotFoundException) { ReportError("Canon DLLs not found!", true); }
            catch (Exception ex) { ReportError(ex.Message, true); }
        }
Пример #3
0
 private void APIHandler_CameraAdded(CanonAPI sender)
 {
     if (sendToUnity != null)
     {
         sendToUnity("{\"CanmeraAdded\":" + sender.ToString() + "}");
     }
 }
Пример #4
0
 public CanonSdkCamera()
 {
     APIHandler                           = new CanonAPI();
     APIHandler.CameraAdded              += APIHandler_CameraAdded;
     ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;
     ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;
 }
Пример #5
0
 public void Initial()
 {
     try
     {
         APIHandler                           = new CanonAPI();
         APIHandler.CameraAdded              += APIHandler_CameraAdded;
         ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;
         ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;
         path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
         GetCameraList();
         IsInit = true;
         if (sendToUnity != null)
         {
             sendToUnity.Invoke("{\"initial\":\"true\"}");
         }
     }
     catch (DllNotFoundException) { ReportError("Canon DLLs not found!", true); }
     catch (Exception ex) {
         ReportError(ex.Message, true);
         if (sendToUnity != null)
         {
             sendToUnity.Invoke("{\"initial\":\"false\"}");
         }
     }
 }
Пример #6
0
        public MainWindow()
        {
            try
            {
                InitializeComponent();
                APIHandler                           = new CanonAPI();
                APIHandler.CameraAdded              += APIHandler_CameraAdded;
                ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;
                ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;
                SavePathTextBox.Text                 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                SetImageAction                       = (BitmapImage img) => { bgbrush.ImageSource = img; };
                SaveFolderBrowser.Description        = "Save Images To...";
                RefreshCamera();
                IsInit = true;

                aTimer          = new System.Timers.Timer();
                aTimer.Elapsed += new ElapsedEventHandler(OnaTimedEvent);
                aTimer.Interval = 100;
                aTimer.Enabled  = true;

                bTimer          = new System.Timers.Timer();
                bTimer.Elapsed += new ElapsedEventHandler(OnbTimedEvent);
                bTimer.Interval = 1000;
                bTimer.Enabled  = true;
            }
            catch (DllNotFoundException) { ReportError("Canon DLLs not found!", true); }
            catch (Exception ex) { ReportError(ex.Message, true); }
        }
        static void Api_CameraAdded(CanonAPI sender)
        {
            var camList = sender.GetCameraList();

            MainCamera = camList[0];
            Waiter.Set();
        }
Пример #8
0
        public MainWindow()
        {
            Console.WriteLine(DateTime.Now.ToString("MM-dd-yyyy-HH.mm.ss"));

            try
            {
                InitializeComponent();

                socetListener              = new AsynchronousSocketListener();
                socetListener.SocketEvent += SocetListener_SocketEvent;
                socetListener.Start();

                APIHandler                           = new CanonAPI();
                APIHandler.CameraAdded              += APIHandler_CameraAdded;
                ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;
                ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;
                localPath            = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                SavePathTextBox.Text = localPath;

                SetImageAction = (BitmapImage img) => { bgbrush.ImageSource = img; };
                SaveFolderBrowser.Description = "Save Images To...";
                RefreshCamera();
                IsInit = true;
            }
            catch (DllNotFoundException) { ReportError("Canon DLLs not found!", true); }
            catch (Exception ex) { ReportError(ex.Message, true); }
        }
Пример #9
0
        public MainWindow()
        {
            InitializeComponent();
            FillSavedData();
            ActivateTimers();
            CheckTemplate();

            //Canon:
            try
            {
                Create.TodayPhotoFolder();
                APIHandler              = new CanonAPI();
                APIHandler.CameraAdded += APIHandler_CameraAdded;

                ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;
                ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;

                SetImageAction = (BitmapImage img) => { liveView.ImageSource = img; };

                RefreshCamera();
                OpenSession();
                MainCamera.SetCapacity(4096, 0x1FFFFFFF);
            }
            // TODO: Close main windows when null reference occures
            catch (NullReferenceException) { Report.Error("Chceck if camera is turned on and restart the program", true); }
            catch (DllNotFoundException) { Report.Error("Canon DLLs not found!", true); }
            catch (Exception ex) { Report.Error(ex.Message, true); }
        }
Пример #10
0
        private void StartCamera()
        {
            try
            {
                APIHandler              = new CanonAPI();
                APIHandler.CameraAdded += APIHandler_CameraAdded;

                ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;
                ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;
                SetImageAction = (BitmapImage img) => {
                    bgbrush.ImageSource = img;
                    img = null;
                };
                SaveFolderBrowser.Description = "Save Images To...";
                RefreshCamera();
                IsInit = true;
                OpenSession();

                // store pics on pc
                MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Both);
                MainCamera.SetCapacity(4096, int.MaxValue);

                StartLV();
                SetLVAf();
            }
            catch (DllNotFoundException) { ReportError("Canon DLLs not found!", true); Application.Current.Shutdown(); }
            catch (Exception ex) { ReportError("Error starting camera: " + ex.Message, true); Application.Current.Shutdown(); }
        }
Пример #11
0
 public CanonSdkCamera(List <CameraModel> cameraModelsHistory) : base(cameraModelsHistory)
 {
     APIHandler                           = new CanonAPI();
     APIHandler.CameraAdded              += APIHandler_CameraAdded;
     ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;
     ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;
 }
Пример #12
0
 public bool Initialize()
 {
     try
     {
         APIHandler = new CanonAPI();
         List <Camera> cameras = APIHandler.GetCameraList();
         if (!OpenSession())
         {
             Console.WriteLine("No camera found. Please plug in camera");
             APIHandler.CameraAdded += APIHandler_CameraAdded;
             WaitEvent.WaitOne();
             WaitEvent.Reset();
             return(false);
         }
         else
         {
             MainCamera.CloseSession(); Console.WriteLine("Session closed"); return(true);
         }
     }
     catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(false); }
     finally
     {
         MainCamera?.Dispose();
         APIHandler.Dispose();
     }
 }
Пример #13
0
        public MainForm()
        {
            try
            {
                InitializeComponent();

                Api              = new CanonAPI();
                Api.CameraAdded += Api_CameraAdded;

                ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;
                ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;

                SavePathTextBox.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                EnableUI(false);
                EnableSavePath(false);
                BulbTextBox.Enabled = false;
                RefreshCameras();
            }
            catch (DllNotFoundException)
            {
                MessageBox.Show("Canon DLLs not found. They should lie beside the executable.");
                SessionButton.Enabled = false;
                RefreshButton.Enabled = false;
            }
            catch (Exception ex) { ShowError(ex); }
        }
Пример #14
0
 public Form1()
 {
     try
     {
         CamList = new List <Camera>();
         InitializeComponent();
         //this.TopMost = true;
         this.FormBorderStyle       = System.Windows.Forms.FormBorderStyle.None;
         this.KeyDown              += Form_KeyDown;
         this.FormClosing          += MainForm_FormClosing;
         this.WindowState           = FormWindowState.Maximized;
         this.BackgroundImage       = Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + @"\74801-amazing-gold-glitzer-hintergrundbilder-1920x1080.jpg");
         this.BackgroundImageLayout = ImageLayout.Zoom;
         APIHandler                           = new CanonAPI();
         APIHandler.CameraAdded              += APIHandler_CameraAdded;
         ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;
         ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;
         LiveViewPicBox.Paint                += LiveViewPicBox_Paint;
         LVBw = LiveViewPicBox.Width;
         LVBh = LiveViewPicBox.Height;
         RefreshCamera();
         IsInit = true;
         this.picBClose.Image     = Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + @"\if_cross-24_103181.png");
         this.picBClose.SizeMode  = PictureBoxSizeMode.Zoom;
         this.picBClose.Enabled   = false;
         this.picBClose.Visible   = false;
         this.picBReload.Image    = Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + @"\if_sync_126579.png");
         this.picBReload.SizeMode = PictureBoxSizeMode.Zoom;
         this.picBReload.Enabled  = false;
         this.picBReload.Visible  = false;
     }
     catch (DllNotFoundException) { ReportError("Canon DLLs not found!", true); }
     catch (Exception ex) { ReportError(ex.Message, true); }
     try
     {
         if (IsInit)
         {
             this.LiveViewPicBox.MouseDown += Form1_MouseDown;
         }
         for (int i = 0; i < 5; i++)
         {
             PictureBox pictureBox = new PictureBox();
             pictureBox.BackColor = Color.Black;
             pictureBox.Width     = 280;
             pictureBox.Height    = 205;
             pictureBox.SizeMode  = PictureBoxSizeMode.Zoom;
             //pictureBox.MaximumSize = new System.Drawing.Size(280, 205);
             pictureBoxes.Add(pictureBox);
             pictureBox.Click += PictureBox_Click;
             flowLayoutPanel1.Controls.Add(pictureBox);
         }
     }
     catch (Exception)
     {
     }
     watch();
 }
Пример #15
0
        public bool TakePhoto(string[] camSettings)  //where cS[0] is ISO(sensitivity), cS[1] is Tv(exposition), cS[2] is Tv in bulb mode and cS[3] is Av(apperture)
        {
            try
            {
                APIHandler = new CanonAPI();
                if (OpenSession())
                {
                    if (!Error)
                    {
                        ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                        MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
                        MainCamera.SetSetting(PropertyID.ISO, ISOValues.GetValue(camSettings[0]).IntValue);
                        MainCamera.SetSetting(PropertyID.Av, AvValues.GetValue(camSettings[3]).IntValue);
                        MainCamera.SetCapacity(4096, int.MaxValue);
                        Console.WriteLine($"Set image output path to: {ImageSaveDirectory}");

                        Console.WriteLine("Taking photo with special settings...");
                        CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv));
                        if (tv == TvValues.Bulb)
                        {
                            MainCamera.TakePhotoBulb(int.Parse(camSettings[2]));
                        }
                        else
                        {
                            MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue(camSettings[1]).IntValue);
                            MainCamera.TakePhoto();
                        }
                        WaitEvent.WaitOne();

                        if (!Error)
                        {
                            Console.WriteLine("Photo taken and saved"); return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(false); }
            finally
            {
                MainCamera?.Dispose();
                APIHandler.Dispose();
            }
        }
Пример #16
0
 private static void APIHandler_CameraAdded(CanonAPI sender)
 {
     try
     {
         Console.WriteLine("Camera added event received");
         if (!OpenSession())
         {
             Console.WriteLine("Sorry, something went wrong. No camera"); Error = true;
         }
     }
     catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); Error = true; }
     finally { WaitEvent.Set(); }
 }
Пример #17
0
 public void Init()
 {
     APIHandler                           = new CanonAPI();
     APIHandler.CameraAdded              += APIHandler_CameraAdded;
     ErrorHandler.SevereErrorHappened    += GUI.ErrorHandler_SevereErrorHappened;
     ErrorHandler.NonSevereErrorHappened += GUI.ErrorHandler_NonSevereErrorHappened;
     defSaveDir                           = @"c:" + Resources.Resources.Strings.CAMERA_DIRECTORY + DateTime.Today.ToLocalTime().ToString("yy-MM-dd");
     Console.WriteLine(defSaveDir);
     RefreshCamera();
     OpenSession();
     SetInitGUI();
     IsInit = true;
 }
Пример #18
0
        static void Main(string[] args)
        {
            try
            {
                APIHandler = new CanonAPI();
                List <Camera> cameras = APIHandler.GetCameraList();
                if (!OpenSession())
                {
                    Console.WriteLine("No camera found. Please plug in camera");
                    APIHandler.CameraAdded += APIHandler_CameraAdded;
                    WaitEvent.WaitOne();
                    WaitEvent.Reset();
                }

                if (!Error)
                {
                    ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                    MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
                    MainCamera.SetCapacity(4096, int.MaxValue);
                    Console.WriteLine($"Set image output path to: {ImageSaveDirectory}");

                    Console.WriteLine("Taking photo with current settings...");
                    CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv));
                    if (tv == TvValues.Bulb)
                    {
                        MainCamera.TakePhotoBulb(2);
                    }
                    else
                    {
                        MainCamera.TakePhoto();
                    }
                    WaitEvent.WaitOne();

                    if (!Error)
                    {
                        Console.WriteLine("Photo taken and saved");
                    }
                }
            }
            catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); }
            finally
            {
                MainCamera?.Dispose();
                APIHandler.Dispose();
                Console.WriteLine("Good bye! (press any key to close)");
                Console.ReadKey();
            }
        }
        public async Task <object> EndSession(dynamic input)
        {
            LogMessage("Ending session");

            MainCamera?.Dispose();
            MainCamera = null;
            Api.Dispose();
            Api = null;

            var result = new NodeResult();

            result.message = "Camera session ended.";
            result.success = true;

            return(result);
        }
Пример #20
0
 private void Main_Shown(object sender, EventArgs e)
 {
     try
     {
         APIHandler                           = new CanonAPI();
         APIHandler.CameraAdded              += APIHandler_CameraAdded;
         ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;
         ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;
         pictureBox.Paint                    += LiveViewPicBox_Paint;
         LVBw = pictureBox.Width;
         LVBh = pictureBox.Height;
         OpenSession();
         IsInit = true;
     }
     catch (DllNotFoundException) { ReportError("Canon DLLs not found!", true); }
     catch (Exception ex) { ReportError(ex.Message, true); }
 }
        public async Task <object> BeginSession(dynamic input)
        {
            LogMessage("Beginning session");

            try
            {
                CameraAddedWaiter = new AutoResetEvent(false);
                if (Api == null)
                {
                    Api              = new CanonAPI();
                    Api.CameraAdded += APIHandler_CameraAdded;
                }

                LogMessage("APIHandler initialised");
                List <Camera> cameras = Api.GetCameraList();

                foreach (var camera in cameras)
                {
                    LogMessage("APIHandler GetCameraList:" + camera);
                }

                if (cameras.Count > 0)
                {
                    OpenSession(cameras[0]);
                }
                else
                {
                    LogMessage("No camera found. Please plug in camera");
                    CameraAddedWaiter.WaitOne();
                    CameraAddedWaiter.Reset();
                }


                var result = new NodeResult();
                result.message = $"Opened session with camera: {MainCamera.DeviceName}";
                result.success = true;

                return(result);
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }
 private static void APIHandler_CameraAdded(CanonAPI sender)
 {
     try
     {
         LogMessage("Camera added event received");
         if (!RetrySession())
         {
             LogMessage("Sorry, something went wrong. No camera");
         }
     }
     catch (Exception ex)
     {
         LogMessage("Error: " + ex.ToString());
     }
     finally
     {
         CameraAddedWaiter.Set();
     }
 }
Пример #23
0
 public MainForm()
 {
     try
     {
         InitializeComponent();
         APIHandler                           = new CanonAPI();
         APIHandler.CameraAdded              += APIHandler_CameraAdded;
         ErrorHandler.SevereErrorHappened    += ErrorHandler_SevereErrorHappened;
         ErrorHandler.NonSevereErrorHappened += ErrorHandler_NonSevereErrorHappened;
         SavePathTextBox.Text                 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
         SaveFolderBrowser.Description        = "Save Images To...";
         LiveViewPicBox.Paint                += LiveViewPicBox_Paint;
         LVBw = LiveViewPicBox.Width;
         LVBh = LiveViewPicBox.Height;
         RefreshCamera();
         IsInit = true;
     }
     catch (DllNotFoundException) { ReportError("Canon DLLs not found!", true); }
     catch (Exception ex) { ReportError(ex.Message, true); }
 }
Пример #24
0
        void InitCanonApi()
        {
            if (_isInitCanonApi)
            {
                return;
            }

            try
            {
                _canonApi       = new CanonAPI();
                _isInitCanonApi = true;
            }
            catch (DllNotFoundException)
            {
                MessageBox.Show(ErrorTexts.CanonSdkFilesNotFound);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #25
0
        /*
         * Stub example for reference:
         */
        public async Task <object> BeginSession(dynamic input)
        {
            var result = new NodeResult();

            try
            {
                Console.WriteLine("Called C# method from node.");
                APIHandler = new CanonAPI();

                Console.WriteLine("APIHandler initialised");
                List <Camera> cameras = APIHandler.GetCameraList();
                foreach (var camera in cameras)
                {
                    Console.WriteLine("APIHandler GetCameraList:" + camera);
                }

                if (cameras.Count > 0)
                {
                    MainCamera = cameras[0];
                    MainCamera.DownloadReady += MainCamera_DownloadReady;
                    MainCamera.OpenSession();
                    Console.WriteLine($"Opened session with camera: {MainCamera.DeviceName}");
                }
                else
                {
                    Console.WriteLine("No camera found. Please plug in camera");
                    APIHandler.CameraAdded += APIHandler_CameraAdded;
                    WaitEvent.WaitOne();
                    WaitEvent.Reset();
                }

                result.message = $"Opened session with camera: {MainCamera.DeviceName}";
                result.success = true;
            }catch (Exception ex)
            {
                result.message = ex.Message;
                result.success = false;
            }
            return(result);
        }
Пример #26
0
        private void StopCamera()
        {
            IsInit = false;

            CloseSession();
            try
            {
                MainCamera?.Dispose();
                MainCamera = null;

                APIHandler?.Dispose();
                APIHandler.CameraAdded -= APIHandler_CameraAdded;
                APIHandler              = null;

                ErrorHandler.SevereErrorHappened    -= ErrorHandler_SevereErrorHappened;
                ErrorHandler.NonSevereErrorHappened -= ErrorHandler_NonSevereErrorHappened;
            }
            catch (Exception ex)
            {
                ReportError("Error stopping camera: " + ex.Message, false);
            }
        }
 private void APIHandler_CameraAdded(CanonAPI sender)
 {
     try { Dispatcher.Invoke((Action) delegate { RefreshCamera(); }); }
     catch (Exception ex) { ReportError(ex.Message, false); }
 }
 private void Api_CameraAdded(CanonAPI sender)
 {
     try { Invoke((MethodInvoker) delegate { GetCamera(); }); }
     catch (Exception ex) { ShowError(ex); }
 }
Пример #29
0
 private void APIHandler_CameraAdded(CanonAPI sender)
 {
 }
 private void Api_CameraAdded(CanonAPI sender)
 {
     try { Dispatcher.Invoke(delegate { RefreshCameras(); }); }
     catch (Exception ex) { ShowError(ex); }
 }