public WebCam(HWDeviceDesciption selectedCamera) { isRecording = false; //logger.Debug("WebCam Constructor"); cameraDevice = new VideoCaptureDevice(selectedCamera.DeviceId); cameraDevice.NewFrame += CameraDevice_NewFrame; //logger.Debug("WebCam Constractor end"); }
private void GetPicturesForm_Load(object sender, EventArgs e) { savedDevice = config.GetDevice(pictureDialog.GetDeviceType()); deviceWorker = devicesFactory.GetDeviceWorkFactory(pictureDialog.GetDeviceType()); deviceWorker.Completed += DeviceWorker_Completed; deviceWorker.Error += DeviceWorker_Error; deviceWorker.ImageChanged += DeviceWorker_ImageChanged; }
public WebCam(int durationTimeSec, HWDeviceDesciption selectedCamera) : this(selectedCamera) { // logger.Debug("WebCam Constructor"); //cameraDevice = new VideoCaptureDevice(selectedCamera.DeviceId); //cameraDevice.NewFrame += CameraDevice_NewFrame; this.durationTimeSec = durationTimeSec; // logger.Debug("WebCam Constractor end"); }
private void DevicesSettings_Load(object sender, EventArgs e) { devicesSearcher = new DeviceSearchFactory(settings.GetDeviceType()); devices = devicesSearcher.GetDevices().ToList(); savedDevice = _deviceConfiguration.GetDevice(settings.GetDeviceType()); if (!devices.Any()) { SaveSetting.Text = "Закрыть"; } }
public void SaveDevice(HWDeviceDesciption device) { switch (device.Device) { case DeviceType.Scanner: currentConfiguration.Scanner.Device = device; break; case DeviceType.WebCam: currentConfiguration.WebCam.Device = device; break; } SaveConfiguration(); }
public HWDeviceDesciption GetDevice(DeviceType deviceType) { HWDeviceDesciption device = new HWDeviceDesciption(); switch (deviceType) { case DeviceType.Scanner: device = currentConfiguration.Scanner.Device; break; case DeviceType.WebCam: device = currentConfiguration.WebCam.Device; break; } return(device); }
public void SaveDevice_TestMethod() { IDeviceConfiguration configuration = new ConfigurationSettings(); var webCam = new HWDeviceDesciption() { Device = DeviceType.WebCam, DeviceId = "camera id custom", Name = "camera name custom" }; configuration.SaveDevice(webCam); var savedWebCam = configuration.GetDevice(DeviceType.WebCam); Assert.AreEqual(savedWebCam.Device, webCam.Device); Assert.AreEqual(savedWebCam.DeviceId, webCam.DeviceId); Assert.AreEqual(savedWebCam.Name, webCam.Name); Assert.AreEqual(savedWebCam.IsSet, webCam.IsSet); }
public Scanner(HWDeviceDesciption selectedScanner) { this.selectedScanner = selectedScanner; twain = new Twain32(); twain.IsTwain2Enable = true; // set twain settings twain.DisableAfterAcquire = true; twain.ShowUI = false; if (this.ParentWindowHandle != IntPtr.Zero) { var parentWnd = new NativeWindow(); parentWnd.AssignHandle(this.ParentWindowHandle); twain.Parent = parentWnd; } // add event handlers twain.EndXfer += endXferEventHandler; twain.AcquireCompleted += acquireCompletedEventHandler; twain.AcquireError += acquireErrorEventHandler; }
public WebCamSettings() { Device = new HWDeviceDesciption(); }
public ScannerSetings() { Device = new HWDeviceDesciption(); }
public bool IsScannerAvailible() { var Scanner = Configuration.GetDevice(DeviceType.Scanner); var twain = new Saraff.Twain.Twain32(); var isDsmOpened = false; try { twain.IsTwain2Enable = false; isDsmOpened = twain.OpenDSM(); twain.ShowUI = false; } catch (Exception ex) { if (twain != null) { twain.CloseDSM(); twain.Dispose(); } logger.Error(ex); return(false); } if (isDsmOpened) { if (!string.IsNullOrEmpty(Scanner.DeviceId)) { if (twain.SourcesCount >= int.Parse(Scanner.DeviceId) + 1) { twain.SourceIndex = int.Parse(Scanner.DeviceId); } else { return(false); } } else //если мы все-таки папали в ветку else, значит устройства еще не было, нужно сохранить первый попавшийся в конфиг { if (twain.SourcesCount != 0) { Scanner = new HWDeviceDesciption { Device = DeviceType.Scanner, DeviceId = "0", Name = twain.GetSourceProductName(0) }; Configuration.SaveDevice(Scanner); twain.SourceIndex = 0; } } for (int i = 0; i < twain.SourcesCount; i++) { if (Scanner.Name == twain.GetSourceProductName(i)) { //совпадение по имени выбранного устройства со списком не гарантирует работу сканера. сканер может быть выключен или иметь битый драйвер, например. if (Scanner.DeviceId == i.ToString()) { //проверить работу сканера можно здесь... //неужели начать сканирование и оборвать единственный способ? twain.AcquireError += twain_AcquireError; twain.AcquireCompleted += twain_AcquireCompleted; try { if (twain.SourcesCount >= int.Parse(Scanner.DeviceId) + 1) { twain.OpenDataSource(); var resolutions = twain.Capabilities.XResolution.Get(); if (resolutions.Count > 0) { twain.Capabilities.XResolution.Set((float)resolutions[0]); twain.Capabilities.YResolution.Set((float)resolutions[0]); } this.CheckCompleted = false; twain.ImageLayout = new RectangleF(new PointF(0, 0), new SizeF(0.2f, 0.2f)); twain.ShowUI = false; twain.Acquire(); } else { return(false); } } catch (Exception ex) { twain.CloseDataSource(); twain.CloseDSM(); twain.Dispose(); logger.Error("Не могу установить соединение со сканером: \n" + ex.Message + "\n Inner exeption: \n" + ex.InnerException); return(false); } while (!this.CheckCompleted) { System.Windows.Forms.Application.DoEvents(); } return(this.IsScanerWork); } } } // если мы дошли до этого места, значит: // 1. в конфиге уже сохранено какое-то устройство. // 2. в списке доступных устройств его нет // по идеи, ничего делать не нужно, возвращаем false. выбранное устройство не доступно(нет в списке) // } return(false); }