2

I'm relatively new to OPC-UA, I use C# to read/write data to Siemens PLC with OPC-UA protocol. I downloaded helper class (UAClientHelperAPI.cs) from Siemens site ad I use the ReadValues and WriteValues method from this class. In short: When I read values from a PLC from one supplier everythig is alright, I read the string and it is ok... insted, when I read from another PLC (supplied by another manufacturer) the strings contains a strange set of characters, like escape char. I read something like this: " \0J?@???@??\0\0\0\0 \0\0\0" or this " \0?\u0001\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0" but is super random... If I put this string in a TextBox visibile in the form, these characters are not displayed (I think beacause are escape characters or not visible). I tried many solutions.... like this

string result = null;
foreach (char c in input.ToCharArray())
{
    var cat = char.GetUnicodeCategory(c);
    if (cat == UnicodeCategory.UppercaseLetter || 
    cat == UnicodeCategory.LowercaseLetter || 
    cat == UnicodeCategory.DecimalDigitNumber || 
    cat == UnicodeCategory.SpaceSeparator)
    {
        result += c;
    }
}

But it only partially solves the problem, sometimes I find some Letter character which have nothing to do with my string. is this by any chance something with unicode?
I don't have enough skills to solve this problem

Anyone can help me ?

I tryed many solutions but I can solve this problem

  • Hello, perhaps try using a test tool to compare result? https://www.unified-automation.com/products/development-tools/uaexpert.html – Per Dahlqvist Dec 05 '22 at 13:51
  • I already use UAExper.... and this tool retrive the correct string without any strange characters – Luca Arniani Dec 06 '22 at 14:07
  • I'm not familiar with the Siemens helper class, but you might want to try and rebuild your solution using the OPC Foundation client examples, which do not assume you use Siemens hardware: https://github.com/OPCFoundation/UA-.NETStandard-Samples – mawax Jan 02 '23 at 13:38

0 Answers0