• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Enumeration.DeviceInformation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Windows.Devices.Enumeration.DeviceInformation的典型用法代码示例。如果您正苦于以下问题:C# DeviceInformation类的具体用法?C# DeviceInformation怎么用?C# DeviceInformation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DeviceInformation类属于Windows.Devices.Enumeration命名空间,在下文中一共展示了DeviceInformation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: 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


示例2: GetDeviceObject

        // Using device type decideds which device object to initilise, this allows for dynamic object creation.
        public static DeviceBase GetDeviceObject(DeviceInformation deviceInfo, DeviceType type)
        {
            DeviceBase device = null;
            // Main switch statement to handle the creation of the device objects.
            switch (type)
            {
                case DeviceType.GenericAccess:
                    device = new GenericAccessDevice();
                    break;
                case DeviceType.HeartRate:
                    device = new HeartRateMonitorDevice();
                    break;
            }

            if (device == null)
            {
                // Display error if device does not have a value and return null.
                MessageHelper.DisplayBasicMessage(StringResources.InitialisationError);
                return device;
            }

            device.Initialise(deviceInfo.Id);

            return device;
        }
开发者ID:EarnieGC,项目名称:AppAcceleratorKit,代码行数:26,代码来源:DeviceHelper.cs


示例3: GetHrAndBatteryDevice

        private async Task<bool> GetHrAndBatteryDevice()
        {
            StatusInformation = "Start search for devices, HR";
            var devices = await DeviceInformation.FindAllAsync(
                GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.HeartRate));
            if (null == devices || devices.Count <= 0) return true;
            foreach (var device in devices.Where(device => device.Name == "Polar H7 498C1817"))
            {
                _devicePolarHr = device;
                StatusInformation2 = "Found hr device";
                break;
            }

            StatusInformation = "Start search for devices, Battery";
            devices = await DeviceInformation.FindAllAsync(
                GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.Battery));
            if (null == devices || devices.Count <= 0) return true;
            foreach (var device in devices.Where(device => device.Name == "Polar H7 498C1817"))
            {
                _devicePolarBattery = device;
                StatusInformation2 = "Found battery device";
                break;
            }
            StatusInformation = $"Found HR [{(_devicePolarHr != null)}] Battery [{(_devicePolarBattery != null)}]";
            return (_devicePolarHr != null && _devicePolarBattery != null);
        }
开发者ID:modulexcite,项目名称:events,代码行数:26,代码来源:MainPage.xaml.cs


示例4: ProjectAsync

        public async Task<int> ProjectAsync(Type viewType, DeviceInformation device = null)
        {
            int mainViewId = ApplicationView.GetForCurrentView().Id;
            int? secondViewId = null;

            var view = CoreApplication.CreateNewView();
            await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                secondViewId = ApplicationView.GetForCurrentView().Id;
                var rootFrame = new Frame();
                rootFrame.Navigate(viewType, null);
                Window.Current.Content = rootFrame;
                Window.Current.Activate();
            });

            if (secondViewId.HasValue)
            {
                if(device == null)
                    await ProjectionManager.StartProjectingAsync(secondViewId.Value, mainViewId);
                else
                    await ProjectionManager.StartProjectingAsync(secondViewId.Value, mainViewId, device);
            }

            return mainViewId;
        }
开发者ID:dimkname,项目名称:UAP-Samples,代码行数:25,代码来源:ProjectionService.cs


示例5: ConnectToDevice

 public async Task ConnectToDevice(DeviceInformation device)
 {
     this.State = ConnectionState.Connecting;
     try
     {
         serialConnection = await SerialDevice.FromIdAsync(device.Id);
         if (serialConnection != null)
         {
             serialConnection.BaudRate = 115200;
             serialConnection.DataBits = 8;
             serialConnection.Parity = SerialParity.None;
             writer = new DataWriter(serialConnection.OutputStream);
             reader = new DataReader(serialConnection.InputStream);
             Task listen = ListenForMessagesAsync();
             this.State = ConnectionState.Connected;
         }
         else {
             Debugger.ReportToDebugger(this, "Unable to create service.\nMake sure that the 'serialcommunication' capability is declared with a function of type 'name:serialPort' in Package.appxmanifest.", Debugger.Device.Pc);
             this.State = ConnectionState.Failure;
         }
     }
     catch (TaskCanceledException ex)
     {
         this.State = ConnectionState.Failure;
         Debugger.ReportToDebugger(this, ex.Message, Debugger.Device.Pc);
     }
     catch (Exception ex)
     {
         this.State = ConnectionState.Failure;
         Debugger.ReportToDebugger(this, ex.Message, Debugger.Device.Pc);
     }
 }
