gOPCClassicConnector.gReadOneItem Method

Top  Previous  Next

Description

Reads value of a single OPC Item from OPC Server synchronously.

This synchronous operation may freeze your application until the end of operation.

 

VB syntax

gOPCClassicConnector.gReadOneItem(ByRef itemToRead As gOPCClassicReadWriteObject)

 

C# syntax

gOPCClassicConnector.gReadOneItem(ref gOPCClassicReadWriteObject itemToRead)

 

Parameters

ItemToRead

A ReadWriteObject that specifies OPC Item you want to read.

 

Return Type

gOPCClassicFunctionResult

 

C# code example

  try

            {

                //Step1: Create a read-write object and assign ItemID

                GelecekCommon.gOPCClassicReadWriteObject read_write_obj = new GelecekCommon.gOPCClassicReadWriteObject();

                read_write_obj.ItemID = txtItemID1.Text;

 

                //Step2: Run gReadOneItem method           

                GelecekCommon.gOPCClassicFunctionResult function_result = gOPCClassicConnector1.gReadOneItem(ref read_write_obj);

 

                //Step3: Check function result, Quality and ResultID, get read value.

                //For a successfull read, function result should be "OK" , ResultID sould be "S_OK" and Quality should be "good"

 

                txtFunctionResult.Text = function_result.ToString();

                txtResultID1.Text = read_write_obj.ResultID.ToString();

                txtQuality1.Text = read_write_obj.Quality.ToString();

 

                if (function_result == GelecekCommon.gOPCClassicFunctionResult.OK && read_write_obj.ResultID == Opc.ResultID.S_OK && read_write_obj.Quality == Opc.Da.Quality.Good)

                {

                    txtValue1.Text = read_write_obj.Value.ToString(); //Be careful, Value should be able to convert to string..

 

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }