Problem with umlauts in translateBrowsePathsToNodeIds

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
ArthurS
Jr. Member
Jr. Member
Posts: 4
Joined: 12 Oct 2022, 14:40

Problem with umlauts in translateBrowsePathsToNodeIds

Post by ArthurS »

I have a list of nodes whose nodeid I want to determine using translateBrowsePathsToNodeIds.
This works so far, but now I have nodes with it that contain umlauts. For these I get BadNoMatch as a result.
The code looks like this:

Code: Select all

	UaBrowsePaths           browsePaths;
	UaRelativePathElements  pathElements;

	OpcUa_UInt32 browseCount = 0;
	browsePaths.create(static_cast<OpcUa_UInt32>(_list.size()));

	for (NodeList::iterator i = _list.begin(); i != _list.end(); i++) {
		gwNode* node = (*i);

		OpcUa_UInt32 pathCount = 0;

		gwNode* ptr;
		for (ptr = node; ptr != _srv; ptr = ptr->Getparent()) {
			if (_stop && (ptr == _stop))
				break;

			if ((ptr->Getgwn() == GWN_OPCUANODE) || (ptr->Getgwn() == GWN_OPCUAFOLDER) || (ptr->Getgwn() == GWN_FOLDER))
				pathCount++;
			if (ptr->Getgwn() == GWN_OPCUAITM) {
				if ((ptr == node) || _stop)
					pathCount++;
				else
					break;
			}
		}

		_nodeid.copyTo(&browsePaths[browseCount].StartingNode);
		pathElements.create(pathCount);

		for (ptr = node; ptr != _srv; ptr = ptr->Getparent()) {
			if ((ptr->Getgwn() == GWN_OPCUAITM) || (ptr->Getgwn() == GWN_OPCUANODE) || (ptr->Getgwn() == GWN_OPCUAFOLDER) || (ptr->Getgwn() == GWN_FOLDER)) {

				pathCount--;

				pathElements[pathCount].IncludeSubtypes = OpcUa_True;
				pathElements[pathCount].IsInverse = OpcUa_False;
				pathElements[pathCount].ReferenceTypeId.Identifier.Numeric = OpcUaId_HierarchicalReferences;
				[b]OpcUa_String_AttachReadOnly(&pathElements[pathCount].TargetName.Name, ptr->GetName());[/b]
				pathElements[pathCount].TargetName.NamespaceIndex = _nodeid.namespaceIndex();

				if (pathCount == 0)
					break;
			}
		}

		browsePaths[browseCount].RelativePath.NoOfElements = pathElements.length();
		browsePaths[browseCount].RelativePath.Elements = pathElements.detach();

		browseCount++;

	}

	UaDiagnosticInfos       diagnosticInfos;
	ServiceSettings         serviceSettings;
	UaBrowsePathResults     browsePathResults;

	UaStatus status = p_Session->translateBrowsePathsToNodeIds(serviceSettings, browsePaths, browsePathResults, diagnosticInfos);

How do I have to pass this at the marked point?

OpcUa_String_AttachReadOnly(&pathElements[pathCount].TargetName.Name, ptr->GetName());

I have already tried conversion to utf8 or utf16, but then I also get errors.

Kind Regards,
Arthur

User avatar
Support Team
Hero Member
Hero Member
Posts: 3064
Joined: 18 Mar 2011, 15:09

Re: Problem with umlauts in translateBrowsePathsToNodeIds

Post by Support Team »

Hello Arthur,

I just tested TranslateBrowsePathToNodeIds with a path containing MultiByte characters and it all works fine. I guess there's an issue when filling the string from gwNode->GetName - so the char* you return probably is not correctly utf8 encoded.
Best regards
Unified Automation Support Team

ArthurS
Jr. Member
Jr. Member
Posts: 4
Joined: 12 Oct 2022, 14:40

Re: Problem with umlauts in translateBrowsePathsToNodeIds

Post by ArthurS »

Thank you for the thought provoking.The conversion to utf8 already worked, but I had buffered that locally.
My mistake was to use OpcUa_String_AttachReadOnly afterwards. With OpcUa_String_AttachCopy it now works.

Kind Regards,
Arthur

Post Reply