// Shows how to configure the OPC UA Console Interaction plug-in by turning off the output colorization.
using System;
using System.Diagnostics;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.Engine;
using OpcLabs.EasyOpc.UA.OperationModel;
using OpcLabs.EasyOpc.UA.Plugins.ConsoleInteraction;
namespace UADocExamples.Interaction
{
class ConsoleInteraction
{
public static void ColorizeOutput()
{
// Configure the shared plug-in.
// Find the parameters object of the plug-in.
UAConsoleInteractionPluginParameters consoleInteractionPluginParameters =
EasyUAClient.SharedParameters.PluginConfigurations.Find<UAConsoleInteractionPluginParameters>();
Debug.Assert(consoleInteractionPluginParameters != null);
// Change the parameter.
consoleInteractionPluginParameters.ColorizeOutput = false;
// Do not implicitly trust any endpoint URLs. We want the user be asked explicitly.
EasyUAClient.SharedParameters.EngineParameters.CertificateAcceptancePolicy.TrustedEndpointUrlStrings.Clear();
// Define which server we will work with.
UAEndpointDescriptor endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
// Require secure connection, in order to enforce the certificate check.
endpointDescriptor.EndpointSelectionPolicy = new UAEndpointSelectionPolicy(UAMessageSecurityModes.Secure);
// Instantiate the client object.
var client = new EasyUAClient();
UAAttributeData attributeData;
try
{
// Obtain attribute data.
// The component automatically triggers the necessary user interaction during the first operation.
attributeData = client.Read(endpointDescriptor, "nsu=http://test.org/UA/Data/;i=10853");
}
catch (UAException uaException)
{
Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message);
return;
}
// Display results.
Console.WriteLine("Value: {0}", attributeData.Value);
Console.WriteLine("ServerTimestamp: {0}", attributeData.ServerTimestamp);
Console.WriteLine("SourceTimestamp: {0}", attributeData.SourceTimestamp);
Console.WriteLine("StatusCode: {0}", attributeData.StatusCode);
}
}
}
// Shows how to configure the OPC UA Console Interaction plug-in by turning off the output colorization.
class procedure ConsoleInteraction.ColorizeOutput;
var
Arguments: OleVariant;
AttributeData: _UAAttributeData;
Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
ClientConfiguration: TEasyUAClientConfiguration;
ConsoleInteractionPluginParameters: _UAconsoleInteractionPluginParameters;
EndpointSelectionPolicy: _UAEndpointSelectionPolicy;
ReadArguments: _UAReadArguments;
Result: _UAAttributeDataResult;
Results: OleVariant;
begin
// Configure the shared plug-in.
// The configuration object allows access to static behavior.
ClientConfiguration := TEasyUAClientConfiguration.Create(nil);
ClientConfiguration.Connect;
// Find the parameters object of the plug-in.
ConsoleInteractionPluginParameters := IUnknown(ClientConfiguration.SharedParameters.PluginConfigurations.Find('OpcLabs.EasyOpc.UA.Plugins.ConsoleInteraction.UAConsoleInteractionPluginParameters')) as _UAConsoleInteractionPluginParameters;
// Change the parameter.
ConsoleInteractionPluginParameters.ColorizeOutput := False;
// Do not implicitly trust any endpoint URLs. We want the user be asked explicitly.
ClientConfiguration.SharedParameters.EngineParameters.CertificateAcceptancePolicy.TrustedEndpointUrlStrings.Clear();
// Define which server we will work with.
ReadArguments := CoUAReadArguments.Create;
ReadArguments.EndpointDescriptor.UrlString := 'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer';
// Require secure connection, in order to enforce the certificate check.
EndpointSelectionPolicy := CoUAEndpointSelectionPolicy.Create;
EndpointSelectionPolicy.AllowedMessageSecurityModes := UAMessageSecurityModes_Secure;
ReadArguments.EndpointDescriptor.EndpointSelectionPolicy := EndpointSelectionPolicy;
ReadArguments.NodeDescriptor.NodeId.ExpandedText := 'nsu=http://test.org/UA/Data/;i=10853';
Arguments := VarArrayCreate([0, 0], varVariant);
Arguments[0] := ReadArguments;
// Instantiate the client object.
Client := CoEasyUAClient.Create;
// Obtain attribute data.
// The component automatically triggers the necessary user interaction during the first operation.
TVarData(Results).VType := varArray or varVariant;
TVarData(Results).VArray := PVarArray(Client.ReadMultiple(Arguments));
Result := IInterface(Results[0]) as _UAAttributeDataResult;
if Result.Succeeded then
begin
AttributeData := Result.AttributeData;
// Display results.
WriteLn('Value: ', AttributeData.Value);
WriteLn('ServerTimestamp: ', DateTimeToStr(AttributeData.ServerTimestamp));
WriteLn('SourceTimestamp: ', DateTimeToStr(AttributeData.SourceTimestamp));
WriteLn('StatusCode: ', AttributeData.StatusCode.ToString);
end
else
WriteLn('*** Failure: ', Result.ErrorMessageBrief);
FreeAndNil(ClientConfiguration);
end;
' Shows how to configure the OPC UA Console Interaction plug-in by turning off the output colorization.
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.Engine
Imports OpcLabs.EasyOpc.UA.OperationModel
Imports OpcLabs.EasyOpc.UA.Plugins.ConsoleInteraction
Namespace UADocExamples.Interaction
Friend Class ConsoleInteraction
Public Shared Sub ColorizeOutput()
' Configure the shared plug-in.
' Find the parameters object of the plug-in.
Dim consoleInteractionPluginParameters =
EasyUAClient.SharedParameters.PluginConfigurations.Find(Of UAConsoleInteractionPluginParameters)()
Debug.Assert(consoleInteractionPluginParameters IsNot Nothing)
' Change the parameter.
consoleInteractionPluginParameters.ColorizeOutput = False
' Do not implicitly trust any endpoint URLs. We want the user be asked explicitly.
EasyUAClient.SharedParameters.EngineParameters.CertificateAcceptancePolicy.TrustedEndpointUrlStrings.Clear()
' Define which server we will work with.
Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
' Require secure connection, in order to enforce the certificate check.
endpointDescriptor.EndpointSelectionPolicy = New UAEndpointSelectionPolicy(UAMessageSecurityModes.Secure)
' Instantiate the client object.
Dim client = New EasyUAClient()
Dim attributeData As UAAttributeData
Try
' Obtain attribute data.
' The component automatically triggers the necessary user interaction during the first operation.
attributeData = client.Read(endpointDescriptor, "nsu=http://test.org/UA/Data/;i=10853")
Catch uaException As UAException
Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
Exit Sub
End Try
' Display results.
Console.WriteLine("Value: {0}", attributeData.Value)
Console.WriteLine("ServerTimestamp: {0}", attributeData.ServerTimestamp)
Console.WriteLine("SourceTimestamp: {0}", attributeData.SourceTimestamp)
Console.WriteLine("StatusCode: {0}", attributeData.StatusCode)
End Sub
End Class
End Namespace