本文整理汇总了C#中Windows.Devices.Enumeration.DeviceWatcher类的典型用法代码示例。如果您正苦于以下问题:C# DeviceWatcher类的具体用法?C# DeviceWatcher怎么用?C# DeviceWatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeviceWatcher类属于Windows.Devices.Enumeration命名空间,在下文中一共展示了DeviceWatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDeviceRemoved
private void OnDeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate deviceInformationUpdate)
{
if (Disconnected != null)
{
Disconnected();
}
}
示例2: OnCustomSensorAdded
/// <summary>
/// Invoked when the device watcher finds a matching custom sensor device
/// </summary>
/// <param name="watcher">device watcher</param>
/// <param name="customSensorDevice">device information for the custom sensor that was found</param>
public async void OnCustomSensorAdded(DeviceWatcher watcher, DeviceInformation customSensorDevice)
{
try
{
customSensor = await CustomSensor.FromIdAsync(customSensorDevice.Id);
if (customSensor != null)
{
CustomSensorReading reading = customSensor.GetCurrentReading();
if (!reading.Properties.ContainsKey(CO2LevelKey))
{
rootPage.NotifyUser("The found custom sensor doesn't provide CO2 reading", NotifyType.ErrorMessage);
customSensor = null;
}
}
else
{
rootPage.NotifyUser("No custom sensor found", NotifyType.ErrorMessage);
}
}
catch (Exception e)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
rootPage.NotifyUser("The user may have denied access to the custom sensor. Error: " + e.Message, NotifyType.ErrorMessage);
});
}
}
示例3: HandleDeviceRemoved
private static void HandleDeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
{
var gamepad = _gamepads[args.Id];
_gamepads.Remove(args.Id);
GamepadRemoved?.Invoke(sender, gamepad);
}
示例4: OnProximitySensorAddedAsync
/// <summary>
/// Invoked when the device watcher detects that the proximity sensor was added.
/// </summary>
/// <param name="sender">The device watcher.</param>
/// <param name="device">The device that was added.</param>
private async void OnProximitySensorAddedAsync(DeviceWatcher sender, DeviceInformation device)
{
if (this.proximitySensor == null)
{
var addedSensor = ProximitySensor.FromId(device.Id);
if (addedSensor != null)
{
var minimumDistanceSatisfied = true;
//if we care about minimum distance
if (this.MinimumDistanceInMillimeters > Int32.MinValue)
{
if ((this.MinimumDistanceInMillimeters > addedSensor.MaxDistanceInMillimeters) ||
(this.MinimumDistanceInMillimeters < addedSensor.MinDistanceInMillimeters))
{
minimumDistanceSatisfied = false;
}
}
if (minimumDistanceSatisfied)
{
this.proximitySensor = addedSensor;
await SetActiveFromReadingAsync(this.proximitySensor.GetCurrentReading());
this.proximitySensor.ReadingChanged += ProximitySensor_ReadingChangedAsync;
}
}
}
}
示例5: DeviceRemoved
private void DeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
{
if (ExternalDeviceRemoved != null)
{
ExternalDeviceRemoved(this, args.Id);
}
}
示例6: HandleDeviceAdded
private static async void HandleDeviceAdded(DeviceWatcher sender, DeviceInformation args)
{
var device = await HidDevice.FromIdAsync(args.Id, FileAccessMode.Read);
var gamepad = new HidGamepad(args, device);
_gamepads.Add(args.Id, gamepad);
GamepadAdded?.Invoke(sender, gamepad);
}
示例7: UsbScopeDevice
public UsbScopeDevice()
{
var usbScopeSelector = HidDevice.GetDeviceSelector(UsagePage, UsageId, Vid, Pid);
ScopeDeviceWatcher = DeviceInformation.CreateWatcher(usbScopeSelector);
ScopeDeviceWatcher.Added += new TypedEventHandler<DeviceWatcher, DeviceInformation>(OnDeviceAdded);
ScopeDeviceWatcher.Removed += new TypedEventHandler<DeviceWatcher, DeviceInformationUpdate>(OnDeviceRemoved);
ScopeDeviceWatcher.Start();
}
示例8: DevicesRemoved
private async void DevicesRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
{
//Debug.WriteLine("Removed USB device: " + args.Id);
await dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
{
UpdateDevices();
});
}
示例9: DevicesEnumCompleted
private async void DevicesEnumCompleted(DeviceWatcher sender, object args)
{
//Debug.WriteLine("USB Devices Enumeration Completed");
await dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
{
UpdateDevices();
});
}
示例10: DeviceWatcher_Added
private async void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
{
await coreDispatcher.RunAsync(
CoreDispatcherPriority.Normal,
() =>
{
FoundDeviceList.Add(args);
});
}
示例11: OnProximitySensorAdded
/// <summary>
/// Invoked when the device watcher finds a proximity sensor
/// </summary>
/// <param name="sender">The device watcher</param>
/// <param name="device">Device information for the proximity sensor that was found</param>
private async void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device)
{
if (null == sensor)
{
ProximitySensor foundSensor = ProximitySensor.FromId(device.Id);
if (null != foundSensor)
{
if (null != foundSensor.MaxDistanceInMillimeters)
{
// Check if this is the sensor that matches our ranges.
// TODO: Customize these values to your application's needs.
// Here, we are looking for a sensor that can detect close objects
// up to 3cm away, so we check the upper bound of the detection range.
const uint distanceInMillimetersLValue = 30; // 3 cm
const uint distanceInMillimetersRValue = 50; // 5 cm
if (foundSensor.MaxDistanceInMillimeters >= distanceInMillimetersLValue &&
foundSensor.MaxDistanceInMillimeters <= distanceInMillimetersRValue)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
rootPage.NotifyUser("Found a proximity sensor that meets the detection range", NotifyType.StatusMessage);
});
}
else
{
// We'll use the sensor anyway, to demonstrate how events work.
// Your app may decide not to use the sensor.
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
rootPage.NotifyUser("Proximity sensor does not meet the detection range, using it anyway", NotifyType.StatusMessage);
});
}
}
else
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
rootPage.NotifyUser("Proximity sensor does not report detection ranges, using it anyway", NotifyType.StatusMessage);
});
}
if (null != foundSensor)
{
sensor = foundSensor;
}
}
else
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
rootPage.NotifyUser("Could not get a proximity sensor from the device id", NotifyType.ErrorMessage);
});
}
}
}
示例12: OnProximitySensorRemoved
/// <summary>
/// Invoked when the device watcher detects that the proximity sensor was removed.
/// </summary>
/// <param name="sender">The device watcher.</param>
/// <param name="device">The device that was removed.</param>
private void OnProximitySensorRemoved(DeviceWatcher sender, DeviceInformationUpdate device)
{
if ((this.proximitySensor != null) && (this.proximitySensor.DeviceId == device.Id))
{
this.proximitySensor.ReadingChanged -= ProximitySensor_ReadingChangedAsync;
this.proximitySensor = null;
SetActive(false);
}
}
示例13: PosDeviceWatcher
/// <summary>
/// Create a PosDeviceWatcher.
/// </summary>
/// <param name="deviceSelector">Device Selector string to use with DeviceWatcher</param>
/// <param name="dispatcher">Associated UI element's Dispatcher so that updates to this.FoundDeviceList are done safely.</param>
public PosDeviceWatcher(string deviceSelector, CoreDispatcher dispatcher)
{
FoundDeviceList = new ObservableCollection<DeviceInformation>();
coreDispatcher = dispatcher;
deviceWatcher = DeviceInformation.CreateWatcher(deviceSelector);
deviceWatcher.Added += DeviceWatcher_Added;
deviceWatcher.Removed += DeviceWatcher_Removed;
deviceWatcher.Updated += DeviceWatcher_Updated;
}
示例14: ExternalDeviceService
public ExternalDeviceService()
{
_deviceWatcher = DeviceInformation.CreateWatcher(DeviceClass.PortableStorageDevice);
_deviceWatcher.Added += DeviceAdded;
_deviceWatcher.Removed += DeviceRemoved;
_deviceWatcher.Start();
}
示例15: NetworkPresenter
public NetworkPresenter()
{
WiFiAdaptersWatcher = DeviceInformation.CreateWatcher(WiFiAdapter.GetDeviceSelector());
WiFiAdaptersWatcher.EnumerationCompleted += AdaptersEnumCompleted;
WiFiAdaptersWatcher.Added += AdaptersAdded;
WiFiAdaptersWatcher.Removed += AdaptersRemoved;
WiFiAdaptersWatcher.Start();
}