gOPCClassicConnector.gConnectOneItemAndObject Method

Top  Previous  Next

Description

Creates a link between OPC Item and a .NET control ( Label, Textbox ) unidirectionally.

If target controls are Gelecek OPC Client Controls, lint is bidirectionally.

Value of  OPC Item is automatically written to predefined property of connected control.

 

If target control is Gelecek OPC Client Control, when user enters a new value, it is written to OPC Item.

 

VB syntax

gOPCClassicConnector.gConnectOneItemAndObject(groupName As StringByRef connectionObject As gOPCClassicConnectionObject, ByRef updateRate As Integer)

 

C# syntax

gOPCClassicConnector.gConnectOneItemAndObject(string groupName,  ref  gOPCClassicConnectionObject connectionObject, ref int updateRate)

 

Parameters

groupName

A unique name for group.

 

updateRate

Miliseconds. Refreshing period of new value comes from OPC Item to target control.

Minimum: 100 ms.

 

connectionObject

A connection object which specifies itemID of OPC Item, target control and  property of target control.

 

 

Return Type

gOPCClassicFunctionResult

 

C# code example for standard .NET control

  try

            {              

                GelecekCommon.gOPCClassicConnectionObject connection_object = new GelecekCommon.gOPCClassicConnectionObject();

                connection_object.ItemID = txtItemID1.Text;

                connection_object.Control = txtValue1;

                connection_object.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.gConnectOneItemAndObject(txtGroupName.Text, ref connection_object, 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)

                {

                    txtResultID.Text = connection_object.ResultID.ToString();

 

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

 

 

C# code example for Gelecek OPC Client Control

  try

            {              

                GelecekCommon.gOPCClassicConnectionObject connection_object = new GelecekCommon.gOPCClassicConnectionObject();

                connection_object.ItemID = txtItemID1.Text;

                connection_object.Control = numValue1.gOPC; //assign gOPC property as control

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

 

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

 

                //Step 2: Apply gConnectItemsAndObjects method            

                GelecekCommon.gOPCClassicFunctionResult function_result = gOPCClassicConnector1.gConnectOneItemAndObject(txtGroupName.Text, ref connection_object, 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)

                {

                    txtResultID.Text = connection_object.ResultID.ToString();

 

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }