你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
DeviceManagementClient.GetDevice(String, RequestContext) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取连接到设备更新的设备的设备IoT 中心的设备属性和最新部署状态。
public virtual Azure.Response GetDevice (string deviceId, Azure.RequestContext context = default);
abstract member GetDevice : string * Azure.RequestContext -> Azure.Response
override this.GetDevice : string * Azure.RequestContext -> Azure.Response
Public Overridable Function GetDevice (deviceId As String, Optional context As RequestContext = Nothing) As Response
参数
- deviceId
- String
Azure IoT 中心中的设备标识符。
- context
- RequestContext
请求上下文,它可以基于每个调用替代客户端管道的默认行为。
返回
从服务返回的响应。 响应正文架构的详细信息位于下面的“备注”部分。
例外
deviceId
为 null。
deviceId
是一个空字符串,预期为非空。
服务返回了不成功状态代码。
示例
此示例演示如何使用所需参数调用 GetDevice 并分析结果。
var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);
Response response = client.GetDevice("<deviceId>");
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("deviceId").ToString());
Console.WriteLine(result.GetProperty("moduleId").ToString());
Console.WriteLine(result.GetProperty("deviceClassId").ToString());
Console.WriteLine(result.GetProperty("groupId").ToString());
Console.WriteLine(result.GetProperty("lastAttemptedUpdate").GetProperty("updateId").GetProperty("provider").ToString());
Console.WriteLine(result.GetProperty("lastAttemptedUpdate").GetProperty("updateId").GetProperty("name").ToString());
Console.WriteLine(result.GetProperty("lastAttemptedUpdate").GetProperty("updateId").GetProperty("version").ToString());
Console.WriteLine(result.GetProperty("lastAttemptedUpdate").GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("lastAttemptedUpdate").GetProperty("friendlyName").ToString());
Console.WriteLine(result.GetProperty("deploymentStatus").ToString());
Console.WriteLine(result.GetProperty("installedUpdate").GetProperty("updateId").GetProperty("provider").ToString());
Console.WriteLine(result.GetProperty("installedUpdate").GetProperty("updateId").GetProperty("name").ToString());
Console.WriteLine(result.GetProperty("installedUpdate").GetProperty("updateId").GetProperty("version").ToString());
Console.WriteLine(result.GetProperty("installedUpdate").GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("installedUpdate").GetProperty("friendlyName").ToString());
Console.WriteLine(result.GetProperty("onLatestUpdate").ToString());
Console.WriteLine(result.GetProperty("lastDeploymentId").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("resultCode").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("extendedResultCode").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("resultDetails").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("update").GetProperty("updateId").GetProperty("provider").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("update").GetProperty("updateId").GetProperty("name").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("update").GetProperty("updateId").GetProperty("version").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("update").GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("update").GetProperty("friendlyName").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("resultCode").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("extendedResultCode").ToString());
Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("resultDetails").ToString());
注解
下面是响应有效负载的 JSON 架构。
响应正文:
的 Device
架构:
{
deviceId: string, # Required. Device identity.
moduleId: string, # Optional. Device module identity.
deviceClassId: string, # Required. Device class identity.
groupId: string, # Optional. Device group identity.
lastAttemptedUpdate: {
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. The update that device last attempted to install.
deploymentStatus: "Succeeded" | "InProgress" | "Canceled" | "Failed", # Optional. State of the device in its last deployment.
installedUpdate: UpdateInfo, # Optional. Currently installed update on device.
onLatestUpdate: boolean, # Required. Boolean flag indicating whether the latest update (the best compatible update for the device's device class and group) is installed on the device
lastDeploymentId: string, # Optional. The deployment identifier for the last deployment to the device
lastInstallResult: {
resultCode: number, # Required. Install result code.
extendedResultCode: number, # Required. Install extended result code
resultDetails: string, # Optional. A string containing further details about the install result
stepResults: [
{
update: UpdateInfo, # Optional. The update that this step installs if it is of reference type.
description: string, # Optional. Step description.
resultCode: number, # Required. Install result code.
extendedResultCode: number, # Required. Install extended result code
resultDetails: string, # Optional. A string containing further details about the install result
}
], # Optional. Array of step results
}, # Optional. Last install result.
}