h-opc icon indicating copy to clipboard operation
h-opc copied to clipboard

Bug when variable name contains "."

Open mnzgth opened this issue 7 years ago • 5 comments

Hello, I'm using nested structures in WinCC which I'm accessing via OPC UA. So my variable name itself contains at least one dot. That's the reason why in "UaClient.cs" / "private UaNode FindNode(string tag, UaNode node)" the simple "tag.Split('.')" doesn't work.

Example:

UaNode[] nodes = opc.ExploreFolder("WinCC.@LOCALMACHINE::.Interne Variablen.Test.psId").ToArray(); // returns 10 nodes
string sTag = nodes[0].Tag; // returns "WinCC.@LOCALMACHINE::.Interne Variablen.TestSpecification.tsId.tsId.Idx01"
var test = opc.Read<Int32>(sTag); // throws Hylasoft.Opc.Common.OpcException: The tag "Idx01" doesn't exist on folder "WinCC.@LOCALMACHINE::.Interne Variablen.Test.tsId"

For testing purposes I modified "FindNode()" to accept the node (and not the tag) as input parameter, then reading/monitoring values worked well...

mnzgth avatar May 22 '17 22:05 mnzgth

Sounds like you found a bug. Feel free to make a pull request with this change and I'll review it.

jmbeach avatar May 23 '17 18:05 jmbeach

Hey, im interested in your Solution aswell. How did you change the "FindNode()" exactly? First the input parameter must be the node and not the tag. And what else did you change?

RschuOWL avatar Oct 18 '18 12:10 RschuOWL

I also came across this bug. Can You suggest me the best workaround waiting for the bug-fix ?

FVilli avatar Dec 18 '18 15:12 FVilli

Why not add an option?

yb123speed avatar Jun 27 '19 07:06 yb123speed

Sorry for bumping this old issue but I got into this issue myself just recently.

For now I used a temporary workaround by replacing the String.Split in FindNode() using Regex.Split with a regex based on this answer, then convert the escaped pattern in the result to the target one (that would be .).

In my case, I modified the regex to make it escape \. then replace the escaped \. with ., to get the correct variable name.

The regex is simple and may have caveats but at least allowed my particular use case to work.

lss4 avatar Jul 15 '21 03:07 lss4