public static tcFunctionResult tcWriteData(int index, object data)
        {
            if (!tcClient.IsConnected)
            {
                LogMessage(string.Format("Error\t: {0}", "Attempted to write to PLC when not connected"));
                return(tcFunctionResult.TC_NOT_CONNECTED);
            }
            if (index > tcVarList.Count || index < 0)
            {
                LogMessage(string.Format("Error\t: {0}", "Attempted to access a value outside the list"));
                return(tcFunctionResult.TC_VARLIST_OUTOFBOUND);
            }
            AdsStream       _DataStrem     = new AdsStream(tcVarList[index].DataSize);
            AdsBinaryWriter tcStreamWriter = new AdsBinaryWriter(_DataStrem);

            try
            {
                switch (tcVarList[index].VariableType.ToLower())
                {
                case "bool":
                    tcStreamWriter.Write((bool)data);
                    tcClient.Write(tcVarList[index].Handle, _DataStrem);
                    break;

                case "arbool":
                    break;

                case "int":
                    break;

                case "arint":
                    break;

                case "string":
                    break;

                case "real":
                    break;

                case "lreal":
                    break;
                }
                tcStreamWriter.Close();
            }
            catch (Exception ex)
            {
                LogMessage(string.Format("Error at writing data {0}\t: {1}", index.ToString(), ex.Message));
                return(tcFunctionResult.TC_FAIL_TO_WRITE_DATA);
            }
            finally
            {
                tcStreamWriter.Close();
            }
            return(tcFunctionResult.TC_SUCCESS);
        }
        static public tcFunctionResult tcSetAxisCommand(int index, Axis_HmiToPlc COMMAND)
        {
            if (!tcClient.IsConnected)
            {
                return(tcFunctionResult.TC_NOT_CONNECTED);
            }
            if (Axis_MaxAxes <= 0)
            {
                return(tcFunctionResult.TC_NO_AXIS);
            }
            if (index < 0 || index >= Axis_MaxAxes)
            {
                return(tcFunctionResult.TC_AXIS_OUTOFBOUND);
            }

            tcAxCommand[index].CONTROLLER_OVERRIDE = COMMAND.CONTROLLER_OVERRIDE;
            tcAxCommand[index].SERVO_HOME          = COMMAND.SERVO_HOME;
            tcAxCommand[index].SERVO_JOG_BW_FAST   = COMMAND.SERVO_JOG_BW_FAST;
            tcAxCommand[index].SERVO_JOG_BW_SLOW   = COMMAND.SERVO_JOG_BW_SLOW;
            tcAxCommand[index].SERVO_JOG_FW_FAST   = COMMAND.SERVO_JOG_FW_FAST;
            tcAxCommand[index].SERVO_JOG_FW_SLOW   = COMMAND.SERVO_JOG_FW_SLOW;
            tcAxCommand[index].SERVO_JOG_MODE      = COMMAND.SERVO_JOG_MODE;
            tcAxCommand[index].SERVO_MOVE_ABS      = COMMAND.SERVO_MOVE_ABS;
            tcAxCommand[index].SERVO_MOVE_REL      = COMMAND.SERVO_MOVE_REL;
            tcAxCommand[index].SERVO_HALT          = COMMAND.SERVO_HALT;
            tcAxCommand[index].SERVO_OFF           = COMMAND.SERVO_OFF;
            tcAxCommand[index].SERVO_ON            = COMMAND.SERVO_ON;
            tcAxCommand[index].SERVO_ON_BW         = COMMAND.SERVO_ON_BW;
            tcAxCommand[index].SERVO_ON_FW         = COMMAND.SERVO_ON_FW;
            tcAxCommand[index].SERVO_RESET         = COMMAND.SERVO_RESET;
            tcAxCommand[index].TARGET_ACCELERATION = COMMAND.TARGET_ACCELERATION;
            tcAxCommand[index].TARGET_DECELERATION = COMMAND.TARGET_DECELERATION;
            tcAxCommand[index].TARGET_JERK         = COMMAND.TARGET_JERK;
            tcAxCommand[index].TARGET_POSITION     = COMMAND.TARGET_POSITION;
            tcAxCommand[index].TARGET_VELOCITY     = COMMAND.TARGET_VELOCITY;

            AdsStream       _dataStream = new AdsStream(tcAxCommand[index].size);
            AdsBinaryWriter _dataWriter = new AdsBinaryWriter(_dataStream);

            _dataWriter.Write(tcAxCommand[index].TARGET_POSITION);
            _dataWriter.Write(tcAxCommand[index].TARGET_VELOCITY);
            _dataWriter.Write(tcAxCommand[index].TARGET_ACCELERATION);
            _dataWriter.Write(tcAxCommand[index].TARGET_DECELERATION);
            _dataWriter.Write(tcAxCommand[index].TARGET_JERK);
            _dataWriter.Write(tcAxCommand[index].CONTROLLER_OVERRIDE);
            _dataWriter.Write(tcAxCommand[index].SERVO_ON);
            _dataWriter.Write(tcAxCommand[index].SERVO_ON_BW);
            _dataWriter.Write(tcAxCommand[index].SERVO_ON_FW);
            _dataWriter.Write(tcAxCommand[index].SERVO_OFF);
            _dataWriter.Write(tcAxCommand[index].SERVO_MOVE_ABS);
            _dataWriter.Write(tcAxCommand[index].SERVO_MOVE_REL);
            _dataWriter.Write(tcAxCommand[index].SERVO_HALT);
            _dataWriter.Write(tcAxCommand[index].SERVO_HOME);
            _dataWriter.Write(tcAxCommand[index].SERVO_RESET);
            _dataWriter.Write(tcAxCommand[index].SERVO_JOG_MODE);
            _dataWriter.Write(tcAxCommand[index].SERVO_JOG_FW_FAST);
            _dataWriter.Write(tcAxCommand[index].SERVO_JOG_BW_FAST);
            _dataWriter.Write(tcAxCommand[index].SERVO_JOG_FW_SLOW);
            _dataWriter.Write(tcAxCommand[index].SERVO_JOG_BW_SLOW);
            try
            {
                tcClient.Write(tcAxCommand[index].handle, _dataStream);
            }
            catch (Exception ex)
            {
                LogMessage(string.Format("{0}\t: {1}", "Error", "Failed to send Axis Command " + ex.Message));
                _dataWriter.Close();
                return(tcFunctionResult.TC_GENERAL_FAILURE_1);
            }
            _dataWriter.Close();
            return(tcFunctionResult.TC_SUCCESS);
        }