Page 1 of 1

Problem with umlauts in translateBrowsePathsToNodeIds

Posted: 22 Feb 2023, 13:00
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

Re: Problem with umlauts in translateBrowsePathsToNodeIds

Posted: 23 Feb 2023, 10:05
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.

Re: Problem with umlauts in translateBrowsePathsToNodeIds

Posted: 01 Mar 2023, 14:09
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