Skip to content

Commit

Permalink
Add OPCWRITE
Browse files Browse the repository at this point in the history
  • Loading branch information
aorzelskiGH committed May 8, 2021
1 parent 4acdd7a commit acbbcf0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/AasxServerBlazor/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"AasxServerBlazor": {
"commandName": "Project",
"commandLineArgs": "--rest --data-path C:\\Development\\ILE_AASX --connect --edit --no-security",
"commandLineArgs": "--rest --data-path C:\\Development\\TimeSeries --connect --edit --no-security --opc-client-rate 3000",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
26 changes: 20 additions & 6 deletions src/AasxServerStandardBib/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2242,7 +2242,12 @@ private static void WalkSubmodelElement(AdminShell.SubmodelElement sme, string n

private static void UpdatePropertyFromOPCClient(AdminShell.Property p, string serverNodeId, SampleClient.UASampleClient client, NodeId clientNodeId)
{
string value;
string value = "";

bool write = (p.HasQualifierOfType("OPCWRITE") != null);
if (write)
value = p.value;

try
{
// ns=#;i=#
Expand All @@ -2256,8 +2261,14 @@ private static void UpdatePropertyFromOPCClient(AdminShell.Property p, string se
clientNodeId = new NodeId(i, ns);
Console.WriteLine("New node id: ", clientNodeId.ToString());
}
value = client.ReadSubmodelElementValue(clientNodeId);
Console.WriteLine(string.Format("{0} <= {1}", serverNodeId, value));
if (write)
{
short i = Convert.ToInt16(value);
client.WriteSubmodelElementValue(clientNodeId, i);
}
else
value = client.ReadSubmodelElementValue(clientNodeId);
}
catch (ServiceResultException ex)
{
Expand All @@ -2266,11 +2277,14 @@ private static void UpdatePropertyFromOPCClient(AdminShell.Property p, string se
}

// update in AAS env
p.Set(p.valueType, value);
if (!write)
{
p.Set(p.valueType, value);

// update in OPC
if (!OPCWrite(serverNodeId, value))
Console.WriteLine("OPC write not successful.");
// update in OPC
if (!OPCWrite(serverNodeId, value))
Console.WriteLine("OPC write not successful.");
}
}
}

Expand Down
33 changes: 31 additions & 2 deletions src/AasxServerStandardBib/UASampleClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,45 @@ private static void CertificateValidator_CertificateValidation(CertificateValida
}

public string ReadSubmodelElementValue(string nodeName, int index)

{
NodeId node = new NodeId(nodeName, (ushort)index);
return (session.ReadValue(node).ToString());
}

public string ReadSubmodelElementValue(NodeId nodeId)

{
return (session.ReadValue(nodeId).ToString(null, CultureInfo.InvariantCulture));
}

public void WriteSubmodelElementValue(NodeId nodeId, object value)
{
WriteValue nodeToWrite = new WriteValue();
nodeToWrite.NodeId = nodeId;
nodeToWrite.AttributeId = Attributes.Value;
nodeToWrite.Value = new DataValue();
nodeToWrite.Value.WrappedValue = new Variant(value);

WriteValueCollection nodesToWrite = new WriteValueCollection();
nodesToWrite.Add(nodeToWrite);

// read the attributes.
StatusCodeCollection results = null;
DiagnosticInfoCollection diagnosticInfos = null;

ResponseHeader responseHeader = session.Write(
null,
nodesToWrite,
out results,
out diagnosticInfos);

ClientBase.ValidateResponse(results, nodesToWrite);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToWrite);

// check for error.
if (StatusCode.IsBad(results[0]))
{
throw ServiceResultException.Create(results[0], 0, diagnosticInfos, responseHeader.StringTable);
}
}
}
}

0 comments on commit acbbcf0

Please sign in to comment.