DeviceInformation 클래스

정의

디바이스를 나타냅니다. 이 클래스를 사용하면 디바이스 열거 중에 지정된 추가 속성뿐만 아니라 잘 알려진 디바이스 속성에 액세스할 수 있습니다.

public ref class DeviceInformation sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class DeviceInformation final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class DeviceInformation
Public NotInheritable Class DeviceInformation
상속
Object Platform::Object IInspectable DeviceInformation
특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

이 예제에서는 디바이스를 증분식으로 열거하고, 디바이스를 찾을 때마다 목록에 추가하고, 제거 및 업데이트를 처리합니다.

using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Imaging;

using Windows.Devices.Enumeration;
using Windows.Devices.Enumeration.Pnp;


// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Application1
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    /// 
    public sealed partial class BlankPage : Page
    {
        public BlankPage()
        {

            this.InitializeComponent();
        }
        Windows.UI.Core.CoreDispatcher dispatcher;
        public static DeviceWatcher watcher = null;
        public static int count = 0;
        public static DeviceInformation[] interfaces = new DeviceInformation[1000];
        public static bool isEnumerationComplete = false;
        public static string StopStatus = null;

        async void WatchDevices(object sender, RoutedEventArgs eventArgs)
        {
            try
            {
                dispatcher = Window.Current.CoreWindow.Dispatcher;
                watcher = DeviceInformation.CreateWatcher();
                // Add event handlers
                watcher.Added += watcher_Added;
                watcher.Removed += watcher_Removed;
                watcher.Updated += watcher_Updated;
                watcher.EnumerationCompleted += watcher_EnumerationCompleted;
                watcher.Stopped += watcher_Stopped;
                watcher.Start();
                OutputText.Text = "Enumeration started.";

            }
            catch (ArgumentException)
            {
                //The ArgumentException gets thrown by FindAllAsync when the GUID isn't formatted properly
                //The only reason we're catching it here is because the user is allowed to enter GUIDs without validation
                //In normal usage of the API, this exception handling probably wouldn't be necessary when using known-good GUIDs 
                OutputText.Text = "Caught ArgumentException. Failed to create watcher.";
            }
        }

        async void StopWatcher(object sender, RoutedEventArgs eventArgs)
        {
            try
            {
                if (watcher.Status == Windows.Devices.Enumeration.DeviceWatcherStatus.Stopped)
                {
                    StopStatus = "The enumeration is already stopped.";
                }
                else
                {
                    watcher.Stop();
                }
            }
            catch (ArgumentException)
            {
                OutputText.Text = "Caught ArgumentException. Failed to stop watcher.";
            }
        }

        async void watcher_Added(DeviceWatcher sender, DeviceInformation deviceInterface)
        {
            interfaces[count] = deviceInterface;
            count += 1;
            if (isEnumerationComplete)
            {
                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    DisplayDeviceInterfaceArray();
                });
            }
        }

        async void watcher_Updated(DeviceWatcher sender, DeviceInformationUpdate devUpdate)
        {
            int count2 = 0;
            foreach (DeviceInformation deviceInterface in interfaces)
            {
                if (count2 < count)
                {
                    if (interfaces[count2].Id == devUpdate.Id)
                    {
                        //Update the element.
                        interfaces[count2].Update(devUpdate);
                    }

                }
                count2 += 1;
            }
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                OutputText.Text = "Enumeration updated. ";
                DisplayDeviceInterfaceArray();
            });
        }

        async void watcher_Removed(DeviceWatcher sender, DeviceInformationUpdate devUpdate)
        {
            int count2 = 0;
            //Convert interfaces array to a list (IList).
            List<DeviceInformation> interfaceList = new List<DeviceInformation>(interfaces);
            foreach (DeviceInformation deviceInterface in interfaces)
            {
                if (count2 < count)
                {
                    if (interfaces[count2].Id == devUpdate.Id)
                    {
                        //Remove the element.
                        interfaceList.RemoveAt(count2);
                    }

                }
                count2 += 1;
            }
            //Convert the list back to the interfaces array.
            interfaces = interfaceList.ToArray();
            count -= 1;
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                OutputText.Text = "Enumeration device was removed. ";
                DisplayDeviceInterfaceArray();
            });
        }

        async void watcher_EnumerationCompleted(DeviceWatcher sender, object args)
        {
            isEnumerationComplete = true;
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    OutputText.Text = "Enumeration complete. ";
                    DisplayDeviceInterfaceArray();
                });
        }

        async void watcher_Stopped(DeviceWatcher sender, object args)
        {
            if (watcher.Status == Windows.Devices.Enumeration.DeviceWatcherStatus.Aborted)
            {
                StopStatus = "Enumeration stopped unexpectedly. Click Watch to restart enumeration.";
            }
            else if (watcher.Status == Windows.Devices.Enumeration.DeviceWatcherStatus.Stopped)
            {
                StopStatus = "You requested to stop the enumeration. Click Watch to restart enumeration.";
            }
        }

        async void DisplayDeviceInterfaceArray()
        {
            DeviceInterfacesOutputList.Items.Clear();
            int count2 = 0;
            foreach (DeviceInformation deviceInterface in interfaces)
            {
                if (count2 < count)
                {
                    DisplayDeviceInterface(deviceInterface);
                }
                count2 += 1;
            }
        }

        async void DisplayDeviceInterface(DeviceInformation deviceInterface)
        {
            var id = "Id:" + deviceInterface.Id;
            var name = deviceInterface.Name;
            var isEnabled = "IsEnabled:" + deviceInterface.IsEnabled;


            var item = id + " is \n" + name + " and \n" + isEnabled;

            DeviceInterfacesOutputList.Items.Add(item);
        }
    }
}

