Exemplo n.º 1
0
        TSetting.TOption[] CreateOptions(TSetting.TRange Range, string[] Options,
                                         string Name)
        {
            if (Range == null || Options == null)
            {
                return(null);
            }

            int[] Ints = CheckIfAllIntegers(Options);
            if (Ints != null)
            {
                TSetting.TOption[] Result = new TSetting.TOption[Ints.Length];
                float SF = GetScaleFactor(Name);
                for (int n = 0; n < Result.Length; n++)
                {
                    Result[n] = new TSetting.TOption((int)(SF * Ints[n]), Options[n]);
                }
                return(Result);
            }

            //Not all integers.
            if (Range == null)
            {
                return(null);
            }
            if (Options.Length == 2)
            {
                //Match up with min and max.
                TSetting.TOption[] Result = new TSetting.TOption[2];
                Result[0] = new TSetting.TOption(Range.Min, Options[0]);
                Result[1] = new TSetting.TOption(Range.Max, Options[1]);
                return(Result);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// A valid line looks like one of the following formats:
        /// Designator:Name:(Type)[Range]=Value{Options}\r\n
        ///     S2:AIR_SPEED(L)[4..1000]=125{4,64,125,250,500,1000,}<\r><\n>
        /// Designator:Name=Value\r\n
        ///     S2:AIR_SPEED=64<\r><\n>
        /// </summary>
        /// <param name="Line">The line.  Must not be null.</param>
        /// <returns>The setting parsed, or null if could not parse setting.</returns>
        TSetting ParseATI5QueryResponseLine(string Line)
        {
            try
            {
                if (Line == "")
                {
                    return(null);
                }

                int    n          = 0;
                string Designator = ParseDesignator(Line, ref n);
                if (Designator == null)
                {
                    return(null);
                }

                n++;
                string Name = ParseName(Line, ref n);
                if (Name == null || Name.Length == 0)
                {
                    return(null);
                }
                TSetting.TRange Range = null;
                if (Line[n] == '(')
                {
                    if (!ParseType(Line, ref n))
                    {
                        return(null);
                    }
                    Range = ParseRange(Line, ref n);
                    if (Range == null)
                    {
                        return(null);
                    }
                }
                if (Line[n] != '=')
                {
                    return(null);
                }
                n++;

                int Value;
                if (!ParseValue(Line, ref n, out Value))
                {
                    return(null);
                }
                string[] Options = null;

                if (n < Line.Length)
                {
                    switch (Line[n])
                    {
                    case '\r':
                        break;

                    case '{':
                        Options = ParseOptions(Line, ref n);
                        break;

                    default:
                        return(null);
                    }
                }

                return(new TSetting(Designator, Name, Range, Value,
                                    CreateOptions(Range, Options, Name), GetIncrement(Name)));
            }
            catch
            {
                return(null);
            }
        }