Ejemplo n.º 1
0
        static DecodeError DoWithRetries <A>(int maxRetries, out A datum, MyDelegate <A, DecodeError> f)
        {
            int         retries = 0;
            bool        stop    = false;
            DecodeError res     = DecodeError.Invalid;

            datum = default(A);
            while (!stop)
            {
                res = f(out datum);
                switch (res)
                {
                case DecodeError.IO:
                    if (retries < maxRetries)
                    {
                        retries++;
                        //System.Threading.Thread.Sleep(100);
                        continue;
                    }
                    else
                    {
                        stop = true;     // failed hard
                    }
                    break;

                default:     // invalid or no error
                    stop = true;
                    break;
                }
            }
            return(res);
        }
Ejemplo n.º 2
0
    public void TestMCSUniqueness()
    {
        Dictionary <TagEPCURI_SGTIN, int> TIDmap = new Dictionary <TagEPCURI_SGTIN, int>();

        for (int index = 0; index < _NumTags - 1; index++)
        {
            object          tag  = _Reader.SingulateTagAssisted(index);
            TagEPCURI_SGTIN epc  = default(TagEPCURI_SGTIN);
            taginfo         info = _TagInfos[index];
            TID             tid  = default(TID);

            Console.WriteLine("Testing tag at position {0}", index);

            DecodeError res0 = default(DecodeError);
            res0 = _Reader.ReadTID(tag, out tid);
            Assert.AreEqual(res0, DecodeError.None);

            res0 = _Reader.ReadEPC_SGTIN(tag, out epc);
            Assert.AreEqual(res0, DecodeError.None);

            Console.WriteLine("Generating serial via MCS");

            bool            resB = false;
            TagEPCURI_SGTIN epc1 = default(TagEPCURI_SGTIN);
            resB = MCS.GenerateEPC(ref tid, ref epc, out epc1);
            Assert.AreEqual(resB, true);

            // there should not be any equal values
            Assert.AreEqual(false, TIDmap.ContainsKey(epc1));
            TIDmap.Add(epc1, index);
        }
    }
Ejemplo n.º 3
0
    public void TestEPCConvertibility()
    {
        for (int index = 0; index < _NumTags; index++)
        {
            object          tag  = _Reader.SingulateTagAssisted(index);
            TagEPCURI_SGTIN epc  = default(TagEPCURI_SGTIN);
            taginfo         info = _TagInfos[index];

            Console.WriteLine("Testing tag at position {0}", index);

            DecodeError res0 = default(DecodeError);
            res0 = _Reader.ReadEPC_SGTIN(tag, out epc);
            Assert.AreEqual(res0, DecodeError.None);
            Assert.AreEqual(epc.Identity.URI, info.PureIdentityURI);
            Assert.AreEqual(epc.Identity.GS1CompanyPrefixLength, info.GS1CompanyPrefixLength);

            Console.WriteLine("Trying to round-trip");

            // Round-tripping should produce exactly the same data
            bool res1 = _Reader.WriteEPC(tag, epc);
            Assert.IsTrue(res1);

            TagEPCURI_SGTIN epc1 = default(TagEPCURI_SGTIN);
            res0 = _Reader.ReadEPC_SGTIN(tag, out epc1);
            Assert.AreEqual(res0, DecodeError.None);
            Assert.AreEqual(epc, epc1);
        }
    }
Ejemplo n.º 4
0
    public void TestMCS()
    {
        Console.WriteLine("Testing MCS");

        for (int index = 0; index < _NumTags; index++)
        {
            object          tag  = _Reader.SingulateTagAssisted(index);
            TID             tid  = default(TID);
            TagEPCURI_SGTIN epc  = default(TagEPCURI_SGTIN);
            taginfo         info = _TagInfos[index];

            Console.WriteLine("Testing tag at position {0}", index);

            DecodeError res = default(DecodeError);
            res = _Reader.ReadTID(tag, out tid);
            Assert.AreEqual(res, DecodeError.None);

            DecodeError res0 = _Reader.ReadEPC_SGTIN(tag, out epc);
            Assert.AreEqual(res0, DecodeError.None);

            Console.WriteLine("Generating a new EPC");

            if ((tid.Serial != null) && tid.Serial.Length > 0)
            {
                TagEPCURI_SGTIN epc1 = default(TagEPCURI_SGTIN);
                var             res1 = MCS.GenerateEPC(ref tid, ref epc, out epc1);
                Assert.IsTrue(res1);

                Console.WriteLine("New EPC SGTIN Pure Identity Tag URI {0}", epc1.Identity.URI);

                // Round-tripping should produce exactly the data that we want to see
                //res = _Reader.WriteEPC(tag, epc1)
                //Assert.IsTrue(res)

                //Dim epc1 As TagEPCURI_SGTIN
                //res = _Reader.ReadEPC(tag, epc1)
                //Assert.IsTrue(res)
                //Assert.AreEqual(epc, epc1)
            }
            else
            {
                Console.WriteLine("Skipping, because the TID does not provide a serial number");
            }
        }
    }
Ejemplo n.º 5
0
    public void TestEPCReading()
    {
        for (int index = 0; index < _NumTags; index++)
        {
            object          tag  = _Reader.SingulateTagAssisted(index);
            TID             tid  = default(TID);
            TagEPCURI_SGTIN epc  = default(TagEPCURI_SGTIN);
            taginfo         info = _TagInfos[index];

            Console.WriteLine("Testing tag at position {0}", index);

            DecodeError res = default(DecodeError);
            res = _Reader.ReadTID(tag, out tid);
            Assert.AreEqual(res, DecodeError.None);

            if (!string.IsNullOrEmpty(info.STID_URI))
            {
                Assert.AreEqual(tid.STID_URI, info.STID_URI);
            }
            if ((info.UTID != null) && info.UTID.Length > 0)
            {
                CollectionAssert.AreEqual(tid.Serial, info.UTID);
            }

            DecodeError res0 = default(DecodeError);
            res0 = _Reader.ReadEPC_SGTIN(tag, out epc);
            Assert.AreEqual(res0, DecodeError.None);
            Assert.AreEqual(epc.Identity.URI, info.PureIdentityURI);

            Console.WriteLine("Trying to round-trip");

            // Round-tripping should produce exactly the same data
            bool res1 = _Reader.WriteEPC(tag, epc);
            Assert.IsTrue(res1);

            TagEPCURI_SGTIN epc1 = default(TagEPCURI_SGTIN);
            res0 = _Reader.ReadEPC_SGTIN(tag, out epc1);
            Assert.AreEqual(res0, DecodeError.None);
            Assert.AreEqual(epc, epc1);
        }
    }
Ejemplo n.º 6
0
    public void TestRawTagURIReading()
    {
        StringBuilder sb = new StringBuilder();

        for (int index = 0; index < _NumTags; index++)
        {
            object  tag  = _Reader.SingulateTagAssisted(index);
            TagRaw  raw  = default(TagRaw);
            taginfo info = _TagInfos[index];

            Console.WriteLine("Testing tag at position {0}", index);

            DecodeError res = default(DecodeError);
            res = _Reader.ReadEPC_Raw(tag, out raw);
            Assert.AreEqual(res, DecodeError.None);

            sb.Length = 0;
            raw.GetURI(sb);
            string uri = sb.ToString();
            Assert.AreEqual(uri, info.RawURI);

            // TODO: write the encoding code, and test that it works
        }
    }
Ejemplo n.º 7
0
 private void Error(IntPtr context, DecodeError status, IntPtr userData)
 {
     // Commented out by Alan and replaced with line below because flac files generally still play with bad CRCs
     //throw new ApplicationException(string.Format("FLAC: Could not decode frame: {0}!", status));
     Console.WriteLine("Could not decode frame: " + status);
 }
Ejemplo n.º 8
0
 private void Error(IntPtr context, DecodeError status, IntPtr userData)
 {
     throw new ApplicationException(string.Format("FLAC: Could not decode frame: {0}!", status));
 }
Ejemplo n.º 9
0
 private void Error(IntPtr context, DecodeError status, IntPtr userData)
 {
     // Commented out by Alan and replaced with line below because flac files generally still play with bad CRCs
     //throw new ApplicationException(string.Format("FLAC: Could not decode frame: {0}!", status));
     Console.WriteLine("Could not decode frame: " + status);
 }
Ejemplo n.º 10
0
 private void Error(IntPtr context, DecodeError status, IntPtr userData)
 {
     throw new ApplicationException(string.Format("FLAC: Could not decode frame: {0}!", status));
 }