관련 PnP 개체를 검색하는 방법(HTML)

[ 이 문서는 Windows 런타임 앱을 작성하는 Windows에서 8.x 및 Windows Phone 8.x 개발자를 대상으로 합니다. Windows 10용으로 개발하는 경우에는 최신 설명서를 참조하세요.]

이 항목에서는 서로 관련된 PnP(플러그 앤 플레이) 개체를 찾는 방법을 설명합니다. 예를 들어 장치 정보 개체와 관련된 장치 컨테이너 개체를 검색할 수 있습니다. 장치 컨테이너는 사용자에게 표시되는 실제 장치를 나타냅니다. 장치 컨테이너를 사용하면 기능 인터페이스 중 하나만이 아닌 전체 장치 하드웨어 제품과 관련된 정보에 액세스할 수 있습니다. 장치 컨테이너 속성의 예로는 제조업체 또는 모델 이름이 있습니다.

PnP 개체 관계 이해

이 항목의 표에는 여러 PnpObjectType 개체 및 개체를 탐색할 때 사용해야 하는 속성 간의 관계가 나와 있습니다. DeviceInformation 개체는 PnpObjectTypedeviceInterfacePnpObject와 동일합니다.

다대일 관계

이 섹션의 표에서는 다른 개체와 다대일 관계인 개체를 탐색하는 방법을 보여 줍니다. 예를 들어 하나 이상의 장치 인터페이스(DeviceInformation 개체로 표시)가 동일한 장치 컨테이너에 속할 수 있습니다. 첫 번째 두 열의 머리글에는 시작할 때 사용한 PnP(플러그 앤 플레이) 개체의 유형이 포함됩니다. 세 번째 열의 항목에는 찾을 관련 PnP 개체가 포함됩니다. 표의 셀은 채워진 경우 관련 PnP 개체를 쿼리하는 데 사용할 수 있는 속성을 포함합니다.

열 머리글에 나열된 개체에서 세 번째 열에 나열된 개체로 이동하려면 다음을 실행하세요.

  1. 시작할 때 사용한 개체에 해당하는 머리글과 동일한 열에 있고 찾을 관련 개체와 동일한 행에 있는 속성을 찾습니다.
  2. 관련 PnP 개체를 검색하는 방법에 설명된 단계에 따라 속성을 검색합니다.
  3. 검색된 값을 PnpObject.createFromIdAsync 호출에서 id 매개 변수로 사용하여 관련 유형의 개체를 만듭니다.
장치 인터페이스( DeviceInformation) 장치 관련 개체
System.Devices.ContainerId System.Devices.ContainerId deviceContainer
System.Devices.DeviceInstancePath device
System.Devices.DeviceInterfaceClassGuid deviceInterfaceClass

 

일대다 관계

이 섹션의 표에서는 다른 개체와 일대다 관계인 개체를 탐색하는 방법을 보여 줍니다. 시작할 때 사용한 개체(맨 위 행에 있음)에서 오른쪽에 나열된 관련 개체로 이동하려면 다음을 실행하세요.

  1. 시작할 때 사용한 개체의 머리글과 동일한 열에 있고 찾을 관련 개체와 동일한 행에 있는 속성을 찾습니다.

  2. 시작할 때 사용한 개체의 ID(제목 행에 있음)와 표에서 식별한 속성을 사용하여 "<property>:=<id>" 형식의 AQS 문자열을 구성합니다.

    예를 들어 ID가 "{1451362b-4b9c-4780-a4bf-6c001619646c}"인 컨테이너에 있는 모든 인터페이스를 찾으려는 경우 AQS 문자열은 "System.Devices.ContainerId:={1451362b-4b9c-4780-a4bf-6c001619646c}"가 됩니다.

  3. AQS 문자열을 Windows.Devices.Enumeration.Pnp.PnpObject.findAllAsync 호출에 대한 매개 변수로 사용하여 관련 유형의 개체를 찾습니다.

    참고  GUID가 포함된 속성으로 작업할 경우 AQS 문자열을 구성할 때 GUID 값은 괄호로 묶어야 합니다.

     

