Bug 579585 - OPC DA variable with ":" in name
Summary: OPC DA variable with ":" in name
Status: UNCONFIRMED
Alias: None
Product: 4DIAC
Classification: IoT
Component: 4DIAC-IDE (show other bugs)
Version: 1.11.2   Edit
Hardware: PC Linux
: P3 normal
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-05 11:53 EDT by Pedro Souza CLA
Modified: 2022-08-16 07:58 EDT (History)
2 users (show)

See Also:


Attachments
Patch to branch 2.0.1 (5.92 KB, patch)
2022-08-16 07:58 EDT, Pedro Souza CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pedro Souza CLA 2022-04-05 11:53:29 EDT
Hello there, I have a question about OPC DA communication,

We are trying to read a variable in a OPC-DA server that has the name "PIC7101:INTERACTIONPAR.OUTMAXLIMIT"... That seems like trouble due to the ":" and possibly the "." in the variable name.

We are using the following string in the client_0_1:

```
opc[10.32.1.81:ABB.AfwOpcDaSurrogate.1:2000:0.1::PIC7101:INTERACTIONPAR.OUTMAXLIMIT]
```

My question is:
How can I tell the block that a ":" is part of a name and not a separator in the string.
Comment 1 xin zhao CLA 2022-04-07 02:24:14 EDT
can you please help to verify if it is caused by ":" or "." ? thank you
Comment 2 Pedro Souza CLA 2022-04-07 06:15:19 EDT
We are currently changing the function:
```
COpcComLayer::processClientParams
```
In the file  "src/com/opc/opccomlayer.cpp" to use ";" as separator. I'll let you know the test results.

We will try reading different variable names to check this.
Comment 3 Pedro Souza CLA 2022-04-07 09:17:49 EDT
We are able to read a variable called "System Tags.Seconds" just fine. So we believe it is really the ":".
Comment 4 xin zhao CLA 2022-04-12 03:17:41 EDT
(In reply to Pedro Souza from comment #2)
> We are currently changing the function:
> ```
> COpcComLayer::processClientParams
> ```
> In the file  "src/com/opc/opccomlayer.cpp" to use ";" as separator. I'll let
> you know the test results.
> 
> We will try reading different variable names to check this.

I think you have found the correct place to change. 
And what if there is ";" in tag name? So can you please help to check the OPC standard for invalid signal for tag name?
Comment 5 xin zhao CLA 2022-04-12 03:19:09 EDT
(In reply to xin zhao from comment #4)
> (In reply to Pedro Souza from comment #2)
> > We are currently changing the function:
> > ```
> > COpcComLayer::processClientParams
> > ```
> > In the file  "src/com/opc/opccomlayer.cpp" to use ";" as separator. I'll let
> > you know the test results.
> > 
> > We will try reading different variable names to check this.
> 
> I think you have found the correct place to change. 
> And what if there is ";" in tag name? So can you please help to check the
> OPC standard for invalid signal for tag name?

signal => symbol, :)
Comment 6 xin zhao CLA 2022-04-14 02:14:03 EDT
https://opcfoundation.org/forum/classic-opc-da-ae-hda-xml-da-etc/opc-da-tag-naming-convention/

it seems the invalid character for tagname is not defined from opc DA standard.
Comment 7 Pedro Souza CLA 2022-04-14 09:29:10 EDT
Ok so we are bypassing things just to work because we need it fast :D ... But this need to be thought through in the near future.


So far we found tags containing double colon ":" and also containing brackets "[" and "]"

For example:
```
[Control Structure]/Root/Control Network/TIT7101J:OUT
```

This causes everything to break because both brackets and double colons are separators used in translating the string to Forte.

The bypass we are making consist in changing those separators into stuff we don't find in the variables we need to read (at least not in this OPC at this client).

So far we've changed the parsers of ":" to ";" and "[]" to "{}" ... this is definitely not a good solution but it does solve our immediate problems.
Comment 8 Pedro Souza CLA 2022-04-14 09:50:28 EDT
I think that a better solution would be implementing some kind of escape characters ...

Like when you what to use "\" in a python string you can't because this symbol is reserved to the interpreter.
Therefore to write the symbol "\" you need to prepend a character to it to tell this to the parser ... so, in python, writing "\\" will be interpreted as just printing "\".

I think the same logic applies to this situation we have here.
Forte will use "[" to separate the protocol and ":" to separate arguments, therefore in order to use "[" or the ":" as the literal symbol the user should add something to tell the interpreter that he wants that symbol written.

Similar stuff happens in regex syntax, if you want a match with any character you type "." but it you want to match the dot you'll type "\."

Some example using "\" as this special character will be:

```
opc[10.32.1.81:ABB.AfwOpcDaSurrogate.1:2000:0.1::\[Control Structure\]/Root/Control Network/TIT7101J\:OUT]
```

This should be able to tell to the parser that "\[" should be interpreted as "[" and "\:" as ":"
Comment 9 xin zhao CLA 2022-04-24 01:40:45 EDT
yes, it seems this is a thorough solution as the ID is used for many protocols. Even we find the solution to opc DA, there will be problems for other communication FBs. 

it is very much appreciated if you are interested in writing an escape solution for chars in ID.
Comment 10 Pedro Souza CLA 2022-04-26 08:51:28 EDT
Following this reply on the Forum:
https://www.eclipse.org/forums/index.php?t=msg&th=1099743&goto=1809430&#msg_1809430

The correct escape character is `$`
Comment 11 xin zhao CLA 2022-04-27 21:24:50 EDT
use '$' is good if the ID contains ',". have you tried "$:" in ID? 

I guess the default escape logic does not contain escaping ":".
Comment 12 Pedro Souza CLA 2022-08-16 07:36:06 EDT
(In reply to xin zhao from comment #11)
> use '$' is good if the ID contains ',". have you tried "$:" in ID? 
> 
> I guess the default escape logic does not contain escaping ":".

Unfortunately the dollar sign only work to escape quotes and double quotes.
Comment 13 Pedro Souza CLA 2022-08-16 07:50:11 EDT
To find which protocol it is,  the method "extractLayerIdAndParams" searches for bracket "[ ]" and in this method the "\" is used to escape them. Meaning that a "\]" will be ignored when searching for the closing bracket.

I've extended this behavior to the "COpcComLayer::processClientParams" method and used the boost library to handle this separation. 
I can be done without boost of course, but as the OPC already has a dependency on it I didn't see any harm in it.

The way it is implemented now we can handle a weird variable like:
```
Pressure_Line_1,5bar:OUT[3].value
```

This can be achieved by writing it like:
```
Pressure_Line_1\,5bar\:OUT\[3\].value
```

- The "," need escaping because it is the separator for variables
- The ":" need escaping because it is the separator for parameters
- The "[" and "]" need escaping because it separates the protocol form parameters
Comment 14 Pedro Souza CLA 2022-08-16 07:58:20 EDT
Created attachment 288683 [details]
Patch to branch 2.0.1

This patch can be applied at branch 2.0.1

```
git apply path/to/patch/file
```

It is a possible implementation of "COpcComLayer::processClientParams" using boost to separate the parameters and variables with "\" as a escape characters for it.