我正在尝试在我的服务器上指定节点ID,但不了解我应该遵循的结构。我遵循看似简单的结构来更改节点ID,并且没有收到错误或警告。我成功创建了节点,如下所示,但没有创建node_id。我想添加一个简单的节点id,我将遵循相同的结构,并添加带有$$$$的行;
// opcua_server.c
#include "ua_types.h"
#define HANDLE_PDU1 15
const uint8_t EN_DISPLAYNAME_PDU1[] = "PDU1";
const UA_UTF8_string_t ENGLISH_TEXT[] = {
{0, 0}, {sizeof(EN_DISPLAYNAME_PDU1) - 1, EN_DISPLAYNAME_PDU1}};
void opcua_add_nodes(void) {
UA_Status_t status = 0;
// Add PDU1 Folder
UA_Folder_t PDU1;
UAServer_Init_config_structure_Folder(&PDU1);
PDU1.node_handle = HANDLE_PDU1;
PDU1.display_name_handle = HANDLE_PDU1;
UA_NodeId_Config_t randomHANDLE; // $$$$ Not creating node id
PDU1.node_id = randomHANDLE; // $$$$ Not creating node id
status = UAServer_Create_Folder(&PDU1);
if (status != 0) {
UA_SERVER_PRINTF("UAServer_Create_Folder returned: %d\n",
(uint16_t)status);
}
status = UAServer_Add_to_folder(folder.node_handle, PDU1.node_handle);
if (status != 0) {
UA_SERVER_PRINTF("UAServer_Add_to_objects_folder returned: %d\n",
(uint16_t)status);
}
}
// ua_types.h
typedef struct {
/**
* A mandatory unique identifier that identifies the node in the library.
* The value zero is invalid.
*/
uint32_t node_handle;
/**
* A mandatory unique identifier that allows the host to efficiently look up
* the
* node name text to display in a translate callback. The value zero is
* invalid.
*/
uint32_t display_name_handle;
/**
* An optional unique identifier that allows the host to efficiently look up
* the
* node description text to display in a translate callback. The value zero
* is
* invalid.
*/
uint32_t description_handle;
/**
* An optional visibility mask that restricts the visibility of the node
* depending
* on which user is logged in. The anonymous user is bit 0 and bits 1 - 15
* represent the corresponding users
*/
uint16_t user_visibility;
/**
* Specifies the namespace index for this node. The UA namespace is 0 and
* cannot
* be used. The default server namespace is 1. Other namespaces may be added
* to the configuration data structure.
*/
uint16_t namespace_index;
/**
* An optional parameter set that defines the NodeId for the node as a
* string
* or a GUID. If this parameter is set to default values then the SDK will
* assign
* an opaque node id to the node. Opaque node ids are easily decoded by the
* SDK
* and offer the best performance. Only populate this parameter set if your
* application requires it.
*/
UA_NodeId_Config_t node_id;
} UA_Base_t;
/*****************************************************************************/
/** \brief A configuration structure for Folder address space nodes.
*
*/
typedef UA_Base_t UA_Folder_t;
/*****************************************************************************/
/** \brief A configuration structure for View address space nodes.
*
*/
typedef UA_Folder_t UA_View_t;
/*****************************************************************************/
/** \brief A configuration structure for Method address space nodes.
*
*/
typedef struct {
/**
* Configuration common to all nodes
*/
UA_Base_t base_config;
/**
* The file size in bytes
*/
uint64_t size;
/**
* The file is writable
*/
bool_t writable;
/**
* An optional writable mask that restricts write access of the file
* depending
* on which user is logged in. The anonymous user is bit 0 and bits 1 - 15
* represent the corresponding users
*/
uint16_t user_writable;
} UA_File_t;
答案 0 :(得分:0)
定义PDU1
时,已创建node_id
并与之关联。您只需访问node_id
并为其每个元素分配值。
替换
UA_NodeId_Config_t randomHANDLE; // $$$$ Not creating node id
PDU1.node_id = randomHANDLE; // $$$$ Not creating node id
与
PDU1.node_id.identifier_type = xxxx; // xxxx, yyyy, zzz is whatever valid value for their type.
PDU1.node_id.string_identifier = yyyy;
PDU1.node_id.guid_identifier = zzzz;
答案 1 :(得分:0)
结果我需要指定标识符类型(我通过查看标识符类型来做)并将其设置为等于opcua_node_encoding_string。结果是我创建的字符串节点ID。
//Add PDU1 Folder
UA_Folder_t PDU1;
UAServer_Init_config_structure_Folder(&PDU1);
PDU1.node_handle = HANDLE_PDU1;
PDU1.display_name_handle = HANDLE_PDU1;
PDU1.node_id.identifier_type = opcua_node_encoding_string;
const char TEST_STRING_ID2[] = "PDU1";
PDU1.node_id.string_identifier.length = sizeof(TEST_STRING_ID2) - 1;
PDU1.node_id.string_identifier.data = (uint8_t*)TEST_STRING_ID2;
status = UAServer_Create_Folder(&PDU1);
if (status != 0)
{
UA_SERVER_PRINTF("UAServer_Create_Folder returned: %d\n", (uint16_t)status);
}
status = UAServer_Add_to_folder(folder.node_handle, PDU1.node_handle);
if (status != 0)
{
UA_SERVER_PRINTF("UAServer_Add_to_objects_folder returned: %d\n", (uint16_t)status);
}