Page 1 of 1

How to get MaxStringLength, "BadOutOfRange" after writing

Posted: 30 Oct 2018, 12:32
by hartmut_irs
Before writing a string value, we want to check the current string length with the defined max string length.

Currently after writing a String value we get the error message "BadOutOfRange". The length of the written value is longer than the defined max string length. This behaviour is correct.

How do we get the information about the max string length for a specific string value? We couldn'd find any code example.

Re: How to get MaxStringLength, "BadOutOfRange" after writin

Posted: 31 Oct 2018, 07:38
by Support Team
Hello,

A server can expose the information about the maximum length of a string with the optional property MaxStringLength.

Description of MaxStringLength in the OPC UA specification:
Only used for DataVariables having a String DataType.
This optional Property indicates the maximum number of bytes supported by the DataVariable.

Re: How to get MaxStringLength, "BadOutOfRange" after writin

Posted: 31 Oct 2018, 10:49
by hartmut_irs
Hello Support-Team,
thank you for the answer.

On server side we have a Siemens OPCUA and the supplier is not able to define a property MaxStringLength.

The Siemens-S7 STRING type is defined like:
Byte0: max string length
Byte1: current string length
Byte2,...: data

An example were we facing the problem:
DataType: STRING (the supplier defined a max. length of 2)

value = 'AB' -> OK
vaule = 'ABC' -> BadOutOfRange

Code: Select all

_gValue.Value = TypeUtils.Cast(gValue, gNode.Type);

WriteValueCollection coNodes = new WriteValueCollection();
coNodes.Add(new WriteValue() { NodeId = gNode.NodeId, AttributeId = Attributes.Value, Value = _gValue });

List<StatusCode> coResults = gSession.Write(coNodes);
if (!StatusCode.IsGood(coResults[0]))
{
	throw new Exception("Failed to write item, result status: " + coResults[0].ToString() + ".");  // BadOutOfRange when Value = 'ABC'
}
When we write the 'AB' to the OPC, the value is correctly written. The 2 length-bytes ahead defined by Siemens-S7 are considered.
We can verfify this with the UAExpert tool.

How we can make a workaround to solve this problem?

Re: How to get MaxStringLength, "BadOutOfRange" after writin

Posted: 02 Nov 2018, 08:01
by Support Team
Hello,

You need to ask the Siemens support for solving the issue. From the OPC UA point of view you can only try writing the value and evaluating the returned StatusCode.