// This example shows how to read and display data of an attribute (value, timestamps, and status code).
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.
#include "stdafx.h" // Includes "QuickOpc.h", and other commonly used files
#include "Read.h"
namespace _EasyUAClient
{
void Read::Main()
{
// Initialize the COM library
CoInitializeEx(NULL, COINIT_MULTITHREADED);
{
// Instantiate the client object
_EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));
// Obtain attribute data. By default, the Value attribute of a node will be read.
_UAAttributeDataPtr AttributeDataPtr = ClientPtr->Read(
//L"http://opcua.demo-this.com:51211/UA/SampleServer",
L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer",
L"nsu=http://test.org/UA/Data/ ;i=10853");
// Display results
_variant_t vString;
vString.ChangeType(VT_BSTR, &AttributeDataPtr->Value);
_tprintf(_T("Value: %s\n"), (LPCTSTR)CW2CT((_bstr_t)vString));
vString.ChangeType(VT_BSTR, &_variant_t(AttributeDataPtr->ServerTimestamp, VT_DATE));
_tprintf(_T("ServerTimestamp: %s\n"), (LPCTSTR)CW2CT((_bstr_t)vString));
vString.ChangeType(VT_BSTR, &_variant_t(AttributeDataPtr->SourceTimestamp, VT_DATE));
_tprintf(_T("SourceTimestamp: %s\n"), (LPCTSTR)CW2CT((_bstr_t)vString));
_tprintf(_T("StatusCode: %s\n"), (LPCTSTR)CW2CT(AttributeDataPtr->StatusCode->ToString));
// Example output:
//
//Value: -2.230064E-31
//ServerTimestamp: 11/6/2011 1:34:30 PM
//SourceTimestamp: 11/6/2011 1:34:30 PM
//StatusCode: Good
}
// Release all interface pointers BEFORE calling CoUninitialize()
CoUninitialize();
}
}
// This example shows how to read and display data of an attribute (value,
// timestamps, and status code).
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.
class procedure Read.Main;
var
Client: EasyUAClient;
AttributeData: _UAAttributeData;
begin
// Instantiate the client object
Client := CoEasyUAClient.Create;
// Obtain attribute data. By default, the Value attribute of a node will be
// read.
AttributeData := Client.Read_(
//'http://opcua.demo-this.com:51211/UA/SampleServer',
'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
'nsu=http://test.org/UA/Data/ ;i=10853');
// Display results
WriteLn('Value: ', AttributeData.Value);
WriteLn('ServerTimestamp: ', DateTimeToStr(AttributeData.ServerTimestamp));
WriteLn('SourceTimestamp: ', DateTimeToStr(AttributeData.SourceTimestamp));
WriteLn('StatusCode: ', AttributeData.StatusCode.ToString);
// Example output:
//
//Value: -2.230064E-31
//ServerTimestamp: 11/6/2011 1:34:30 PM
//SourceTimestamp: 11/6/2011 1:34:30 PM
//StatusCode: Good
end;
// This example shows how to read and display data of an attribute (value,
// timestamps, and status code).
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.
class procedure Read.Main;
var
Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
AttributeData: _UAAttributeData;
begin
// Instantiate the client object
Client := CoEasyUAClient.Create;
// Obtain attribute data. By default, the Value attribute of a node will be
// read.
try
AttributeData := Client.Read(
//'http://opcua.demo-this.com:51211/UA/SampleServer',
//'https://opcua.demo-this.com:51212/UA/SampleServer/',
'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
'nsu=http://test.org/UA/Data/ ;i=10853');
except
on E: EOleException do
begin
WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
Exit;
end;
end;
// Display results
WriteLn('Value: ', AttributeData.Value);
WriteLn('ServerTimestamp: ', DateTimeToStr(AttributeData.ServerTimestamp));
WriteLn('SourceTimestamp: ', DateTimeToStr(AttributeData.SourceTimestamp));
WriteLn('StatusCode: ', AttributeData.StatusCode.ToString);
// Example output:
//
//Value: -2.230064E-31
//ServerTimestamp: 11/6/2011 1:34:30 PM
//SourceTimestamp: 11/6/2011 1:34:30 PM
//StatusCode: Good
end;
// This example shows how to read and display data of an attribute (value, timestamps, and status code).
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in PHP on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PHP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.
// Instantiate the client object
$Client = new COM("OpcLabs.EasyOpc.UA.EasyUAClient");
// Obtain attribute data. By default, the Value attribute of a node will be read.
try
{
$AttributeData = $Client->Read(
//"http://opcua.demo-this.com:51211/UA/SampleServer",
"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer",
"nsu=http://test.org/UA/Data/ ;i=10853");
}
catch (com_exception $e)
{
printf("*** Failure: %s\n", $e->getMessage());
Exit();
}
// Display results
printf("Value: %s\n", $AttributeData->Value);
printf("ServerTimestamp: %s\n", $AttributeData->ServerTimestamp);
printf("SourceTimestamp: %s\n", $AttributeData->SourceTimestamp);
printf("StatusCode: %s\n", $AttributeData->StatusCode);
// Example output:
//
//Value: -2.230064E-31
//ServerTimestamp: 11/6/2011 1:34:30 PM
//SourceTimestamp: 11/6/2011 1:34:30 PM
//StatusCode: Good
// This example shows how to read and display data of an attribute (value, timestamps, and status code).
mle_outputtext.Text = ""
// Instantiate the client object
OLEObject client
client = CREATE OLEObject
client.ConnectToNewObject("OpcLabs.EasyOpc.UA.EasyUAClient")
// Obtain attribute data. By default, the Value attribute of a node will be read.
OLEObject attributeData
TRY
attributeData = client.Read("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10853") // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
CATCH (OLERuntimeError oleRuntimeError)
mle_outputtext.Text = mle_outputtext.Text + "*** Failure: " + oleRuntimeError.Description + "~r~n"
RETURN
END TRY
// Display results
mle_outputtext.Text = mle_outputtext.Text + "Value: " + String(attributeData.value) + "~r~n"
mle_outputtext.Text = mle_outputtext.Text + "ServerTimestamp: " + String(attributeData.ServerTimestamp) + "~r~n"
mle_outputtext.Text = mle_outputtext.Text + "SourceTimestamp: " + String(attributeData.SourceTimestamp) + "~r~n"
mle_outputtext.Text = mle_outputtext.Text + "StatusCode: " + String(attributeData.StatusCode) + "~r~n"
// Example output:
//
//Value: -2.230064E-31
//ServerTimestamp: 11/6/2011 1:34:30 PM
//SourceTimestamp: 11/6/2011 1:34:30 PM
//StatusCode: Good
# This example shows how to read and display data of an attribute (value, timestamps, and status code).
#
# The Python for Windows (pywin32) extensions package is needed. Install it using "pip install pypiwin32".
# CAUTION: We now recommend using Python.NET package instead. Full set of examples with Python.NET is available!
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
import win32com.client
from pywintypes import com_error
# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.UA.EasyUAClient')
# Obtain attribute data. By default, the Value attribute of a node will be read.
try:
attributeData = client.Read('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
'nsu=http://test.org/UA/Data/ ;i=10853')
except com_error as e:
print('*** Failure: ' + e.args[2][1] + ': ' + e.args[2][2])
exit()
# Display results
print('Value: ', attributeData.Value)
print('ServerTimestamp: ', attributeData.ServerTimestamp)
print('SourceTimestamp: ', attributeData.SourceTimestamp)
print('StatusCode: ', attributeData.StatusCode)
# Example output:
#
#Value: -2.230064E-31
#ServerTimestamp: 11/6/2011 1:34:30 PM
#SourceTimestamp: 11/6/2011 1:34:30 PM
#StatusCode: Good
REM This example shows how to read and display data of an attribute (value, timestamps, and status code).
REM
REM Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
REM OPC client and subscriber examples in Visual Basic on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VB .
REM Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
REM a commercial license in order to use Online Forums, and we reply to every post.
Public Sub Read_Main_Command_Click()
OutputText = ""
' Instantiate the client object
Dim Client As New EasyUAClient
' Obtain attribute data. By default, the Value attribute of a node will be read.
On Error Resume Next
Dim AttributeData As UAAttributeData
Set AttributeData = Client.Read("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", _
"nsu=http://test.org/UA/Data/ ;i=10853")
If Err.Number <> 0 Then
OutputText = OutputText & "*** Failure: " & Err.Source & ": " & Err.Description & vbCrLf
Exit Sub
End If
On Error GoTo 0
' Display results
OutputText = OutputText & "Value: " & AttributeData.value & vbCrLf
OutputText = OutputText & "ServerTimestamp: " & AttributeData.ServerTimestamp & vbCrLf
OutputText = OutputText & "SourceTimestamp: " & AttributeData.SourceTimestamp & vbCrLf
OutputText = OutputText & "StatusCode: " & AttributeData.StatusCode & vbCrLf
' Example output:
'
'Value: -2.230064E-31
'ServerTimestamp: 11/6/2011 1:34:30 PM
'SourceTimestamp: 11/6/2011 1:34:30 PM
'StatusCode: Good
End Sub
Rem This example shows how to read and display data of an attribute (value, timestamps, and status code).
Rem
Rem Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Rem OPC client and subscriber examples in VBScript on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBScript .
Rem Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
Rem a commercial license in order to use Online Forums, and we reply to every post.
Option Explicit
' Instantiate the client object
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")
' Obtain attribute data. By default, the Value attribute of a node will be read.
On Error Resume Next
Dim AttributeData: Set AttributeData = Client.Read("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", _
"nsu=http://test.org/UA/Data/ ;i=10853")
If Err.Number <> 0 Then
WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
WScript.Quit
End If
On Error Goto 0
' Display results
WScript.Echo "Value: " & AttributeData.Value
WScript.Echo "ServerTimestamp: " & AttributeData.ServerTimestamp
WScript.Echo "SourceTimestamp: " & AttributeData.SourceTimestamp
WScript.Echo "StatusCode: " & AttributeData.StatusCode
' Example output:
'
'Value: -2.230064E-31
'ServerTimestamp: 11/6/2011 1:34:30 PM
'SourceTimestamp: 11/6/2011 1:34:30 PM
'StatusCode: Good