static public tcFunctionResult tcGetAxisFeedback(int index, ref Axis_PlcToHmi RESULT)
        {
            if (!tcClient.IsConnected)
            {
                return(tcFunctionResult.TC_NOT_CONNECTED);
            }
            if (Axis_MaxAxes <= 0)
            {
                return(tcFunctionResult.TC_NO_AXIS);
            }
            if (index < 0 || index > Axis_MaxAxes - 1)
            {
                return(tcFunctionResult.TC_AXIS_OUTOFBOUND);
            }

            AdsStream       _DataStream = new AdsStream(tcAxFeedback[index].size);
            AdsBinaryReader _DataReader = new AdsBinaryReader(_DataStream);

            try
            {
                tcClient.Read(tcAxFeedback[index].handle, _DataStream);

                RESULT.actualPosition      = _DataReader.ReadDouble();
                RESULT.actualVelocity      = _DataReader.ReadDouble();
                RESULT.setPosition         = _DataReader.ReadDouble();
                RESULT.setVelocity         = _DataReader.ReadDouble();
                RESULT.controlleroverride  = _DataReader.ReadDouble();
                RESULT.ErrorID             = _DataReader.ReadUInt32();
                RESULT.hasError            = _DataReader.ReadBoolean();
                RESULT.isDisabled          = _DataReader.ReadBoolean();
                RESULT.isFwDisabled        = _DataReader.ReadBoolean();
                RESULT.isBwDisabled        = _DataReader.ReadBoolean();
                RESULT.isCalibrated        = _DataReader.ReadBoolean();
                RESULT.hasJob              = _DataReader.ReadBoolean();
                RESULT.isNotMoving         = _DataReader.ReadBoolean();
                RESULT.isPositiveDirection = _DataReader.ReadBoolean();
                RESULT.isNegativeDirection = _DataReader.ReadBoolean();
                RESULT.isInTarget          = _DataReader.ReadBoolean();
                RESULT.isInRange           = _DataReader.ReadBoolean();
            }
            catch (Exception ex)
            {
                LogMessage(string.Format("{0}\t: {1}", "Error", "Failed to read PlcToHmi" + ex.Message));
                _DataReader.Close();
                return(tcFunctionResult.TC_FAIL_TO_READ_AXIS_FEEDBACK);
            }

            _DataReader.Close();
            return(tcFunctionResult.TC_SUCCESS);
        }
 static public tcFunctionResult tcUpdateAxStatus()
 {
     if (!tcClient.IsConnected)
     {
         return(tcFunctionResult.TC_NOT_CONNECTED);
     }
     if (Axis_MaxAxes <= 0)
     {
         return(tcFunctionResult.TC_NO_AXIS);
     }
     for (int k = 0; k < Axis_MaxAxes; k++)
     {
         AdsStream       _DataStream = new AdsStream(tcAxFeedback[k].size);
         AdsBinaryReader _DataReader = new AdsBinaryReader(_DataStream);
         try
         {
             tcClient.Read(tcAxFeedback[k].handle, _DataStream);
             tcAxFeedback[k].actualPosition      = _DataReader.ReadDouble();
             tcAxFeedback[k].actualVelocity      = _DataReader.ReadDouble();
             tcAxFeedback[k].setPosition         = _DataReader.ReadDouble();
             tcAxFeedback[k].setVelocity         = _DataReader.ReadDouble();
             tcAxFeedback[k].controlleroverride  = _DataReader.ReadDouble();
             tcAxFeedback[k].isDisabled          = _DataReader.ReadBoolean();
             tcAxFeedback[k].isFwDisabled        = _DataReader.ReadBoolean();
             tcAxFeedback[k].isBwDisabled        = _DataReader.ReadBoolean();
             tcAxFeedback[k].isCalibrated        = _DataReader.ReadBoolean();
             tcAxFeedback[k].hasJob              = _DataReader.ReadBoolean();
             tcAxFeedback[k].isNotMoving         = _DataReader.ReadBoolean();
             tcAxFeedback[k].isPositiveDirection = _DataReader.ReadBoolean();
             tcAxFeedback[k].isNegativeDirection = _DataReader.ReadBoolean();
             tcAxFeedback[k].isInTarget          = _DataReader.ReadBoolean();
             tcAxFeedback[k].isInRange           = _DataReader.ReadBoolean();
         }
         catch (Exception ex)
         {
             LogMessage(string.Format("{0}\t: {1}", "Error", "Failed to read PlcToHmi" + ex.Message));
             _DataReader.Close();
             return(tcFunctionResult.TC_FAIL_TO_READ_AXIS_FEEDBACK);
         }
         _DataReader.Close();
     }
     return(tcFunctionResult.TC_SUCCESS);
 }
        static public Axis_PlcToHmi tcGetAxsPlcToHmi(int index)
        {
            if (!tcClient.IsConnected)
            {
                return(null);
            }
            if (Axis_MaxAxes <= 0)
            {
                return(null);
            }
            if (index < 0 || index > Axis_MaxAxes - 1)
            {
                return(null);
            }

            AdsStream       _DataStream = new AdsStream(tcAxFeedback[index].size);
            AdsBinaryReader _DataReader = new AdsBinaryReader(_DataStream);

            try
            {
                Axis_PlcToHmi _buffer = new Axis_PlcToHmi();
                tcClient.Read(tcAxFeedback[index].handle, _DataStream);
                _buffer.actualPosition      = _DataReader.ReadDouble();
                _buffer.actualVelocity      = _DataReader.ReadDouble();
                _buffer.setPosition         = _DataReader.ReadDouble();
                _buffer.setVelocity         = _DataReader.ReadDouble();
                _buffer.controlleroverride  = _DataReader.ReadDouble();
                _buffer.ErrorID             = _DataReader.ReadUInt32();
                _buffer.hasError            = _DataReader.ReadBoolean();
                _buffer.isDisabled          = _DataReader.ReadBoolean();
                _buffer.isFwDisabled        = _DataReader.ReadBoolean();
                _buffer.isBwDisabled        = _DataReader.ReadBoolean();
                _buffer.isCalibrated        = _DataReader.ReadBoolean();
                _buffer.hasJob              = _DataReader.ReadBoolean();
                _buffer.isNotMoving         = _DataReader.ReadBoolean();
                _buffer.isPositiveDirection = _DataReader.ReadBoolean();
                _buffer.isNegativeDirection = _DataReader.ReadBoolean();
                _buffer.isInTarget          = _DataReader.ReadBoolean();
                _buffer.isInRange           = _DataReader.ReadBoolean();
                return(_buffer);
            }
            catch (Exception ex)
            {
                LogMessage(string.Format("{0}\t: {1}", "Error", "Failed to read PlcToHmi" + ex.Message));
                _DataReader.Close();
                return(null);
            }
        }
        public static tcFunctionResult tcReadAll()
        {
            if (!tcClient.IsConnected)
            {
                return(tcFunctionResult.TC_NOT_CONNECTED);
            }
            for (int i = 0; i < tcVarList.Count; i++)
            {
                AdsStream       tcDataStream   = new AdsStream(tcVarList[i].DataSize);
                AdsBinaryReader tcStreamReader = new AdsBinaryReader(tcDataStream);
                try
                {
                    tcClient.Read(tcVarList[i].Handle, tcDataStream);
                }
                catch (Exception ex)
                {
                    LogMessage(string.Format("{0}\t: {1}", "Failed to read from device", ex.Message));
                    return(tcFunctionResult.TC_FAIL_TO_READ_DATA);
                }
                tcPlcVar buffer = tcVarList[i];
                switch (tcVarList[i].VariableType.ToLower())
                {
                case "bool":
                    buffer.Data = tcStreamReader.ReadBoolean();
                    break;

                case "arbool":
                    bool[] boolBuffer = new bool[buffer.Count];
                    for (int j = 0; j < boolBuffer.Length; j++)
                    {
                        boolBuffer[j] = tcStreamReader.ReadBoolean();
                    }
                    buffer.Data = (object)boolBuffer;
                    break;

                case "int":
                    buffer.Data = tcStreamReader.ReadInt16();
                    break;

                case "arint":
                    short[] shortBuffer = new short[buffer.Count];
                    for (int j = 0; j < shortBuffer.Length; j++)
                    {
                        shortBuffer[j] = tcStreamReader.ReadInt16();
                    }
                    buffer.Data = (object)shortBuffer;
                    break;

                case "string":
                    buffer.Data = tcStreamReader.ReadPlcString(255);
                    break;

                case "real":
                    buffer.Data = tcStreamReader.ReadSingle();
                    break;

                case "lreal":
                    buffer.Data = tcStreamReader.ReadDouble();
                    break;
                }
                tcVarList[i] = buffer;
                tcStreamReader.Close();
            }
            return(tcFunctionResult.TC_SUCCESS);
        }