开发者ID:AliceTheCat,项目名称:LightTable,代码行数:32,代码来源:SerialConnection.cs


示例6: UsbConnection

 public UsbConnection(DeviceInformation deviceInfo)
 {
     UpdateRate = 1000;
     DevicePath = deviceInfo.Id;
     SerialNumber = DevicePath.Split('#')[2];
     Name = deviceInfo.Name;
 }
开发者ID:treehopper-electronics,项目名称:treehopper-sdk,代码行数:7,代码来源:UsbConnection.cs


示例7: 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


示例8: HidGamepad

        private HidGamepad(DeviceInformation deviceInformation, HidDevice device)
        {
            _deviceInformation = deviceInformation;

            _device = device;
            _device.InputReportReceived += HandleInputReportRecieved;
        }
开发者ID:bricelam,项目名称:HidGamepad,代码行数:7,代码来源:HidGamepad.cs


示例9: DeviceAdded

 private void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
 {
     if (ExternalDeviceAdded != null)
     {
         ExternalDeviceAdded(this, args.Id);
     }
 }
开发者ID:kusl,项目名称:vlcwinrt,代码行数:7,代码来源:ExternalDeviceService.cs


示例10: 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


示例11: GetDeviceService

        /// <summary>
        /// Finds the GattDeviceService for a specified device by serviceUuid
        /// IMPORTANT: Has to be called from UI thread the first time the app uses the device to be able to ask the user for permission to use it.
        /// </summary>
        /// <returns>Returns the gatt device service of the first device that supports it. Returns null if access is denied.</returns>
        /// <exception cref="DeviceNotFoundException">Thrown if there isn't a device which provides the service Uuid.</exception>
        public async static Task<GattDeviceService> GetDeviceService(DeviceInformation device, string serviceUuid)
        {
            Validator.RequiresNotNullOrEmpty(serviceUuid, "serviceUuid");

            Validator.RequiresNotNull(device, "device");

            return await GattDeviceService.FromIdAsync(device.Id);
        }
开发者ID:ChrisMBenson,项目名称:azure-stream-analytics,代码行数:14,代码来源:GattUtils.cs


示例12: 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


示例13: 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


示例14: CameraSelectionList_SelectionChanged

 private async void CameraSelectionList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     string selectedCameraItem = e.AddedItems.FirstOrDefault().ToString();
     foreach (DeviceInformation item in _allVideoDevices)
     {
         if (string.Equals(item.Name, selectedCameraItem))
         {
             _desiredDevice = item;
             await StartDeviceAsync();
         }
     }
 }
开发者ID:CHS982,项目名称:Coding4Fun,代码行数:12,代码来源:MainPage.xaml.cs


示例15: StartProjecting

        private async void StartProjecting(DeviceInformation selectedDisplay)
        {
            // If projection is already in progress, then it could be shown on the monitor again
            // Otherwise, we need to create a new view to show the presentation
            if (rootPage.ProjectionViewPageControl == null)
            {
                // First, create a new, blank view
                var thisDispatcher = Window.Current.Dispatcher;
                await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // ViewLifetimeControl is a wrapper to make sure the view is closed only
                    // when the app is done with it
                    rootPage.ProjectionViewPageControl = ViewLifetimeControl.CreateForCurrentView();

                    // Assemble some data necessary for the new page
                    var initData = new ProjectionViewPageInitializationData();
                    initData.MainDispatcher = thisDispatcher;
                    initData.ProjectionViewPageControl = rootPage.ProjectionViewPageControl;
                    initData.MainViewId = thisViewId;

                    // Display the page in the view. Note that the view will not become visible
                    // until "StartProjectingAsync" is called
                    var rootFrame = new Frame();
                    rootFrame.Navigate(typeof(ProjectionViewPage), initData);
                    Window.Current.Content = rootFrame;

                    // The call to Window.Current.Activate is required starting in Windos 10.
                    // Without it, the view will never appear.
                    Window.Current.Activate();
                });
            }

            try
            {
                // Start/StopViewInUse are used to signal that the app is interacting with the
                // view, so it shouldn't be closed yet, even if the user loses access to it
                rootPage.ProjectionViewPageControl.StartViewInUse();

                // Show the view on a second display that was selected by the user
                rootPage.NotifyUser("Starting projection on " + selectedDisplay.Name, NotifyType.StatusMessage);
                await ProjectionManager.StartProjectingAsync(rootPage.ProjectionViewPageControl.Id, thisViewId, selectedDisplay);

                rootPage.NotifyUser("Projection started with success on " + selectedDisplay.Name, NotifyType.StatusMessage);
                rootPage.ProjectionViewPageControl.StopViewInUse();
            }
            catch (InvalidOperationException)
            {
                rootPage.NotifyUser("Start projection failed", NotifyType.ErrorMessage);
            }
        }
开发者ID:C-C-D-I,项目名称:Windows-universal-samples,代码行数:50,代码来源:Scenario3.xaml.cs


示例16: UwpHidDeviceInformation

        public UwpHidDeviceInformation([NotNull] UwpHidDeviceFactory factory, [NotNull] DeviceInformation deviceInformation)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            if (deviceInformation == null)
            {
                throw new ArgumentNullException(nameof(deviceInformation));
            }

            this.factory = factory;
            this.deviceInformation = deviceInformation;
        }
开发者ID:vbfox,项目名称:U2FExperiments,代码行数:14,代码来源:UwpHidDeviceInformation.cs


示例17: InitCaptureSettings

        private MediaCaptureInitializationSettings InitCaptureSettings(DeviceInformation device)
        {
            MediaCaptureInitializationSettings captureInitSettings = new MediaCaptureInitializationSettings();
            captureInitSettings.AudioDeviceId = "";
            captureInitSettings.VideoDeviceId = device.Id;

            captureInitSettings.StreamingCaptureMode = settings.IsVolumeOn
                ? StreamingCaptureMode.AudioAndVideo
                : StreamingCaptureMode.Video;

            captureInitSettings.PhotoCaptureSource = PhotoCaptureSource.VideoPreview;

            return captureInitSettings;
        }
开发者ID:Ontropix,项目名称:slow-camera,代码行数:14,代码来源:VideoRecorderViewModel.cs


示例18: 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


示例19: Picker_DisconnectButtonClicked

        private async void Picker_DisconnectButtonClicked(DialDevicePicker sender, DialDisconnectButtonClickedEventArgs args)
        {
            // casting 必須在 UI Thread 下執行
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                try
                {                    
                    // 取得被選擇的 dial device
                    DialDevice selectedDialDevice = await DialDevice.FromIdAsync(args.Device.Id);
                    // 更新 picker status
                    picker.SetDisplayStatus(selectedDialDevice, DialDeviceDisplayStatus.Connecting);
                    // 取得 dial app 
                    DialApp app = selectedDialDevice.GetDialApp(txtAppName.Text);
                  
                    // 請求斷綫
                    DialAppStopResult result = await app.StopAsync();

                    if (result == DialAppStopResult.Stopped)
                    {
                        picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Disconnected);
                        activeDialDevice = null;
                        activeDeviceInformation = null;
                        picker.Hide();
                        tblMsg.Text += "Stoped, success";
                    }
                    else
                    {
                        if (result == DialAppStopResult.StopFailed || result == DialAppStopResult.NetworkFailure)
                        {
                            // 如果失敗的話要記得多 retry 的機制
                            picker.SetDisplayStatus(args.Device, DialDeviceDisplayStatus.Error);
                            tblMsg.Text += $"Stoped, {result}";
                        }
                        else
                        {
                            // 如果設備沒有支援 Stop 機制,則直接清楚連綫就好
                            activeDialDevice = null;
                            activeDeviceInformation = null;
                            tblMsg.Text += "the device does not support Stop";
                        }
                    }
                }
                catch (Exception ex)
                {
                    tblMsg.Text += ex.Message;
                }
            });
        }
开发者ID:poumason,项目名称:DotblogsSampleCode,代码行数:48,代码来源:DialSenderPage.xaml.cs


示例20: Initialize

        /// <summary>
        /// Retrieves the sensors GATT device service from a specified DeviceInformation and saves it for further usage.
        /// IMPORTANT: Has to be called from UI thread the first time the app uses the device to be able to ask the user for permission to use it
        /// </summary>
        /// <returns>Indicates if the gatt service could be retrieved and set successfully</returns>
        public async Task<bool> Initialize(DeviceInformation deviceInfo)
        {
            Validator.RequiresNotNull(deviceInfo);
            if (!deviceInfo.Id.Contains(SensorServiceUuid))
                throw new ArgumentException("Wrong DeviceInformation passed. You need to get the right DeviceInformation via SPECIFICSENSORCLASS.SensorServiceUuid.");

            if (this.deviceService != null)
            {
                Clean();
            }

            this.deviceService = await GattDeviceService.FromIdAsync(deviceInfo.Id);
            if (this.deviceService == null)
                return false;
            return true;
        }
开发者ID:ChrisMBenson,项目名称:azure-stream-analytics,代码行数:21,代码来源:SensorBase.cs



注:本文中的Windows.Devices.Enumeration.DeviceInformation类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Enumeration.DeviceWatcher类代码示例发布时间:2022-05-26
下一篇:
C# Dom.XmlDocument类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap