/// <inheritdoc /> public IEnumerable <string> Discover() { lock (_discoveryLock) { UsbDeviceCollection?usbDeviceCollection = _context.List(); _context.SetDebugLevel(LibUsbDotNet.LogLevel.Debug); // Filter out all but Concept2 Vendor var discoveredDevices = usbDeviceCollection.Where(d => d.VendorId == VendorId); // Discover disconnected device based on location foreach (UsbDevice detachedDevice in _devices.Values.Except(discoveredDevices, new IUsbDeviceComparer())) { Location location = new (detachedDevice.BusNumber, detachedDevice.Address); // If events are enabled, fire one for the device being lost EventArgs args = new DeviceEventArgs(location); DeviceLost?.Invoke(this, args); // Clean up device Destroy(detachedDevice); // Remove from devices _devices.Remove(location, out _); } // Discover new devices using Location as the comparer foreach (UsbDevice foundDevice in discoveredDevices.Except(_devices.Values, new IUsbDeviceComparer())) { if (!IsValidDevice(foundDevice)) { _logger.LogWarning("Invalid device encountered. Not being added to the device list."); } Location location = new (foundDevice.BusNumber, foundDevice.Address); if (!foundDevice.IsOpen) { Initialize(foundDevice); } string serialNumber = foundDevice.Info.SerialNumber; // If events are enabled, fire one for the device being found EventArgs args = new DeviceEventArgs(location) { SerialNumber = serialNumber }; DeviceFound?.Invoke(this, args); // Add to devices _devices.TryAdd(location, serialNumber, foundDevice); } return(_devices.SerialNumbers); } }
static NatUtility() { foreach (var searcher in new ISearcher [] { UpnpSearcher.Instance, PmpSearcher.Instance }) { searcher.DeviceFound += (o, e) => DeviceFound?.Invoke(o, e); searcher.DeviceLost += (o, e) => DeviceLost?.Invoke(o, e); } }
/// <summary> /// Called when a discovered BLE device is no longer reachable /// </summary> /// <param name="sender">Device watcher which discovered the device</param> /// <param name="device_info">BLE device information</param> private void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate device_info) { // Retrieve device information BleDeviceInformation ble_device_info = new BleDeviceInformation(); ble_device_info.Id = device_info.Id; // Notify device removal DeviceLost?.Invoke(this, ble_device_info); }
private void OnDeviceStateChanged(DeviceState state) { if (state == DeviceState.Connected) { DeviceFound?.Invoke(this, Device); } else { DeviceLost?.Invoke(this, null); } }
/// <summary> /// Saves the current screen at a scaled resolution /// </summary> /// <param name="filename">The file name to save the screenshot too</param> /// <param name="size">The size to scale the resolution down too</param> public void Screenshot(string filename, Size size) { #region Sanity checks if (filename == null) { throw new ArgumentNullException(nameof(filename)); } #endregion if (size.Width > RenderSize.Width || size.Height > RenderSize.Height) { throw new ArgumentException(Resources.InvalidScreenshotSize, nameof(size)); } // Backup PostRender delegate and deactiavte it Action postRender = PreRender; PreRender = null; var sizeBackup = new Size(); if (size != RenderSize) { // The size needs to be changed // Backup current size and replace it with new size sizeBackup = RenderSize; RenderSize = size; // Update everything hooked to the engine DeviceLost?.Invoke(); DeviceReset?.Invoke(); } // Render one frame for screenshot Render(0, true); // Copy the BackBuffer to the file Surface.ToFile(BackBuffer, filename, ImageFileFormat.Jpg, new Rectangle(new Point(), size)); Log.Info("Screenshot created"); if (sizeBackup != Size.Empty) { // The size was changed // Restore the original viewport RenderSize = sizeBackup; // Update everything hooked to the engine DeviceLost?.Invoke(); DeviceReset?.Invoke(); // Render one frame to restore original configuration Render(0, true); } // Restore PostRender delegate PreRender = postRender; }
private void UpdateDevicesNearby(object sender, ElapsedEventArgs e) { foreach (var ls in _lastSeen.ToArray()) { if ((DateTime.Now - ls.Value).TotalMilliseconds > _nearbyTimeout) { var device = _devices.SingleOrDefault(d => d.Value.Id == ls.Key).Key; _lastSeen.Remove(ls.Key); DeviceLost?.Invoke(this, device); } } }
private void OnDeviceLost(DeviceWatcher sender, DeviceInformationUpdate args) { lock (RemoteDevices) { var device = RemoteDevices.FirstOrDefault(x => x.DeviceId == args.Id); if (device != null) { RemoteDevices.Remove(device); DeviceLost.Invoke(this, device); RaisePropertyChanged(new PropertyChangedEventArgs(nameof(RemoteDevices))); } } }
protected void RaiseDeviceLost(NatDevice device) { NatDevice actualDevice; lock (Devices) { // If the device is not in the dictionary, bail out. if (!Devices.TryGetValue(device, out actualDevice)) { return; } Devices.Remove(actualDevice); } DeviceLost?.Invoke(this, new DeviceEventArgs(actualDevice)); }
/// <summary> /// Recreate all device resources and set them back to the current state. /// Locks the set of holographic camera resources until the function exits. /// </summary> public void HandleDeviceLost() { DeviceLost?.Invoke(this, null); UseHolographicCameraResources(cameraResourcesDictionary => { foreach (var pair in cameraResourcesDictionary) { var cameraResources = pair.Value; cameraResources.ReleaseAllDeviceResources(this); } }); InitializeUsingHolographicSpace(); DeviceRestored?.Invoke(this, null); }
public void Reconnect() { if (Device != null) { DeviceLost?.Invoke(this, null); Device.ParameterChanged -= OnDeviceParamChanged; try { Device.Execute(Command.StopSignal); Device.Disconnect(); } catch { } Device.Dispose(); Device = null; } }
/// <summary> /// Resets the engine /// </summary> private void Reset() { // Set flag to prevent infinite loop of resets _isResetting = true; #region Cleanup Log.Info("Clearing Direct3D resources"); BackBuffer.Dispose(); DeviceLost?.Invoke(); #endregion #region Wait // Wait in case the device isn't ready to be reset while (Device.TestCooperativeLevel() == ResultCode.DeviceLost) { Thread.Sleep(100); WinForms.Application.DoEvents(); } // Catch internal driver errors var result = Device.TestCooperativeLevel(); if (result != ResultCode.DeviceNotReset && result != ResultCode.Success) { throw new Direct3D9Exception(result); } #endregion #region Reset Log.Info("Resetting Direct3D device"); Log.Info("Presentation parameters:\n" + PresentParams); Device.Reset(PresentParams); // Setup the default values for the Direct3D device and restore resources SetupTextureFiltering(); RenderViewport = Device.Viewport; BackBuffer = Device.GetBackBuffer(0, 0); DeviceReset?.Invoke(); State.Reset(); Performance.Reset(); #endregion _isResetting = NeedsReset = false; }
public void Reconnect() { if (Device != null) { DeviceLost?.Invoke(this, null); Device.ParameterChanged -= OnDeviceParamChanged; try { Device.Execute(Command.StopSignal); Device.Disconnect(); } catch { } Device.Dispose(); Device = null; } var deviceSearchForm = new DeviceSearchForm(new List <string>()); if (deviceSearchForm.ShowDialog() == DialogResult.OK) { OnDeviceFound(deviceSearchForm.SelectedDevice); } }
/// <summary> /// Raises the on device lost. /// </summary> protected void RaiseOnDeviceLost() { DeviceLost?.Invoke(this, EventArgs.Empty); }
public void Start(string id) { #if DEBUG if (!Enabled) { throw new InvalidProgramException(); } #endif if (!string.IsNullOrEmpty(id) && id == currentDeviceId && started) { return; } if (started) { // We must wait until the monitor is fully closed before restarting it. // We will call back into here from the "device stopped" event. log.DebugFormat("Audio input level monitor already started on a different device."); changeDeviceAsked = true; nextDeviceId = id; Stop(); return; } changeDeviceAsked = false; nextDeviceId = null; if (WaveIn.DeviceCount == 0) { log.DebugFormat("Audio input level monitor failed to start, no input device available."); DeviceLost?.Invoke(this, EventArgs.Empty); return; } if (waveIn == null) { waveIn = new WaveInEvent(); waveIn.WaveFormat = new WaveFormat(22050, 1); waveIn.DataAvailable += WaveIn_DataAvailable; waveIn.RecordingStopped += WaveIn_RecordingStopped; } int deviceNumber = 0; if (!string.IsNullOrEmpty(id)) { int waveInDevices = WaveIn.DeviceCount; for (int i = 0; i < waveInDevices; i++) { WaveInCapabilities wic = WaveIn.GetCapabilities(i); if (wic.ProductName == id) { deviceNumber = i; break; } } } try { waveIn.DeviceNumber = deviceNumber; waveIn.StartRecording(); started = true; WaveInCapabilities wic = WaveIn.GetCapabilities(waveIn.DeviceNumber); currentDeviceId = wic.ProductName; log.DebugFormat("Audio input level monitor started: {0}", wic.ProductName); } catch (Exception e) { log.ErrorFormat("The microphone is not available. {0}", e.Message); DeviceLost?.Invoke(this, EventArgs.Empty); currentDeviceId = null; } }
protected virtual void OnDeviceLost(object sender, DeviceEventArgs eventArgs) { DeviceLost.DispatchOnContext <DeviceEventArgs>(this, EventContext, eventArgs); }
protected virtual void OnDeviceLost(EventArgs e) { DeviceLost?.Invoke(this, e); }
internal void ServiceDropped() { OnDeviceLost(); DeviceLost?.Invoke(this, EventArgs.Empty); }
public int DeviceRemoved(int lFindData, string bstrUDN) { DeviceLost?.Invoke(lFindData, bstrUDN); return(default(int)); }