public Model() { _objects = new ObservableCollection <ObjectModel>(); _managers = new List <NikonManager>(); string[] md3s = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.md3", SearchOption.AllDirectories); if (md3s.Length == 0) { Log.GetInstance().WriteLine("Couldn't find any MD3 files in " + Directory.GetCurrentDirectory()); Log.GetInstance().WriteLine("Download MD3 files from Nikons SDK website: https://sdk.nikonimaging.com/apply/"); } foreach (string md3 in md3s) { const string requiredDllFile = "NkdPTP.dll"; string requiredDllPath = Path.Combine(Path.GetDirectoryName(md3), requiredDllFile); if (!File.Exists(requiredDllPath)) { Log.GetInstance().WriteLine("Warning: Couldn't find " + requiredDllFile + " in " + Path.GetDirectoryName(md3) + ". The library will not work properly without it!"); } Log.GetInstance().WriteLine("Opening " + md3); NikonManager manager = new NikonManager(md3); manager.DeviceAdded += new DeviceAddedDelegate(_manager_DeviceAdded); manager.DeviceRemoved += new DeviceRemovedDelegate(_manager_DeviceRemoved); _objects.Add(new ObjectModel(manager)); _managers.Add(manager); } }
private void Mgr_DeviceAdded(NikonManager sender, NikonDevice device) { NikonManager tmpManager = _activeNikonManager; var connected = false; try { _activeNikonManager = sender; _activeNikonManager.DeviceRemoved += Mgr_DeviceRemoved; Logger.WriteTraceMessage("NikonManager starting device init: " + _activeNikonManager.Name); Init(device); Name = _camera.Name; if (Name == "") { _activeNikonManager = tmpManager; } connected = true; } catch (Exception ex) { Logger.WriteTraceMessage(ex.ToString()); } finally { Connected = connected; _cameraConnected.TrySetResult(Connected); } }
public DrawingForm() { InitializeComponent(); #region Initialize Nikon // Disable buttons ToggleButtons(false); // Initialize live view timer liveViewTimer = new Timer(); liveViewTimer.Tick += new EventHandler(liveViewTimer_Tick); liveViewTimer.Interval = 1000 / 30; // Initialize Nikon manager manager = new NikonManager("Type0009.md3"); manager.DeviceAdded += new DeviceAddedDelegate(manager_DeviceAdded); manager.DeviceRemoved += new DeviceRemovedDelegate(manager_DeviceRemoved); #endregion /* #region Initialize Emgu * CvInvoke.UseOpenCL = false; * try * { * capture = new VideoCapture(); * capture.ImageGrabbed += ProcessFrame; * } * catch (NullReferenceException excpt) * { * MessageBox.Show(excpt.Message); * } #endregion */ }
public void Run() { try { // Create manager object - make sure you have the correct MD3 file for your Nikon DSLR (see https://sdk.nikonimaging.com/apply/) NikonManager manager = new NikonManager("Type0003.md3"); // Listen for the 'DeviceAdded' event manager.DeviceAdded += manager_DeviceAdded; // Wait for a device to arrive _waitForDevice.WaitOne(); // Hook up capture events _device.ImageReady += _device_ImageReady; _device.CaptureComplete += _device_CaptureComplete; // Capture _device.Capture(); // Wait for the capture to complete _waitForCaptureComplete.WaitOne(); // Shutdown manager.Shutdown(); } catch (NikonException ex) { Console.WriteLine(ex.Message); } }
public MainScreen() { InitializeComponent(); CenterComponents(); this.Cursor = new Cursor(GetType(), "hand128.cur"); imageSenderTimer = new Timer(); imageSenderTimer.Interval = 60000; imageSenderTimer.Tick += imageSenderTimer_Tick; imageSenderTimer.Start(); manager = new NikonManager("D40_Mod.md3"); manager.DeviceAdded += new DeviceAddedDelegate(manager_DeviceAdded); manager.DeviceRemoved += new DeviceRemovedDelegate(manager_DeviceRemoved); viewCount = 3; list = new ImageList(viewCount); collection = new ImageCollection[viewCount]; imRead = new ImageRead("images"); while (imRead.GetImage()) { list.Add(imRead.CurrentImage); } try { collection = list.CurrentItems; FillPictureBoxes(); } catch (NoItemFoundException) { AutoClosingMessageBox.Show(this, "Sisteme kayıtlı fotoğraf bulunamadı", "Hata", 3000, MessageBoxIcon.Error); } }
//AutoResetEvent _waitForCaptureComplete = new AutoResetEvent(false); public Form1() { InitializeComponent(); string username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; var macAddr = ( from nic in NetworkInterface.GetAllNetworkInterfaces() where nic.OperationalStatus == OperationalStatus.Up select nic.GetPhysicalAddress().ToString() ).FirstOrDefault(); Console.WriteLine("{0}_{1}", username, macAddr); devices = new Dictionary <int, NikonDevice>() { { 1, null }, { 2, null } }; // Disable buttons ToggleButtons(false); // Initialize live view timer //liveViewTimer = new Timer(); //liveViewTimer.Tick += new EventHandler(liveViewTimer_Tick); //liveViewTimer.Interval = 1000 / 30; // Initialize Nikon manager manager = new NikonManager("Type0004.md3"); manager.DeviceAdded += new DeviceAddedDelegate(manager_DeviceAdded); manager.DeviceRemoved += new DeviceRemovedDelegate(manager_DeviceRemoved); }
private void MainScreen_FormClosing(object sender, FormClosingEventArgs e) { manager.DeviceAdded -= new DeviceAddedDelegate(manager_DeviceAdded); manager.DeviceRemoved -= new DeviceRemovedDelegate(manager_DeviceRemoved); manager.Shutdown(); device = null; manager = null; }
public NikonController(string md3File) { SaveToPc = true; IsConnected = false; IsReady = false; IsSaved = false; man = new NikonManager(md3File); man.DeviceAdded += DeviceAdded; }
private void manager_DeviceAdded(NikonManager sender, NikonDevice device) { Device = device; // Wire device events Device.ImageReady += new ImageReadyDelegate(device_ImageReady); // Enable buttons button_takePicture.IsEnabled = true; button_takePicture.Content = "Start"; ToggleLiveView(); }
void manager_DeviceAdded(NikonManager sender, NikonDevice device) { camera = device; // Set shooting mode to 'continuous, highspeed' NikonEnum shootingMode = camera.GetEnum(eNkMAIDCapability.kNkMAIDCapability_ShootingMode); shootingMode.Index = (int)eNkMAIDShootingMode.kNkMAIDShootingMode_CH; camera.SetEnum(eNkMAIDCapability.kNkMAIDCapability_ShootingMode, shootingMode); }
private void CleanupUnusedManagers(NikonManager activeManager) { foreach (NikonManager mgr in _nikonManagers) { if (mgr != activeManager) { mgr.Shutdown(); } } _nikonManagers.Clear(); }
void manager_DeviceAdded(NikonManager sender, NikonDevice device) { if (_device == null) { // Save device _device = device; // Signal that we got a device _waitForDevice.Set(); } }
void manager_DeviceAdded(NikonManager sender, NikonDevice device) { this.device = device; // Set the device name cameraLabel.Text = device.Name; // Enable buttons ToggleCameraButtons(true); // Hook up device capture events device.ImageReady += new ImageReadyDelegate(device_ImageReady); device.CaptureComplete += new CaptureCompleteDelegate(device_CaptureComplete); }
void manager_DeviceRemoved(NikonManager sender, NikonDevice device) { this.device = null; // Stop live view timer liveViewTimer.Stop(); // Clear device name cameraLabel.Text = "No Camera"; // Disable buttons ToggleCameraButtons(false); // Clear live view picture pictureBox.Image = null; }
void manager_DeviceAdded(NikonManager sender, NikonDevice device) { Console.WriteLine("=> {0}, {1}", sender.Id, sender.Name); if (_device == null) { // Save device _device = device; // Signal that we got a device _waitForDevice.Set(); } }
void manager_DeviceRemoved(NikonManager sender, NikonDevice device) { this.device = null; // Stop live view timer liveViewTimer.Stop(); // Disable buttons ToggleButtons(false); // Clear live view picture imageBox.Image = null; }
void manager_DeviceAdded(NikonManager sender, NikonDevice device) { this.device = device; // Set the device name label_name.Text = device.Name; device.SaveMedia(1); // Enable buttons not_tasweer_design(true); // Hook up device capture events device.ImageReady += new ImageReadyDelegate(device_ImageReady); device.CaptureComplete += new CaptureCompleteDelegate(device_CaptureComplete); }
public void Disconnect() { Connected = false; liveViewTimer.Stop(); _lvCapture = false; _camera.LiveViewEnabled = false; _camera = null; _activeNikonManager?.Shutdown(); _nikonManagers?.Clear(); _nikonManagers = null; _activeNikonManager = null; //_camera.ImageReady -= Camera_ImageReady; //_camera.CaptureComplete -= _camera_CaptureComplete; }
public bool Connect(CancellationToken token) { var connected = false; Task.Run(() => { try { _nikonManagers.Clear(); string architecture = (IntPtr.Size == 4) ? "x86" : "x64"; var md3Folder = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "SDK", architecture, "Nikon"); Logger.WriteTraceMessage("md3Folder: " + md3Folder); foreach (string file in Directory.GetFiles(md3Folder, "*.md3", SearchOption.AllDirectories)) { Logger.WriteTraceMessage("Processing md3: " + file); NikonManager mgr = new NikonManager(file); mgr.DeviceAdded += Mgr_DeviceAdded; _nikonManagers.Add(mgr); } _cameraConnected = new TaskCompletionSource <bool>(); var d = DateTime.Now; do { token.ThrowIfCancellationRequested(); Thread.Sleep(500); } while (!_cameraConnected.Task.IsCompleted); connected = _cameraConnected.Task.Result; } catch (OperationCanceledException) { _activeNikonManager = null; } finally { CleanupUnusedManagers(_activeNikonManager); } return(connected); //return Task.FromResult<bool>(connected); }).Wait(); return(connected); //return Task.FromResult<bool>(true); }
void _manager_DeviceRemoved(NikonManager sender, NikonDevice device) { ObjectModel deviceModelToRemove = null; foreach (ObjectModel deviceModel in _objects) { if (deviceModel.Object == device) { deviceModelToRemove = deviceModel; } } _objects.Remove(deviceModelToRemove); OnPropertyChanged("NewestIndex"); }
static void Main(string[] args) { NikonManager nikonManager = new NikonManager("Type0004.md3"); // D7000 try { nikonManager.DeviceAdded += OnDeviceAdded; Console.WriteLine("Press any key to continue.."); Console.ReadLine(); } finally { nikonManager.Shutdown(); } }
private static void OnDeviceAdded(NikonManager sender, NikonDevice device) { Console.WriteLine("Nikon camera added..."); try { int batteryLevel = device.GetInteger(eNkMAIDCapability.kNkMAIDCapability_BatteryLevel); Console.WriteLine($"Battery level: {batteryLevel}"); PrintCapabilities(device); } catch (NikonException ex) { Console.WriteLine($"Error getting the battery level: {ex.Message}, code: {ex.ErrorCode}"); } }
void manager_DeviceRemoved(NikonManager sender, NikonDevice device) { this.device = null; //stop live view timer liveViewTimer.Stop(); //clear device name label1.Text = "No Camera Attached"; labelBatteryLevel.Text = ""; //disable buttons ToggleButtons(false); //clear picture box pictureBox1.Image = null; }
public void Run() { try { // Create manager object - make sure you have the correct MD3 file for your Nikon DSLR (see https://sdk.nikonimaging.com/apply/) NikonManager manager = new NikonManager("Type0003.md3"); // Listen for the 'DeviceAdded' event manager.DeviceAdded += manager_DeviceAdded; // Wait for a device to arrive _waitForDevice.WaitOne(); // Enable live view (required for manual focus) _device.LiveViewEnabled = true; // Get the current manual focus 'drive step' NikonRange driveStep = _device.GetRange(eNkMAIDCapability.kNkMAIDCapability_MFDriveStep); // Set the drive step to max driveStep.Value = driveStep.Max; _device.SetRange(eNkMAIDCapability.kNkMAIDCapability_MFDriveStep, driveStep); // Drive all the way to 'closest' DriveManualFocus(eNkMAIDMFDrive.kNkMAIDMFDrive_InfinityToClosest); // Set the drive step to something small driveStep.Value = 200.0; _device.SetRange(eNkMAIDCapability.kNkMAIDCapability_MFDriveStep, driveStep); // Drive manual focus towards infinity in small steps for (int i = 0; i < 10; i++) { DriveManualFocus(eNkMAIDMFDrive.kNkMAIDMFDrive_ClosestToInfinity); } // Disable live view _device.LiveViewEnabled = false; // Shutdown manager.Shutdown(); } catch (NikonException ex) { Console.WriteLine(ex.Message); } }
public tasweer_daf() { InitializeComponent(); // Disable buttons not_tasweer_design(false); // Initialize live view timer liveViewTimer = new System.Windows.Forms.Timer(); liveViewTimer.Tick += new EventHandler(liveViewTimer_Tick); liveViewTimer.Interval = 1000 / 30; // Initialize Nikon manager manager = new NikonManager("Type0014.md3"); manager.DeviceAdded += new DeviceAddedDelegate(manager_DeviceAdded); manager.DeviceRemoved += new DeviceRemovedDelegate(manager_DeviceRemoved); }
public Form1() { InitializeComponent(); // Disable buttons ToggleButtons(false); // Initialize live view timer liveViewTimer = new Timer(); liveViewTimer.Tick += new EventHandler(liveViewTimer_Tick); liveViewTimer.Interval = 1000 / 30; // Initialize Nikon manager manager = new NikonManager("Type0014.md3"); manager.DeviceAdded += new DeviceAddedDelegate(manager_DeviceAdded); manager.DeviceRemoved += new DeviceRemovedDelegate(manager_DeviceRemoved); }
void manager_DeviceRemoved(NikonManager sender, NikonDevice device) { devices[device.DeviceID] = null; //this.device = null; // Stop live view timer //liveViewTimer.Stop(); // Clear device name label_name.Text = "ŸoÏà™C"; // Disable buttons ToggleButtons(false); // Clear live view picture pictureBox.Image = null; }
public MainWindow() { InitializeComponent(); // Initialize live view timer liveViewTimer = new DispatcherTimer(); liveViewTimer.Tick += new EventHandler(liveViewTimer_Tick); liveViewTimer.Interval = new TimeSpan(0, 0, 1); _LiveView = new LiveView(); photostrip = new PhotoStrip(); Manager = new NikonManager(@"Type0004.md3"); button_takePicture.Content = "Connect\n Camera"; button_takePicture.IsEnabled = false; Manager.DeviceAdded += new DeviceAddedDelegate(manager_DeviceAdded); }
public async Task <bool> Connect(CancellationToken token) { Task.Run(async() => { var connected = false; try { _nikonManagers.Clear(); string architecture = (IntPtr.Size == 4) ? "x86" : "x64"; var md3Folder = Path.Combine("C:/Program Files (x86)/Common Files/ASCOM/Camera/ASCOM.DSLR.Camera", "SDK", architecture, "Nikon"); foreach (string file in Directory.GetFiles(md3Folder, "*.md3", SearchOption.AllDirectories)) { Logger.WriteTraceMessage("Processing md3: " + file); NikonManager mgr = new NikonManager(file); mgr.DeviceAdded += Mgr_DeviceAdded; _nikonManagers.Add(mgr); } _cameraConnected = new TaskCompletionSource <bool>(); var d = DateTime.Now; do { token.ThrowIfCancellationRequested(); Thread.Sleep(500); } while (!_cameraConnected.Task.IsCompleted); connected = _cameraConnected.Task.Result; } catch (OperationCanceledException) { _activeNikonManager = null; } finally { CleanupUnusedManagers(_activeNikonManager); } return(connected); }).Wait(); return(true); }
void manager_DeviceAdded(NikonManager sender, NikonDevice device) { DeviceCounter += 1; device.DeviceID = DeviceCounter; devices[DeviceCounter] = device; //this.device = device; // Set the device name label_name.Text = device.Name; // Enable buttons ToggleButtons(true); // Hook up device capture events device.ImageReady += new ImageReadyDelegate(device_ImageReady); device.CaptureComplete += new CaptureCompleteDelegate(device_CaptureComplete); Console.WriteLine("{0} - >", devices[DeviceCounter].DeviceID); }