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.
How to get MaxStringLength, "BadOutOfRange" after writing
Moderator: uasdknet
-
- Jr. Member
- Posts: 4
- Joined: 26 Oct 2018, 08:31
- Support Team
- Hero Member
- Posts: 3073
- Joined: 18 Mar 2011, 15:09
Re: How to get MaxStringLength, "BadOutOfRange" after writin
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:
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.
Best regards
Unified Automation Support Team
Unified Automation Support Team
-
- Jr. Member
- Posts: 4
- Joined: 26 Oct 2018, 08:31
Re: How to get MaxStringLength, "BadOutOfRange" after writin
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
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?
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'
}
We can verfify this with the UAExpert tool.
How we can make a workaround to solve this problem?
- Support Team
- Hero Member
- Posts: 3073
- Joined: 18 Mar 2011, 15:09
Re: How to get MaxStringLength, "BadOutOfRange" after writin
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.
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.
Best regards
Unified Automation Support Team
Unified Automation Support Team