// Shows how to read an OPC item that is of array type. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . // OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp . // 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. using System; using OpcLabs.EasyOpc.DataAccess; using OpcLabs.EasyOpc.OperationModel; namespace DocExamples.DataAccess._EasyDAClient { partial class ReadItemValue { public static void Array() { // Instantiate the client object. var client = new EasyDAClient(); Console.WriteLine("Reading array value..."); int[] value; try { // UInt16 is returned as Int32, because UInt16 is not a CLS-compliant type (and is not supported in VB.NET). value = (int[])client.ReadItemValue("", "OPCLabs.KitServer.2", "Simulation.ReadValue_ArrayOfUI2"); } catch (OpcException opcException) { Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message); return; } if (!(value is null)) { Console.WriteLine(value[0]); Console.WriteLine(value[1]); Console.WriteLine(value[2]); } } } }
' Shows how to read an OPC item that is of array type. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . ' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET . ' 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. Imports OpcLabs.EasyOpc.DataAccess Imports OpcLabs.EasyOpc.OperationModel Namespace DataAccess._EasyDAClient Partial Friend Class ReadItemValue Public Shared Sub Array() Dim client As New EasyDAClient() Console.WriteLine("Reading array value...") Dim value As Int32() Try ' UInt16 is returned as Int32, because UInt16 is not a CLS-compliant type (and is not supported in VB.NET). value = CType(client.ReadItemValue("", "OPCLabs.KitServer.2", "Simulation.ReadValue_ArrayOfUI2"), Int32()) Catch opcException As OpcException Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message) Exit Sub End Try If Not IsNothing(value) Then Console.WriteLine(value(0)) Console.WriteLine(value(1)) Console.WriteLine(value(2)) End If End Sub End Class End Namespace
# Shows how to read an OPC item that is of array type. # # Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . # OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python . # 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. # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc # Import .NET namespaces. from OpcLabs.EasyOpc import * from OpcLabs.EasyOpc.DataAccess import * from OpcLabs.EasyOpc.OperationModel import * # Instantiate the client object client = EasyDAClient() print('Reading array value...') try: # UInt16 is returned as Int32, because UInt16 is not a CLS-compliant type (and is not supported in VB.NET). value = IEasyDAClientExtension.ReadItemValue(client, '', 'OPCLabs.KitServer.2', 'Simulation.ReadValue_ArrayOfUI2') except OpcException as opcException: print('*** Failure: ' + opcException.GetBaseException().Message, sep='') exit() # Display results if value is not None: print(value[0]) print(value[1]) print(value[2])
Copyright © 2004-2024 CODE Consulting and Development, s.r.o., Plzen. All rights reserved.
Documentation Home, Send Documentation Feedback. Technical Support