Exemplo n.º 1
0
        private bool TryReadUnsignedNumber(
            bool negate,
            out object result,
            IntegerReader tryReadNum,
            FloatReader tryReadFrac,
            char exponentChar,
            int exponent)
        {
            BigInteger num;

            if (tryReadNum(out num))
            {
                if (Expect('.'))
                {
                    FloatLiteral frac;
                    if (!tryReadFrac(out frac))
                    {
                        frac = FloatLiteral.Zero(exponent);
                    }
                    var floatNum = num + frac;

                    if (Expect(exponentChar) || Expect(char.ToUpperInvariant(exponentChar)))
                    {
                        floatNum = floatNum.ChangeBase(exponent);
                        if (!TryAppendExponent(floatNum, out floatNum))
                        {
                            result = null;
                            return(false);
                        }
                    }

                    result = MaybeNegate(floatNum, negate);
                }
                else if (Expect(exponentChar) || Expect(char.ToUpperInvariant(exponentChar)))
                {
                    FloatLiteral floatNum;
                    if (!TryAppendExponent(FloatLiteral.Number(num, exponent), out floatNum))
                    {
                        result = null;
                        return(false);
                    }

                    result = MaybeNegate(floatNum, negate);
                }
                else
                {
                    result = MaybeNegate(num, negate);
                }
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
Exemplo n.º 2
0
        private DataObserver readValue3(DataObserver oldDataObs)
        {
            DataObserver dObs             = oldDataObs;
            string       completeVariable = oldDataObs.PathName;
            int          importOk         = vc.importVariable(completeVariable);
            int          typeVS           = -1;
            long         oldTimeStamp     = oldDataObs.Timestamp;
            long         timeStamp        = 0;
            string       value            = "";

            vc.getType(completeVariable, out typeVS);



            if (importOk != 0 /*&& !oldDataObs.IsChanging*/)
            {
                //vc.waitForConnection(completeVariable,500);
                switch (typeVS)
                {
                ///=================================================================================================
                /// Si le type est égal à 1 alors c'est un entier
                ///=================================================================================================
                case 1:
                    dObs.Type = VS_Type.INTEGER;
                    IntegerReader intr = vc.createIntegerReader(completeVariable);
                    int           valVarInt;

                    if (intr != null)
                    {
                        intr.setBlocking(1 * 20);
                        //intr.waitForEventConnection();
                        VariableState t = intr.waitForFirstValue();

                        if (t == VariableState.Ok)
                        {
                            intr.get(out valVarInt, out timeStamp);
                            value = valVarInt.ToString();
                        }
                    }

                    break;

                ///=================================================================================================
                ///=================================================================================================
                /// Si le type est égal à 2 alors c'est un double
                ///=================================================================================================
                case 2:

                    dObs.Type = VS_Type.DOUBLE;
                    DoubleReader dblr = vc.createDoubleReader(completeVariable);
                    double       valVarDbl;

                    if (dblr != null)
                    {
                        dblr.setBlocking(1 * 20);
                        //dblr.waitForEventConnection();
                        VariableState t = dblr.waitForFirstValue();

                        if (t == VariableState.Ok)
                        {
                            dblr.get(out valVarDbl, out timeStamp);
                            value = valVarDbl.ToString();
                        }
                    }
                    break;

                ///=================================================================================================
                case 3:
                    break;

                ///=================================================================================================
                /// Si le type est égal à 4 alors c'est un Vector Integer (Tableau d'entier)
                ///=================================================================================================

                /*
                 * case 4:
                 *  dObs.Type = VS_Type.VECTOR_INTEGER;
                 *  VectorIntegerReader vecIntReader = vc.createVectorIntegerReader(completeVariable);
                 *  IntegerVector valVarVecInt = new IntegerVector();
                 *
                 *  if (vecIntReader != null)
                 *  {
                 *      vecIntReader.setBlocking(1 * 200);
                 *      VariableState t = vecIntReader.waitForConnection();
                 *
                 *      if (t == VariableState.Ok)
                 *      {
                 *          vecIntReader.get(valVarVecInt, out timeStamp);
                 *          value = tableToString(valVarVecInt);
                 *      }
                 *  }
                 *  break;
                 */
                ///=================================================================================================
                default:
                    dObs.Type = VS_Type.INVALID;
                    value     = "Undefined";
                    break;
                }

                if (!oldDataObs.Value.Equals(value))
                {
                    dObs.Value           = value;
                    dObs.ValueHasChanged = true;
                }
                else
                {
                    dObs.ValueHasChanged = false;
                }
                dObs.Timestamp = timeStamp;
                //dObs.WhenUpdated = howManyTime(oldTimeStamp, dObs.Timestamp);
                dObs.WhenUpdated = createDateTime(dObs.Timestamp);
            }
            displayValues(dObs);
            return(dObs);
        }
Exemplo n.º 3
0
        public void Test_IntegerReader()
        {
            const string raw = "0 5 +5000 -12345 -0 not_number";
            var stream = new MemoryStream(Encoding.ASCII.GetBytes(raw));
            var reader = new IntegerReader(stream, null);

            var obj = reader.Read();
            Assert.IsNotNull(obj);
            Assert.AreEqual(0, obj.Value);

            obj = reader.Read();
            Assert.IsNotNull(obj);
            Assert.AreEqual(5, obj.Value);

            obj = reader.Read();
            Assert.IsNotNull(obj);
            Assert.AreEqual(5000, obj.Value);

            obj = reader.Read();
            Assert.IsNotNull(obj);
            Assert.AreEqual(-12345, obj.Value);

            obj = reader.Read();
            Assert.IsNotNull(obj);
            Assert.AreEqual(0, obj.Value);

            obj = reader.Read();
            Assert.IsNull(obj);

            stream.Dispose();
        }