本文整理汇总了C#中Windows.Devices.Enumeration.DeviceWatcher类的典型用法代码示例。如果您正苦于以下问题:C# DeviceWatcher类的具体用法?C# DeviceWatcher怎么用?C# DeviceWatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeviceWatcher类属于Windows.Devices.Enumeration命名空间,在下文中一共展示了DeviceWatcher类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: OnDeviceRemoved
private void OnDeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate deviceInformationUpdate)
{
if (Disconnected != null)
{
Disconnected();
}
}
开发者ID:gazzyt,项目名称:GaryScope,代码行数:7,代码来源:UsbScopeDevice.cs
示例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);
});
}
}
开发者ID:t-angma,项目名称:Windows-universal-samples,代码行数:32,代码来源:scenario2_polling.xaml.cs
示例3: HandleDeviceRemoved
private static void HandleDeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
{
var gamepad = _gamepads[args.Id];
_gamepads.Remove(args.Id);
GamepadRemoved?.Invoke(sender, gamepad);
}
开发者ID:bricelam,项目名称:HidGamepad,代码行数:7,代码来源:HidGamepad.cs
示例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;
}
}
}
}
开发者ID:igrali,项目名称:ContextualTriggers,代码行数:36,代码来源:ProximityStateTrigger.cs
示例5: DeviceRemoved
private void DeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
{
if (ExternalDeviceRemoved != null)
{
ExternalDeviceRemoved(this, args.Id);
}
}
开发者ID:kusl,项目名称:vlcwinrt,代码行数:7,代码来源:ExternalDeviceService.cs
示例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);
}
开发者ID:bricelam,项目名称:HidGamepad,代码行数:8,代码来源:HidGamepad.cs
示例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();
}
开发者ID:gazzyt,项目名称:GaryScope,代码行数:8,代码来源:UsbScopeDevice.cs
示例8: DevicesRemoved
private async void DevicesRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
{
//Debug.WriteLine("Removed USB device: " + args.Id);
await dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
{
UpdateDevices();
});
}
开发者ID:SteamMaker,项目名称:haxc,代码行数:9,代码来源:ConnectedDevicePresenter.cs
示例9: DevicesEnumCompleted
private async void DevicesEnumCompleted(DeviceWatcher sender, object args)
{
//Debug.WriteLine("USB Devices Enumeration Completed");
await dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
{
UpdateDevices();
});
}
开发者ID:SteamMaker,项目名称:haxc,代码行数:9,代码来源:ConnectedDevicePresenter.cs
示例10: DeviceWatcher_Added
private async void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
{
await coreDispatcher.RunAsync(
CoreDispatcherPriority.Normal,
() =>
{
FoundDeviceList.Add(args);
});
}
开发者ID:huoxudong125,项目名称:Windows-universal-samples,代码行数:9,代码来源:PosDeviceWatcher.cs
示例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);
});
}
}
}
开发者ID:C-C-D-I,项目名称:Windows-universal-samples,代码行数:62,代码来源:Scenario1_DataEvents.xaml.cs
示例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);
}
}
开发者ID:igrali,项目名称:ContextualTriggers,代码行数:15,代码来源:ProximityStateTrigger.cs
示例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;
}
开发者ID:huoxudong125,项目名称:Windows-universal-samples,代码行数:15,代码来源:PosDeviceWatcher.cs
示例14: MidiDeviceWatcher
public MidiDeviceWatcher(DeviceWatcher watcher)
{
_watcher = watcher;
// wire up events
_watcher.Added += Watcher_Added;
_watcher.Removed += Watcher_Removed;
_watcher.Updated += Watcher_Updated;
_watcher.EnumerationCompleted += Watcher_EnumerationCompleted;
}
开发者ID:Psychlist1972,项目名称:Windows-10-PowerShell-MIDI,代码行数:11,代码来源:MidiDeviceWatcher.cs
示例15: MidiDeviceWatcher
/// <summary>
/// Constructor: Initialize and hook up Device Watcher events
/// </summary>
/// <param name="midiSelectorString">MIDI Device Selector</param>
/// <param name="dispatcher">CoreDispatcher instance, to update UI thread</param>
/// <param name="portListBox">The UI element to update with list of devices</param>
internal MidiDeviceWatcher(string midiSelectorString, CoreDispatcher dispatcher, ListBox portListBox)
{
this.deviceWatcher = DeviceInformation.CreateWatcher(midiSelectorString);
this.portList = portListBox;
this.midiSelector = midiSelectorString;
this.coreDispatcher = dispatcher;
this.deviceWatcher.Added += DeviceWatcher_Added;
this.deviceWatcher.Removed += DeviceWatcher_Removed;
this.deviceWatcher.Updated += DeviceWatcher_Updated;
this.deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
}
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:18,代码来源:MidiDeviceWatcher.cs
示例16: 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)
{
sensor = ProximitySensor.FromId(device.Id);
if (null == sensor)
{
// failed to find the sensor corresponding to the id
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
rootPage.NotifyUser("Could not get a proximity sensor from the device id", NotifyType.ErrorMessage);
});
}
}
}
开发者ID:C-C-D-I,项目名称:Windows-universal-samples,代码行数:20,代码来源:Scenario4_BackgroundProximitySensor.xaml.cs
示例17: DeviceWatcher_Removed
private async void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate args)
{
await coreDispatcher.RunAsync(
CoreDispatcherPriority.Normal,
() =>
{
for (int index = 0; index < FoundDeviceList.Count; ++index)
{
if (FoundDeviceList[index].Id == args.Id)
{
FoundDeviceList.RemoveAt(index);
break;
}
}
});
}
开发者ID:huoxudong125,项目名称:Windows-universal-samples,代码行数:16,代码来源:PosDeviceWatcher.cs
示例18: ExternalDeviceService
public ExternalDeviceService()
{
_deviceWatcher = DeviceInformation.CreateWatcher(DeviceClass.PortableStorageDevice);
_deviceWatcher.Added += DeviceAdded;
_deviceWatcher.Removed += DeviceRemoved;
_deviceWatcher.Start();
}
开发者ID:robUx4,项目名称:vlc-winrt,代码行数:7,代码来源:ExternalDeviceService.cs
示例19: NetworkPresenter
public NetworkPresenter()
{
WiFiAdaptersWatcher = DeviceInformation.CreateWatcher(WiFiAdapter.GetDeviceSelector());
WiFiAdaptersWatcher.EnumerationCompleted += AdaptersEnumCompleted;
WiFiAdaptersWatcher.Added += AdaptersAdded;
WiFiAdaptersWatcher.Removed += AdaptersRemoved;
WiFiAdaptersWatcher.Start();
}
开发者ID:MicrosoftEdge,项目名称:WebOnPi,代码行数:8,代码来源:NetworkPresenter.cs
示例20: Scenario4_BackgroundProximitySensor
public Scenario4_BackgroundProximitySensor()
{
this.InitializeComponent();
watcher = DeviceInformation.CreateWatcher(ProximitySensor.GetDeviceSelector());
watcher.Added += OnProximitySensorAdded;
watcher.Start();
}
开发者ID:C-C-D-I,项目名称:Windows-universal-samples,代码行数:8,代码来源:Scenario4_BackgroundProximitySensor.xaml.cs
注:本文中的Windows.Devices.Enumeration.DeviceWatcher类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论