Skip to content

Commit

Permalink
Set the default value of the StatusCode on BaseVariableState to BadWa…
Browse files Browse the repository at this point in the history
…itingForInitialData. (#1668)

* Removed assigning a default value to any variable value in the AddReverseReferences method.
Set the default value of the StatusCode on BaseVariableState to BadWaitingForInitialData.

* Allow initalization from variable states with status code BadWaitingForInitialData
  • Loading branch information
mrsuciu committed Jan 19, 2022
1 parent 33fab0d commit 213f37e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
12 changes: 1 addition & 11 deletions Libraries/Opc.Ua.Server/Diagnostics/CustomNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@
* ======================================================================*/

using System;
using System.Text;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using Opc.Ua;
using Opc.Ua.Server;


namespace Opc.Ua.Server
{
Expand Down Expand Up @@ -722,13 +719,6 @@ protected virtual void AddReverseReferences(IDictionary<NodeId, IList<IReference

foreach (NodeState source in m_predefinedNodes.Values)
{
// assign a default value to any variable value.
BaseVariableState variable = source as BaseVariableState;

if (variable != null && variable.Value == null)
{
variable.Value = TypeInfo.GetDefaultValue(variable.DataType, variable.ValueRank, Server.TypeTree);
}

IList<IReference> references = new List<IReference>();
source.GetReferences(SystemContext, references);
Expand Down
23 changes: 19 additions & 4 deletions Stack/Opc.Ua.Core/Stack/State/BaseVariableState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
using System.Runtime.Serialization;
using System.Reflection;
using System.Threading;

namespace Opc.Ua
{
Expand All @@ -38,6 +35,7 @@ public BaseVariableState(NodeState parent) : base(NodeClass.Variable, parent)
m_timestamp = DateTime.MinValue;
m_accessLevel = m_userAccessLevel = AccessLevels.CurrentRead;
m_copyPolicy = VariableCopyPolicy.CopyOnRead;
m_statusCode = StatusCodes.BadWaitingForInitialData;
}
#endregion

Expand All @@ -53,16 +51,24 @@ protected override void Initialize(ISystemContext context, NodeState source)

if (instance != null)
{
// The value will be set to default(T) if the originating value is null
m_value = ExtractValueFromVariant(context, instance.m_value, false);
m_timestamp = instance.m_timestamp;
m_statusCode = instance.m_statusCode;
m_dataType = instance.m_dataType;
m_valueRank = instance.m_valueRank;
m_arrayDimensions = null;
m_accessLevel = instance.m_accessLevel;
m_userAccessLevel = instance.m_userAccessLevel;
m_minimumSamplingInterval = instance.m_minimumSamplingInterval;
m_historizing = instance.m_historizing;
// Allow initalization from variable states with status code BadWaitingForInitialData
if (instance.m_statusCode == StatusCodes.BadWaitingForInitialData)
{
m_statusCode = StatusCodes.Good;
}else
{
m_statusCode = instance.m_statusCode;
}

if (instance.m_arrayDimensions != null)
{
Expand Down Expand Up @@ -466,7 +472,14 @@ public object Value
ChangeMasks |= NodeStateChangeMasks.Value;
}

if ((m_value == null) && (StatusCode == StatusCodes.BadWaitingForInitialData))
{
StatusCode = StatusCodes.Good;
}

m_value = value;


}
}

Expand Down Expand Up @@ -2027,6 +2040,7 @@ public class PropertyState : BaseVariableState
/// </summary>
public PropertyState(NodeState parent) : base(parent)
{
StatusCode = StatusCodes.BadWaitingForInitialData;
}

/// <summary>
Expand Down Expand Up @@ -2148,6 +2162,7 @@ public BaseDataVariableState(NodeState parent) : base(parent)
{
if (parent != null)
{
StatusCode = StatusCodes.BadWaitingForInitialData;
ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HasComponent;
}
}
Expand Down

0 comments on commit 213f37e

Please sign in to comment.