Skip to content

Commit c9a7ba5

Browse files
committed
Implement returning the output of a method call in the status field of the broker message (similar to reads etc.).
1 parent 5dee054 commit c9a7ba5

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

KafkaClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private void HandleCommand()
105105
// route this to the right handler
106106
if (request.Command == "MethodCall")
107107
{
108-
new UAClient().ExecuteUACommand(_appConfig, requestPayload);
108+
response.Status = new UAClient().ExecuteUACommand(_appConfig, requestPayload);
109109
Log.Logger.Information($"Call succeeded, sending response to broker...");
110110
response.Success = true;
111111
}

MQTTClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private async Task HandleMessageAsync(MqttApplicationMessageReceivedEventArgs ar
269269
// route this to the right handler
270270
if (request.Command == "MethodCall")
271271
{
272-
new UAClient().ExecuteUACommand(_uAApplication, requestPayload);
272+
response.Status = new UAClient().ExecuteUACommand(_uAApplication, requestPayload);
273273
response.Success = true;
274274
}
275275
else if (request.Command == "Read")

UAClient.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Opc.Ua.Cloud.Commander
99

1010
public class UAClient
1111
{
12-
public void ExecuteUACommand(ApplicationConfiguration appConfiguration, string payload)
12+
public string ExecuteUACommand(ApplicationConfiguration appConfiguration, string payload)
1313
{
1414
Session session = null;
1515

@@ -66,6 +66,18 @@ public void ExecuteUACommand(ApplicationConfiguration appConfiguration, string p
6666
{
6767
throw new ServiceResultException(new ServiceResult(results[0].StatusCode, 0, diagnosticInfos, responseHeader.StringTable));
6868
}
69+
70+
// put the results in a comma-seperated string
71+
string result = string.Empty;
72+
if ((results?.Count > 0) && (results[0].OutputArguments != null) && (results[0].OutputArguments.Count > 0))
73+
{
74+
foreach (Variant argument in results[0].OutputArguments)
75+
{
76+
result += argument.ToString() + ',';
77+
}
78+
}
79+
80+
return result.TrimEnd(',');
6981
}
7082
catch (Exception ex)
7183
{

0 commit comments

Comments
 (0)