gOPCClassicConnector.gWriteItems Method

Top  Previous  Next


Writes new values to OPC Items synchronously.

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


VB syntax

gOPCClassicConnector.gWriteItems(ByRef itemsToWrite() As gOPCClassicReadWriteObject)


C# syntax

gOPCClassicConnector.gWriteItems(ref gOPCClassicReadWriteObject[] itemsToWrite)




An aray of ReadWriteObjects that specify OPC Items you want to write to.


Return Type



C# code example



                //Step1: Create an array of read-write object , assign ItemIDs and assign values you want to write

                GelecekCommon.gOPCClassicReadWriteObject[] read_write_objs = new GelecekCommon.gOPCClassicReadWriteObject[2];


                for (int i = 0; i < read_write_objs.Length; i++)


                    read_write_objs[i] = new GelecekCommon.gOPCClassicReadWriteObject();


                read_write_objs[0].ItemID = txtItemID1.Text;

                read_write_objs[0].Value = txtValue1.Text; //Be careful, Text should be able to convert to data type of OPC Node


                read_write_objs[1].ItemID = txtItemID2.Text;

                read_write_objs[1].Value = txtValue2.Text; //Be careful, Text should be able to convert to data type of OPC Node


                //Step2: Run gReadItems method  

                GelecekCommon.gOPCClassicFunctionResult function_result = gOPCClassicConnector1.gWriteItems(ref read_write_objs);


                //Step3: Check function result and ResultID to be sure about a successfull writing

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

                //For writing do not care "Quality

                txtFunctionResult.Text = function_result.ToString();


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

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


                if (function_result != GelecekCommon.gOPCClassicFunctionResult.OK

                    || read_write_objs[0].ResultID != Opc.ResultID.S_OK

                    || read_write_objs[1].ResultID != Opc.ResultID.S_OK)


                    MessageBox.Show("error in writing");



            catch (Exception ex)