共用方式為


Twin class

裝置對應項是說明 Azure IoT 中樞所儲存之裝置狀態的檔,即使裝置已離線,仍可供使用。 其建置約3個區段:

  • 標籤:金鑰/值群組只能從服務端存取
  • 所需屬性:由服務更新,並由裝置接收
  • 報告屬性:由裝置更新,並由服務接收。

請注意,雖然有可能,但想要和報告的屬性不需要相符,而且如果需要,同步這兩個集合的邏輯會留給SDK的使用者。

如需詳細資訊,請參閱 瞭解裝置對應項

取得特定裝置 Twin 的建議方法是使用 getTwin(string, HttpResponseCallback<Twin>) 方法。

建構函式

Twin(string | DeviceIdentity, Registry)

具現化新的 Twin。 取得新 Twin 對象的建議方式是使用 getTwin(string, HttpResponseCallback<Twin>) 方法。

屬性

deviceId

與對應項相關聯的裝置身分識別的唯一標識符,因為它存在於裝置身分識別登錄中。

etag

用於開放式並行存取的標籤,以避免多個平行版本的裝置對應項。

modelId

與對應項相關聯的裝置身分識別模型標識符,因為它存在於裝置身分識別登錄中。

moduleId

與對應項相關聯的模組模組標識符,因為它存在於裝置身分識別登錄中。

properties

所需和報告的屬性日記(分別在 properties.desiredproperties.reported中)。

tags

只有服務端可用的索引鍵/值組集合,而且可用於查詢來尋找特定裝置。

方法

get()
get(IncomingMessageCallback<Twin>)

從IoT中樞服務取得這個裝置對應項的最新版本。

toJSON()
update(any)
update(any, IncomingMessageCallback<Twin>)

使用提供作為自變數的修補程式來更新裝置對應項。

建構函式詳細資料

Twin(string | DeviceIdentity, Registry)

具現化新的 Twin。 取得新 Twin 對象的建議方式是使用 getTwin(string, HttpResponseCallback<Twin>) 方法。

new Twin(device: string | DeviceIdentity, registryClient: Registry)

參數

device

string | DeviceIdentity

描述裝置的裝置識別碼字串或物件。 如果 Object,它必須包含 deviceId 屬性。

registryClient
Registry

用來執行 REST API 呼叫的 HTTP 登錄用戶端。

屬性詳細資料

deviceId

與對應項相關聯的裝置身分識別的唯一標識符,因為它存在於裝置身分識別登錄中。

deviceId: string

屬性值

string

etag

用於開放式並行存取的標籤,以避免多個平行版本的裝置對應項。

etag: string

屬性值

string

modelId

與對應項相關聯的裝置身分識別模型標識符,因為它存在於裝置身分識別登錄中。

modelId?: string

屬性值

string

moduleId

與對應項相關聯的模組模組標識符,因為它存在於裝置身分識別登錄中。

moduleId?: string

屬性值

string

properties

所需和報告的屬性日記(分別在 properties.desiredproperties.reported中)。

properties: { desired: {[key: string]: any}, reported: {[key: string]: any} }

屬性值

{ desired: {[key: string]: any}, reported: {[key: string]: any} }

tags

只有服務端可用的索引鍵/值組集合,而且可用於查詢來尋找特定裝置。

tags: {[key: string]: string}

屬性值

{[key: string]: string}

方法詳細資料

get()

function get(): Promise<ResultWithIncomingMessage<Twin>>

傳回

Promise<ResultWithIncomingMessage<Twin>>

get(IncomingMessageCallback<Twin>)

從IoT中樞服務取得這個裝置對應項的最新版本。

function get(done?: IncomingMessageCallback<Twin>)

參數

done

IncomingMessageCallback<Twin>

作業完成時要呼叫的選擇性函式。 done 會使用三個自變數來呼叫:Error 物件(可以是 null)、代表所建立裝置識別的對應項 對應項 物件,以及用於記錄或偵錯的傳輸特定回應物件。

toJSON()

function toJSON(): object

傳回

object

update(any)

function update(patch: any): Promise<ResultWithIncomingMessage<Twin>>

參數

patch

any

傳回

Promise<ResultWithIncomingMessage<Twin>>

update(any, IncomingMessageCallback<Twin>)

使用提供作為自變數的修補程式來更新裝置對應項。

function update(patch: any, done?: IncomingMessageCallback<Twin>)

參數

patch

any

物件,其中包含要套用至此裝置對應項的新值。

done

IncomingMessageCallback<Twin>

作業完成時要呼叫的選擇性函式。 done 會使用三個自變數來呼叫:Error 物件(可以是 null)、代表所建立裝置識別的對應項 對應項 物件,以及用於記錄或偵錯的傳輸特定回應物件。