簡體   English   中英

如何定義和使用自定義結構類型?

[英]How to define and use custom structure type?

說我想根據OPC-UA定義類型為Person的“字段” NameAge (定義ByteStream的任何結構的節點並序列化/反序列化數據很簡單-這不是我想要的)。 我也想定義類型為Person變量節點person並一步寫入該節點。 怎么做?

請注意:當我用此類數據更新person (Kevin, 47)(Jane, 22)客戶端應該獲得訂閱,或者當直接讀取變量時僅那兩對,而不是(Kevin,22)

我使用OPC-UA .Net官方堆棧,但是我應該能夠從任何給定的框架中“翻譯”。

使用OPC UA,可以實現上述目標。這被稱為信息建模。

是否支持OPC UA SDK(框架)到SDK。

如果SDK支持自定義對象類型,自定義變量類型創建,則可以在簡單的節點集XML文件的幫助下創建自定義類型。

在您的示例中,您可以創建一個名為Person的變量類型,並創建一個相同的實例。 您還將能夠如上所述獲得推送通知。

請找到下面提到的Nodeset XML Snippet,用於創建自定義對象類型自定義變量並創建其實例。

 <!-- Below XML logic will explain on how to create Custom Object Type and Custom Variable Type--> <UAObjectType NodeId="ns=2;s=PersonType" BrowseName="2:PersonType"> <DisplayName>PersonType</DisplayName> <Description>A Person Object Type</Description> <References> <Reference ReferenceType="HasComponent">ns=2;s=NameType</Reference> <Reference ReferenceType="HasComponent">ns=2;s=AgeType</Reference> <Reference ReferenceType="HasSubtype" IsForward="false">i=58</Reference> </References> </UAObjectType> <UAVariableType NodeId="ns=2;s=AgeType" BrowseName="2:AgeType" DataType="Byte"> <DisplayName>AgeType</DisplayName> <Description>A Age variable type. it is component of AgeType</Description> <References> <Reference ReferenceType="HasComponent" IsForward="false" >ns=2;s=PersonType</Reference> <Reference ReferenceType="HasSubtype" IsForward="false">i=63</Reference> </References> </UAVariableType> <UAVariableType NodeId="ns=2;s=NameType" BrowseName="2:NameType" DataType="LocalizedText"> <DisplayName>NameType</DisplayName> <Description>A Name Variable type. it is component of NameType</Description> <References> <Reference ReferenceType="HasComponent" IsForward="false" >ns=2;s=PersonType</Reference> <Reference ReferenceType="HasSubtype" IsForward="false">i=63</Reference> </References> </UAVariableType> <!-- Below XML logic will explain on how to create instance of an object using above mentioned types--> <!-- This will create a person1 object inside the Object folder --> <UAObject NodeId="ns=2;s=Person1" BrowseName="2:Person1"> <DisplayName>Person1</DisplayName> <References> <Reference ReferenceType="Organizes" IsForward="false">i=85</Reference> <Reference ReferenceType="HasComponent">ns=2;s=Name1</Reference> <Reference ReferenceType="HasComponent">ns=2;s=Age1</Reference> <Reference ReferenceType="HasTypeDefinition" IsForward="false">ns=2;s=PersonType</Reference> </References> </UAObject> <UAVariable NodeId="ns=2;s=Age1" BrowseName="2:Age1" DataType="Byte"> <DisplayName>Age1</DisplayName> <Description>A Age variable type. it is component of AgeType</Description> <References> <Reference ReferenceType="HasComponent" IsForward="false" >ns=2;s=Person1</Reference> <Reference ReferenceType="HasTypeDefinition" IsForward="false">ns=2;s=AgeType</Reference> </References> <Value> <Byte>10</Byte> </Value> </UAVariable> <UAVariable NodeId="ns=2;s=Name1" BrowseName="2:Name1" DataType="LocalizedText"> <DisplayName>Name1</DisplayName> <Description>A Name Variable type. it is component of NameType</Description> <References> <Reference ReferenceType="HasComponent" IsForward="false" >ns=2;s=Person1</Reference> <Reference ReferenceType="HasTypeDefinition" IsForward="false">ns=2;s=NameType</Reference> </References> <Value> <LocalizedText> <Locale>en</Locale> <Text>MyName</Text> </LocalizedText> </Value> </UAVariable> 

如果SDK支持節點集文件解析,則請將此代碼段放入現有的節點集文件中並導入。 或創建一個節點集文件,然后將其添加到服務器代碼中。

這將輕松創建對象類型及其實例。

我希望這有幫助。

謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM