gOPCUAConnector.gWriteItems Method

Top  Previous  Next


Writes new values to OPC Nodes synchronously.

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


VB syntax

gOPCUAConnector.gWriteItems(ByRef itemsToWrite() As gOPCUAReadWriteObject)


C# syntax

gOPCUAConnector.gWriteItems(ref gOPCUAReadWriteObject[] itemsToWrite)




Array of ReadWriteObjects that hold NodeIDs and values you want to write.


Return Type



C# code example



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

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


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


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


                read_write_objs[0].NodeID = txtNodeID1.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].NodeID = txtNodeID2.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.gOPCUAStatusCode function_result = gOPCUAConnector1.gWriteItems(ref read_write_objs);


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

                //For a successfull write, function result should be "Good" , status code sould be "Good" 


                txtFunctionResult.Text = function_result.ToString();


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

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


                if (function_result != GelecekCommon.gOPCUAStatusCode.Good

                    || read_write_objs[0].StatusCode != GelecekCommon.gOPCUAStatusCode.Good

                    || read_write_objs[1].StatusCode != GelecekCommon.gOPCUAStatusCode.Good)


                    MessageBox.Show("error in writing");



            catch (Exception ex)