gOPCUAConnector.gConnectItemsAndObjects Method

Top  Previous  Next

Description

Creates links from OPC Nodes to .NET controls ( Label, Textbox ) unidirectionally.

If target controls are Gelecek OPC Client Controls, link is bidirectional.

Values of  OPC Nodes are automatically written to predefined property of connected controls.

 

If target controls are Gelecek OPC Client Controls, when user enters a new value, it is written to OPC Node.

 

Connection methods create subscriptions.

 

VB syntax

gOPCUAConnector.gConnectItemsAndObjects(subscriptionID As StringByRef connectionObjects() As gOPCUAConnectionObject, ByRef publishingInterval As Integer)

 

C# syntax

gOPCUAConnector.gConnectItemsAndObjects(string subscriptionID, ref gOPCUAConnectionObject[] connectionObjects, ref int publishingInterval) 

 

Parameters

subscriptionID

A unique name for subscription.

 

publishingInterval

Miliseconds. Refreshing period of new values come from OPC Nodes to target controls.

This value might be modified by server, check it after calling method.

 

connectionObjects

An array of connection objects which specifies NodeIDs of OPC Nodes, target controls and  properties of target controls.

 

Return Type

gOPCUAStatusCode

 

C# code example

  try

            {

                //Step1: Create an array of connection objects and assign NodeIDs, target controls, target properties

                GelecekCommon.gOPCUAConnectionObject[] connection_objects = new GelecekCommon.gOPCUAConnectionObject[2];

                connection_objects[0] = new GelecekCommon.gOPCUAConnectionObject();

                connection_objects[0].NodeID = txtNodeID1.Text;

                connection_objects[0].Control = txtValue1;

                connection_objects[0].PropertyName = "Text"//Be careful, data type of OPC Node should be able to convert to data type of this propert

 

                connection_objects[1] = new GelecekCommon.gOPCUAConnectionObject();

                connection_objects[1].NodeID = txtNodeID2.Text;

                connection_objects[1].Control = txtValue2;

                connection_objects[1].PropertyName = "Text"//Be careful, data type of OPC Node should be able to convert to data type of this property

 

                int publishing_interval = Convert.ToInt32(numPublishingInterval.Value);

 

                //Step 2: Apply gConnectItemsAndObjects method            

                GelecekCommon.gOPCUAStatusCode function_result = gOPCUAConnector1.gConnectItemsAndObjects(txtSubscriptionID.Text, ref connection_objects, ref publishing_interval);

 

                txtFunctionResult.Text = function_result.ToString();

 

                //Step3: Check results

                //For a successfull connection, function result should be "Good" and Status code sould be "Good"

                if (function_result == GelecekCommon.gOPCUAStatusCode.Good)

                {

                    txtStatusCode1.Text = connection_objects[0].StatusCode.ToString();

                    txtStatusCode2.Text = connection_objects[1].StatusCode.ToString();

 

                }

 

                //publishing_interval may be changed by server, you can check it here..

 

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }