Use bracketless OPC UA node IDs for arrays
This commit is contained in:
@@ -256,7 +256,7 @@ namespace ZB.MOM.WW.LmxOpcUa.Host.OpcUa
|
||||
var variable = CreateVariable(parent, attr.AttributeName, attr.AttributeName, new NodeId(opcUaDataTypeId),
|
||||
attr.IsArray ? ValueRanks.OneDimension : ValueRanks.Scalar);
|
||||
|
||||
var nodeIdString = attr.FullTagReference;
|
||||
var nodeIdString = GetNodeIdentifier(attr);
|
||||
variable.NodeId = new NodeId(nodeIdString, NamespaceIndex);
|
||||
|
||||
if (attr.IsArray && attr.ArrayDimension.HasValue)
|
||||
@@ -275,6 +275,16 @@ namespace ZB.MOM.WW.LmxOpcUa.Host.OpcUa
|
||||
VariableNodeCount++;
|
||||
}
|
||||
|
||||
private static string GetNodeIdentifier(GalaxyAttributeInfo attr)
|
||||
{
|
||||
if (!attr.IsArray)
|
||||
return attr.FullTagReference;
|
||||
|
||||
return attr.FullTagReference.EndsWith("[]", StringComparison.Ordinal)
|
||||
? attr.FullTagReference.Substring(0, attr.FullTagReference.Length - 2)
|
||||
: attr.FullTagReference;
|
||||
}
|
||||
|
||||
private FolderState CreateFolder(NodeState? parent, string path, string name)
|
||||
{
|
||||
var folder = new FolderState(parent)
|
||||
@@ -348,6 +358,9 @@ namespace ZB.MOM.WW.LmxOpcUa.Host.OpcUa
|
||||
|
||||
for (int i = 0; i < nodesToRead.Count; i++)
|
||||
{
|
||||
if (nodesToRead[i].AttributeId != Attributes.Value)
|
||||
continue;
|
||||
|
||||
var nodeId = nodesToRead[i].NodeId;
|
||||
if (nodeId.NamespaceIndex != NamespaceIndex) continue;
|
||||
|
||||
@@ -379,6 +392,9 @@ namespace ZB.MOM.WW.LmxOpcUa.Host.OpcUa
|
||||
|
||||
for (int i = 0; i < nodesToWrite.Count; i++)
|
||||
{
|
||||
if (nodesToWrite[i].AttributeId != Attributes.Value)
|
||||
continue;
|
||||
|
||||
var nodeId = nodesToWrite[i].NodeId;
|
||||
if (nodeId.NamespaceIndex != NamespaceIndex) continue;
|
||||
|
||||
@@ -404,7 +420,15 @@ namespace ZB.MOM.WW.LmxOpcUa.Host.OpcUa
|
||||
}
|
||||
|
||||
var success = _mxAccessClient.WriteAsync(tagRef, value).GetAwaiter().GetResult();
|
||||
errors[i] = success ? ServiceResult.Good : new ServiceResult(StatusCodes.BadInternalError);
|
||||
if (success)
|
||||
{
|
||||
PublishLocalWrite(tagRef, value);
|
||||
errors[i] = ServiceResult.Good;
|
||||
}
|
||||
else
|
||||
{
|
||||
errors[i] = new ServiceResult(StatusCodes.BadInternalError);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -462,6 +486,18 @@ namespace ZB.MOM.WW.LmxOpcUa.Host.OpcUa
|
||||
return Convert.ChangeType(value, elementType);
|
||||
}
|
||||
|
||||
private void PublishLocalWrite(string tagRef, object? value)
|
||||
{
|
||||
if (!_tagToVariableNode.TryGetValue(tagRef, out var variable))
|
||||
return;
|
||||
|
||||
var dataValue = DataValueConverter.FromVtq(Vtq.Good(value));
|
||||
variable.Value = dataValue.Value;
|
||||
variable.StatusCode = dataValue.StatusCode;
|
||||
variable.Timestamp = dataValue.SourceTimestamp;
|
||||
variable.ClearChangeMasks(SystemContext, false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subscription Delivery
|
||||
|
||||
Reference in New Issue
Block a user