deviceContainer 장치 deviceInterfaceClass 관련 개체
System.Devices.ContainerId System.Devices.DeviceInstancePath System.Devices.DeviceInterfaceClassGuid deviceInterface
System.Devices.ContainerId System.Devices.DeviceInstancePath device

 

예제

DeviceInformation ID에서 컨테이너 가져오기

장치 인터페이스가 속성 컨테이너에 대한 속성을 가져와야 할 수 있습니다. 예를 들어 선택한 장치의 장치 ID가 있지만 모델 이름을 가져와야 하는 경우 System.Devices.ModelName이 컨테이너 속성이고 장치 인터페이스 속성이 아니므로 컨테이너 개체를 만들어야 합니다.

다음 코드에서는 장치 ID로 시작하는 컨테이너 속성을 가져오는 방법을 보여 줍니다.


// GetModelNameFromDeviceID gets the ModelName property from the
// device interface's container.
// The parameter devID is assumed to be a valid device interface ID.
string GetModelNameFromDeviceID (devID)
{
// First create a DeviceInformation object from the ID.
// Create the argument that specifies that additional properties
// returned should include the System.Devices.ContainerId property.
   var propertiesToGet = new Array();
   propertiesToGet.push("System.Devices.ContainerId");


// Create a DeviceInformation object from the ID.
   var Enum = Windows.Devices.Enumeration;
   var DevInfo = Enum.DeviceInformation;
   var contID;   // The container ID
   DevInfo.createFromIdAsync(devID, propertiesToGet).then(
       function(devInf) {             
            var prop = devInf.properties;
            if (prop) {
                contID = prop.lookup("System.Devices.ContainerID");               
            }
       },
       function (e) {
           displayError("Failed to create DeviceInformation: " + e.message);
       });

// Use the container ID to create a PnPObject representing the container,
// and specify that the created object should have a 
// System.Devices.ModelId property.


// Create the argument that specifies that the additional properties to
// return should include the System.Devices.ContainerId property.
   var containerPropertiesToGet = new Array();
   containerPropertiesToGet.push("System.Devices.ModelId");

   var modelID;


var Pnp = Enum.Pnp;
var pnpObjType = Pnp.PnpObjectType;
var deviceType = pnpObjType.device;

// NOTE: We need to add extra braces "{}" back to the container ID before
// passing it to createIdAsync (a pair of braces is lost in the implicit
// conversion from GUID to string).
   contID = "{" + contID + "}";

// Create the container from its ID.
   Pnp.createFromIdAsync(deviceType, contID, containerPropertiesToGet).then(
       function(contInf) {
           var prop = contInf.properties;
           if (prop) {
               modelID = prop.lookup("System.Devices.ModelID");
           });
   return modelID;
}

참고  

앞에 나온 예제에서처럼 속성 조회의 GUID 결과를 GUID가 문자열 인수로 사용되는 함수에 전달하는 경우 GUID 인수 주위에 추가 중괄호 "{}"를 추가한 다음 함수에 전달해야 합니다. 이는 속성 조회의 결과가 문자열이 아니라 variant 유형이므로 문자열을 인수로 사용하는 함수에 인수를 전달할 때 중괄호 쌍이 암시적 변환 시 손실됩니다.

 

특정 장치 컨테이너에서 모든 DeviceInformation 개체 가져오기

이 예제에서는 AQS 쿼리를 작성하고 이 쿼리를 findAllAsync에 전달하여 지정된 장치 컨테이너에서 .DeviceInformation 개체를 찾는 방법을 보여 줍니다.

function findInterfacesInContainer(containerId) {

    var Enum = Windows.Devices.Enumeration;
    var aqsString = "System.Devices.ContainerId:=\"" + containerId + "\"";

    Enum.DeviceInformation.findAllAsync(aqsString, null).then(
            successCallback, 
            errorCallback);
}

// Handles successful completion of the findAllAsync method.
function successCallback(deviceInformationCollection) {
    // Add your code here for processing the enumerated device collection.
}

// Handles an error completion of the findAllAsync method.
function errorCallback(e) {
    // Add your error-handling code here.
}

관련 항목

장치 또는 PnP 개체의 추가 속성을 검색하는 방법

AQS 쿼리