설명

DeviceInformation 개체는 ID(DeviceInformation.Id), 종류(DeviceInformation.Kind) 및 속성 모음(DeviceInformation.Properties)으로 구성됩니다. DeviceInformation 개체의 다른 속성은 모두 Properties 속성 모음에서 파생됩니다. 예를 들어 NameSystem.ItemNameDisplay에서 파생됩니다.

FindAllAsync를 성공적으로 완료하면 DeviceInformation 개체가 포함된 DeviceInformationCollection이 생성됩니다.

CreateWatcher 호출이 성공하면 DeviceInformation 개체가 발견된 각 디바이스에 대해 추가된 이벤트에 전달됩니다.

Name 속성은 지역화 또는 이름을 할당하는 사용자로 인해 이름이 변경될 수 있으므로 디바이스를 찾는 용도가 아니라 표시 목적으로만 사용해야 합니다.

CreateFromIdAsync 는 성공하면 DeviceInformation 개체를 만듭니다.

DeviceInformation 클래스는 디바이스 정보를 제공하지만, 더 구체적으로는 디바이스가 노출하는 기능을 나타내는 인터페이스인 디바이스 인터페이스의 속성을 제공합니다. 다기능 디바이스에는 둘 이상의 디바이스 인터페이스가 있을 수 있습니다. 사용자가 디바이스로 보는 물리적 개체를 디바이스 컨테이너라고 하며 ManufacturerModelID와 같은 속성을 가집니다. 디바이스 열거 및 속성 복구에 대한 자세한 내용은 디바이스 열거를 참조하세요.

속성

EnclosureLocation

인클로저에 있는 디바이스의 물리적 위치입니다. 예를 들어 랩톱 내에서 웹캠의 위치를 설명할 수 있습니다.

Id

디바이스의 ID를 나타내는 문자열입니다.

IsDefault

이 디바이스가 클래스의 기본 디바이스인지 여부를 나타냅니다.

IsEnabled

이 디바이스를 사용할 수 있는지 여부를 나타냅니다.

Kind

이 개체가 나타내는 DeviceInformation 의 형식을 가져옵니다.

Name

서버의 이름입니다. 이 이름은 앱에 가장 적합한 언어입니다.

Pairing

이 디바이스가 페어링할 기능에 대한 정보를 가져옵니다.

Properties

디바이스 열거 중에 지정할 수 있는 추가 속성뿐만 아니라 잘 알려진 값을 포함하는 속성 저장소입니다.

메서드

CreateFromIdAsync(String)

DeviceInformation ID에서 DeviceInformation 개체를 만듭니다.

CreateFromIdAsync(String, IIterable<String>)

DeviceInformation ID 및 추가 속성 목록에서 DeviceInformation 개체를 만듭니다.

CreateFromIdAsync(String, IIterable<String>, DeviceInformationKind)

DeviceInformation ID, 추가 속성 목록 및 DeviceInformationKind 매개 변수에서 DeviceInformation 개체를 만듭니다.

CreateFromIdAsync(String, IIterable<String>, DeviceInformationKind, IDeviceEnumerationSettings)

디바이스를 나타냅니다. 이 클래스를 사용하면 디바이스 열거 중에 지정된 추가 속성뿐만 아니라 잘 알려진 디바이스 속성에 액세스할 수 있습니다.

CreateWatcher()

모든 디바이스에 대한 DeviceWatcher 를 만듭니다.

CreateWatcher(DeviceClass)

지정된 DeviceClass와 일치하는 디바이스에 대한 DeviceWatcher를 만듭니다.

CreateWatcher(String)

지정된 AQS(고급 쿼리 구문) 문자열과 일치하는 디바이스에 대한 DeviceWatcher 를 만듭니다.

CreateWatcher(String, IIterable<String>)

지정된 AQS(고급 쿼리 구문) 문자열 및 지정된 속성 컬렉션과 일치하는 디바이스에 대한 DeviceWatcher 를 만듭니다.

CreateWatcher(String, IIterable<String>, DeviceInformationKind)

지정된 AQS(고급 쿼리 구문) 문자열, 지정된 속성 컬렉션 및 디바이스 종류와 일치하는 디바이스에 대한 DeviceWatcher 를 만듭니다.

CreateWatcher(String, IIterable<String>, DeviceInformationKind, IDeviceEnumerationSettings)

디바이스를 나타냅니다. 이 클래스를 사용하면 디바이스 열거 중에 지정된 추가 속성뿐만 아니라 잘 알려진 디바이스 속성에 액세스할 수 있습니다.

FindAllAsync()

모든 DeviceInformation 개체를 열거합니다.

FindAllAsync(DeviceClass)

지정된 클래스의 DeviceInformation 개체를 열거합니다.

FindAllAsync(String)

지정된 AQS(고급 쿼리 구문) 디바이스 인터페이스 선택기 문자열과 일치하는 DeviceInformation 개체를 열거합니다.

FindAllAsync(String, IIterable<String>)

지정된 AQS(고급 쿼리 구문) 디바이스 인터페이스 선택기 문자열과 일치하고 지정된 속성 컬렉션을 포함하는 DeviceInformation 개체를 열거합니다.

FindAllAsync(String, IIterable<String>, DeviceInformationKind)

지정된 AQS(고급 쿼리 구문) 디바이스 인터페이스 선택기 문자열, 디바이스 종류 및 지정된 속성 컬렉션을 포함하는 DeviceInformation 개체를 열거합니다.

FindAllAsync(String, IIterable<String>, DeviceInformationKind, IDeviceEnumerationSettings)

디바이스를 나타냅니다. 이 클래스를 사용하면 디바이스 열거 중에 지정된 추가 속성뿐만 아니라 잘 알려진 디바이스 속성에 액세스할 수 있습니다.

GetAqsFilterFromDeviceClass(DeviceClass)

디바이스 유형의 하위 집합을 열거하는 데 사용할 필터를 만듭니다.

GetGlyphThumbnailAsync()

디바이스의 문자 모양을 가져옵니다.

GetThumbnailAsync()

디바이스에 대한 썸네일 이미지를 반환합니다.

Update(DeviceInformationUpdate)

기존 DeviceInformation 개체의 속성을 업데이트.

적용 대상

추가 정보