你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

DeviceManagementClient.GetDeviceClasses(String, RequestContext) 方法

定义

根据设备更新 PnP 接口中报告的模型 ID 和兼容性属性,获取所有设备类的列表, (设备组与相同更新兼容的设备,这些属性适用于IoT 中心设备更新IoT 中心) 。

public virtual Azure.Pageable<BinaryData> GetDeviceClasses (string filter = default, Azure.RequestContext context = default);
abstract member GetDeviceClasses : string * Azure.RequestContext -> Azure.Pageable<BinaryData>
override this.GetDeviceClasses : string * Azure.RequestContext -> Azure.Pageable<BinaryData>
Public Overridable Function GetDeviceClasses (Optional filter As String = Nothing, Optional context As RequestContext = Nothing) As Pageable(Of BinaryData)

参数

filter
String

限制返回的设备类集。 可以根据易记名称进行筛选。

context
RequestContext

请求上下文,可以基于每个调用替代客户端管道的默认行为。

返回

Pageable<T>包含对象列表的服务中的 BinaryData 。 集合中每个项的正文架构的详细信息,请参阅下面的“备注”部分。

例外

服务返回了非成功状态代码。

示例

此示例演示如何调用 GetDeviceClasses 并分析结果。

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);

foreach (var data in client.GetDeviceClasses())
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("deviceClassId").ToString());
    Console.WriteLine(result.GetProperty("deviceClassProperties").GetProperty("compatProperties").GetProperty("<test>").ToString());
}

此示例演示如何使用所有参数调用 GetDeviceClasses,以及如何分析结果。

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);

foreach (var data in client.GetDeviceClasses("<filter>"))
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("deviceClassId").ToString());
    Console.WriteLine(result.GetProperty("friendlyName").ToString());
    Console.WriteLine(result.GetProperty("deviceClassProperties").GetProperty("contractModel").GetProperty("id").ToString());
    Console.WriteLine(result.GetProperty("deviceClassProperties").GetProperty("contractModel").GetProperty("name").ToString());
    Console.WriteLine(result.GetProperty("deviceClassProperties").GetProperty("compatProperties").GetProperty("<test>").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("updateId").GetProperty("provider").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("updateId").GetProperty("name").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("updateId").GetProperty("version").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("description").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("friendlyName").ToString());
}

注解

下面是可分页响应中一项的 JSON 架构。

响应正文:

DeviceClassesListValue架构:

{
              deviceClassId: string, # Required. The device class identifier. This is generated from the model Id and the compat properties reported by the device update agent in the Device Update PnP interface in IoT Hub. It is a hex-encoded SHA1 hash.
              friendlyName: string, # Optional. The device class friendly name. This can be updated by callers after the device class has been automatically created.
              deviceClassProperties: {
                contractModel: {
                  id: string, # Required. The Device Update agent contract model Id of the device class. This is also used to calculate the device class Id.
                  name: string, # Required. The Device Update agent contract model name of the device class. Intended to be a more readable form of the contract model Id.
                }, # Optional. The Device Update agent contract model.
                compatProperties: Dictionary<string, string>, # Required. The compat properties of the device class. This object can be thought of as a set of key-value pairs where the key is the name of the compatibility property and the value is the value of the compatibility property. There will always be at least 1 compat property
              }, # Required. The device class properties that are used to calculate the device class Id
              bestCompatibleUpdate: {
                updateId: {
                  provider: string, # Required. Update provider.
                  name: string, # Required. Update name.
                  version: string, # Required. Update version.
                }, # Required. Update identifier.
                description: string, # Optional. Update description.
                friendlyName: string, # Optional. Friendly update name.
              }, # Optional. Update that is the highest version compatible with this device class.
            }

适用于