gOPCClassicConnector.gConnectItemsAndObjects Method

Top  Previous  Next

Description

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

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

Values of  OPC Items 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 Item.

 

VB syntax

gOPCClassicConnector.gConnectItemsAndObjects(groupName As StringByRef connectionObjects() As gOPCClassicConnectionObject, ByRef updateRate As Integer)

 

C# syntax

gOPCClassicConnector.gConnectItemsAndObjects(string groupName, ref gOPCClassicConnectionObject[] connectionObjects, ref int updateRate)

 

Parameters

groupName

A unique name for group.

 

updateRate

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

Minimum: 100 ms.

 

connectionObjects

An array of connection objects which specifies itemIDs of OPC Items, target controls and  properties of target controls.

 

Return Type

gOPCClassicFunctionResult

 

C# code example for standard .NET controls

  try

            {

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

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

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

                connection_objects[0].ItemID = txtItemID1.Text;

                connection_objects[0].Control = txtValue1;

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

 

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

                connection_objects[1].ItemID = txtItemID2.Text;

                connection_objects[1].Control = txtValue2;

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

 

                int updateRate = Convert.ToInt32(numUpdateRate.Value);

 

                //Step 2: Apply gConnectItemsAndObjects method            

                GelecekCommon.gOPCClassicFunctionResult function_result = gOPCClassicConnector1.gConnectItemsAndObjects(txtGroupName.Text, ref connection_objects, ref updateRate);

 

                txtFunctionResult.Text = function_result.ToString();

 

                //Step3: Check results

                //For a successfull connection, function result should be "OK" and ResultID sould be "S_OK

                if (function_result == GelecekCommon.gOPCClassicFunctionResult.OK)

                {

                    txtResultID1.Text = connection_objects[0].ResultID.ToString();

                    txtResultID2.Text = connection_objects[1].ResultID.ToString();

 

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

 

 

C# code example for Gelecek OPC Client Controls (gNumericBox in this example)

 

      //Creating a connection group to connect Gelecek OPC Client Controls.

            //Please note that These controls have automatic control capability, this is just an example of connecting with Connector.

            //Before this operation, gOPCClassicConnector1 should be connected to OPC Server.

 

            try

            {

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

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

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

                connection_objects[0].ItemID = txtItemID1.Text;

                connection_objects[0].Control = numValue1.gOPC; //assign gOPC property as control

                connection_objects[0].PropertyName = "PLCValue"//Be careful, data type of this OPC Item should be able to convert to data type of PLCValue (double).

 

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

                connection_objects[1].ItemID = txtItemID2.Text;

                connection_objects[1].Control = numValue2.gOPC; //assign gOPC property as control

                connection_objects[1].PropertyName = "PLCValue"//Be careful, data type of this OPC Item should be able to convert to data type of PLCValue (double).

 

                int updateRate = Convert.ToInt32(numUpdateRate.Value);

 

                //Step 2: Apply gConnectItemsAndObjects method            

                GelecekCommon.gOPCClassicFunctionResult function_result = gOPCClassicConnector1.gConnectItemsAndObjects(txtGroupName.Text, ref connection_objects, ref updateRate);

 

                txtFunctionResult.Text = function_result.ToString();

 

                //Step3: Check results

                //For a successfull connection, function result should be "OK" and ResultID sould be "S_OK

                if (function_result == GelecekCommon.gOPCClassicFunctionResult.OK)

                {

                    txtResultID1.Text = connection_objects[0].ResultID.ToString();

                    txtResultID2.Text = connection_objects[1].ResultID.ToString();

 

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

 

            //As a result of connection, values of connected itemIDs will be sent to target controls, target properties

            //Here, Target controls are numValue1.gOPC and numValue2.gOPC, Target properties are PLCValue

 

            //As target controls are Gelecek OPC Client controls, connection is bidirectional..