Esempio n. 1
0
        static void Main(string[] args)
        {
            // Program setup
            if (1 != args.Length)
            {
                Console.WriteLine(String.Join("\r\n", new string[] {
                    "Please provide reader URL, such as:",
                    "tmr:///com4",
                    "tmr://my-reader.example.com",
                }));
                Environment.Exit(1);
            }

            try
            {
                // Create Reader object, connecting to physical device.
                // Wrap reader in a "using" block to get automatic
                // reader shutdown (using IDisposable interface).
                using (Reader r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
                    {
                        Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
                        if (supportedRegions.Length < 1)
                        {
                            throw new FAULT_INVALID_REGION_Exception();
                        }
                        else
                        {
                            r.ParamSet("/reader/region/id", supportedRegions[0]);
                        }
                    }

                    DenatranIAVCustomTagOperations denatranIavCustomTagOp = new DenatranIAVCustomTagOperations();

                    denatranIavCustomTagOp.reader = r;

                    #region Initialsettings
                    //Initial settings
                    //Set BLF 320KHZ
                    Console.WriteLine(String.Format("Get BLF : {0}", r.ParamGet("/reader/gen2/blf")));
                    Console.WriteLine("Set BLF to 320KHZ");
                    r.ParamSet("/reader/gen2/blf", Gen2.LinkFrequency.LINK320KHZ);
                    Console.WriteLine(String.Format("Get BLF : {0}", r.ParamGet("/reader/gen2/blf")));
                    Console.WriteLine();

                    //Set session
                    Console.WriteLine(String.Format("Get session : {0}", r.ParamGet("/reader/gen2/session")));
                    Console.WriteLine("Set session");
                    r.ParamSet("/reader/gen2/session", Gen2.Session.S0);
                    Console.WriteLine(String.Format("Get session : {0}", r.ParamGet("/reader/gen2/session")));
                    Console.WriteLine();

                    //Set target
                    Console.WriteLine(String.Format("Get target : {0}", r.ParamGet("/reader/gen2/target")));
                    Console.WriteLine("Set target");
                    r.ParamSet("/reader/gen2/target", Gen2.Target.AB);
                    Console.WriteLine(String.Format("Get target : {0}", r.ParamGet("/reader/gen2/target")));
                    Console.WriteLine();

                    //Set tari
                    Console.WriteLine(String.Format("Get tari : {0}", r.ParamGet("/reader/gen2/tari")));
                    Console.WriteLine("Set tari");
                    r.ParamSet("/reader/gen2/tari", Gen2.Tari.TARI_6_25US);
                    Console.WriteLine(String.Format("Get tari : {0}", r.ParamGet("/reader/gen2/tari")));
                    Console.WriteLine();

                    //Set tagencoding
                    Console.WriteLine(String.Format("Get tagencoding : {0}", r.ParamGet("/reader/gen2/tagEncoding")));
                    Console.WriteLine("Set tagencoding");
                    r.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.FM0);
                    Console.WriteLine(String.Format("Get tagencoding : {0}", r.ParamGet("/reader/gen2/tagEncoding")));
                    Console.WriteLine();

                    //Set Q
                    Console.WriteLine(String.Format("Get Q : {0}", r.ParamGet("/reader/gen2/q")));
                    Console.WriteLine("Set Q");
                    Gen2.StaticQ staticQ = new Gen2.StaticQ(0);
                    r.ParamSet("/reader/gen2/q", staticQ);
                    Console.WriteLine(String.Format("Get Q : {0}", r.ParamGet("/reader/gen2/q")));
                    Console.WriteLine();
                    #endregion Initialsettings

                    TagReadData[] tagReads;
                    // Read
                    tagReads = r.Read(500);

                    if (tagReads.Length == 0)
                    {
                        Console.WriteLine("Error : No tags found");
                    }
                    else
                    {
                        #region Filter initialization
                        //Gen2Select filter
                        Gen2.Select selectfilter = new Gen2.Select(false, Gen2.Bank.EPC, 32,
                                                                   (ushort)(tagReads[0].Epc.Length * 8), ByteFormat.FromHex(tagReads[0].EpcString));
                        //TagData filter
                        TagFilter tagdataFilter = new TagData(ByteFormat.FromHex(tagReads[0].EpcString));

                        #endregion Filter initialization

                        #region Tag Operation Initialization

                        byte   payload     = 0x80;
                        ushort readptr     = 0xFFFF;
                        ushort wordAddress = 0xFFFF;
                        ushort word        = 0xFFFF;
                        //Read ptr for readsec tagop
                        ushort readSecReadPtr = 0x0000;
                        //Set the tag Identification and writeCredentials
                        Gen2.DenatranIAVWriteCredential writeCredential = new Gen2.DenatranIAVWriteCredential
                                                                              (new byte [] { 0x80, 0x10, 0x00, 0x12, 0x34, 0xAD, 0xBD, 0xC0 },
                                                                              new byte [] { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF });
                        //Set the data and writeCredentials for WriteSec
                        Gen2.DenatranIAVWriteSecCredential writeSecCredential = new Gen2.DenatranIAVWriteSecCredential
                                                                                    (new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 },
                                                                                    new byte[] { 0x35, 0x49, 0x87, 0xbd, 0xb2, 0xab, 0xd2, 0x7c, 0x2e, 0x34, 0x78, 0x8b, 0xf2, 0xf7, 0x0b, 0xa2 });
                        //IAVDenatran secure tag operation - ActivateSecureMode
                        denatranIavCustomTagOp.tagOpActivateSecureMode = new Gen2.Denatran.IAV.ActivateSecureMode(payload);
                        //IAVDenatran secure tag operation - AuthenticateOBU
                        denatranIavCustomTagOp.tagOpAuthenticateOBU = new Gen2.Denatran.IAV.AuthenticateOBU(payload);
                        //IAVDenatran secure tag operation - ActivateSiniavMode
                        denatranIavCustomTagOp.tagOpActivateSiniavMode = new Gen2.Denatran.IAV.ActivateSiniavMode(0x81, new byte[] { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef });
                        //IAVDenatran secure tag operation - OBUAuthFullPass1
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass1 = new Gen2.Denatran.IAV.OBUAuthFullPass1(payload);
                        //IAVDenatran secure tag operation - OBUAuthFullPass2
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass2 = new Gen2.Denatran.IAV.OBUAuthFullPass2(payload);
                        //IAVDenatran secure tag operation - OBUAuthID
                        denatranIavCustomTagOp.tagOpOBUAuthID = new Gen2.Denatran.IAV.OBUAuthID(payload);
                        //IAVDenatran secure tag operation - OBUReadFromMemMap
                        denatranIavCustomTagOp.tagOpOBUReadFromMemMap = new Gen2.Denatran.IAV.OBUReadFromMemMap
                                                                            (payload, readptr);
                        //IAVDenatran secure tag operation - OBUWriteToMemMap
                        denatranIavCustomTagOp.tagOpOBUWriteToMemMap = new Gen2.Denatran.IAV.OBUWriteToMemMap
                                                                           (payload, wordAddress, word, writeCredential);
                        //IAVDenatran secure tag operation - OBUAuthFullPass
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass = new Gen2.Denatran.IAV.OBUAuthFullPass(payload);
                        //IAVDenatran secure tag operation - GetTokenId
                        denatranIavCustomTagOp.tagOpGetTokenId = new Gen2.Denatran.IAV.GetTokenId();
                        //IAVDenatran secure tag operation - ReadSec
                        denatranIavCustomTagOp.tagOpReadSec = new Gen2.Denatran.IAV.ReadSec
                                                                  (payload, readSecReadPtr);
                        //IAVDenatran secure tag operation - WriteSec
                        denatranIavCustomTagOp.tagOpWriteSec = new Gen2.Denatran.IAV.WriteSec
                                                                   (payload, writeSecCredential);
                        #endregion Tag Operation Initialization

                        #region Standalonetagoperations

                        //Standalone tagop
                        Console.WriteLine("Standalone tagop without filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(null);

                        Console.WriteLine("Standalone tagop with tagdata filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(tagdataFilter);

                        Console.WriteLine("Standalone tagop with gen2Select filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(selectfilter);

                        #endregion Standalonetagoperations

                        #region Embeddedtagoperations

                        //Embedded tagop
                        Console.WriteLine("Embedded tagop without filter and fastsearch : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(null, false);

                        Console.WriteLine("Embedded tagop with tagdata filter and fastsearch enabled : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(tagdataFilter, true);

                        Console.WriteLine("Embedded tagop with gen2select filter and fast search enabled : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(selectfilter, true);

                        #endregion Embeddedtagoperations
                    }
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
        static void Main(string[] args)
        {
            // Program setup
            if (1 > args.Length)
            {
                Usage();
            }
            for (int nextarg = 1; nextarg < args.Length; nextarg++)
            {
                string arg = args[nextarg];
                if (arg.Equals("--ant"))
                {
                    if (null != antennaList)
                    {
                        Console.WriteLine("Duplicate argument: --ant specified more than once");
                        Usage();
                    }
                    antennaList = ParseAntennaList(args, nextarg);
                    nextarg++;
                }
                else
                {
                    Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg);
                    Usage();
                }
            }
            try
            {
                // Create Reader object, connecting to physical device.
                // Wrap reader in a "using" block to get automatic
                // reader shutdown (using IDisposable interface).
                using (Reader r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
                    {
                        Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
                        if (supportedRegions.Length < 1)
                        {
                            throw new FAULT_INVALID_REGION_Exception();
                        }
                        r.ParamSet("/reader/region/id", supportedRegions[0]);
                    }
                    if (r.isAntDetectEnabled(antennaList))
                    {
                        Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
                        Usage();
                    }
                    // Create a simplereadplan which uses the antenna list created above
                    SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000);
                    // Set the created readplan
                    r.ParamSet("/reader/read/plan", plan);

                    //Use first antenna for operation
                    if (antennaList != null)
                    {
                        r.ParamSet("/reader/tagop/antenna", antennaList[0]);
                    }

                    DenatranIAVCustomTagOperations denatranIavCustomTagOp = new DenatranIAVCustomTagOperations();

                    denatranIavCustomTagOp.reader = r;

                    #region EnablingGEN2DenatranIAVTagOps
                    // Serial reader condition is bypassed to add support for Network readers.
                    Console.WriteLine(String.Format("Get Protocol Extension : {0}", r.ParamGet("/reader/gen2/protocolExtension")));
                    Console.WriteLine();


                    #endregion

                    #region Initialsettings
                    //Initial settings
                    //Set tagencoding
                    Console.WriteLine(String.Format("Get tagencoding : {0}", r.ParamGet("/reader/gen2/tagEncoding")));
                    Console.WriteLine("Set tagencoding");
                    r.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.FM0);
                    Console.WriteLine(String.Format("Get tagencoding : {0}", r.ParamGet("/reader/gen2/tagEncoding")));
                    Console.WriteLine();

                    //Set BLF 320KHZ
                    Console.WriteLine(String.Format("Get BLF : {0}", r.ParamGet("/reader/gen2/blf")));
                    Console.WriteLine("Set BLF to 320KHZ");
                    r.ParamSet("/reader/gen2/blf", Gen2.LinkFrequency.LINK320KHZ);
                    Console.WriteLine(String.Format("Get BLF : {0}", r.ParamGet("/reader/gen2/blf")));
                    Console.WriteLine();

                    //Set tari
                    Console.WriteLine(String.Format("Get tari : {0}", r.ParamGet("/reader/gen2/tari")));
                    Console.WriteLine("Set tari");
                    r.ParamSet("/reader/gen2/tari", Gen2.Tari.TARI_6_25US);
                    Console.WriteLine(String.Format("Get tari : {0}", r.ParamGet("/reader/gen2/tari")));
                    Console.WriteLine();

                    //Set session
                    Console.WriteLine(String.Format("Get session : {0}", r.ParamGet("/reader/gen2/session")));
                    Console.WriteLine("Set session");
                    r.ParamSet("/reader/gen2/session", Gen2.Session.S0);
                    Console.WriteLine(String.Format("Get session : {0}", r.ParamGet("/reader/gen2/session")));
                    Console.WriteLine();

                    //Set target
                    Console.WriteLine(String.Format("Get target : {0}", r.ParamGet("/reader/gen2/target")));
                    Console.WriteLine("Set target");
                    r.ParamSet("/reader/gen2/target", Gen2.Target.AB);
                    Console.WriteLine(String.Format("Get target : {0}", r.ParamGet("/reader/gen2/target")));
                    Console.WriteLine();

                    //Set Q
                    Console.WriteLine(String.Format("Get Q : {0}", r.ParamGet("/reader/gen2/q")));
                    Console.WriteLine("Set Q");
                    Gen2.StaticQ staticQ = new Gen2.StaticQ(0);
                    r.ParamSet("/reader/gen2/q", staticQ);
                    Console.WriteLine(String.Format("Get Q : {0}", r.ParamGet("/reader/gen2/q")));
                    Console.WriteLine();
                    #endregion Initialsettings

                    TagReadData[] tagReads;
                    // Read
                    tagReads = r.Read(500);

                    if (tagReads.Length == 0)
                    {
                        Console.WriteLine("Error : No tags found");
                    }
                    else
                    {
                        #region Filter initialization
                        //Gen2Select filter
                        Gen2.Select selectfilter = new Gen2.Select(false, Gen2.Bank.EPC, 32,
                                                                   (ushort)(tagReads[0].Epc.Length * 8), ByteFormat.FromHex(tagReads[0].EpcString));
                        //TagData filter
                        TagFilter tagdataFilter = new TagData(ByteFormat.FromHex(tagReads[0].EpcString));

                        #endregion Filter initialization

                        #region Tag Operation Initialization

                        byte   payload          = 0x80;
                        byte   OBUAuthID        = 0x00;
                        byte   OBUAuthFullPass  = 0x01;
                        byte   OBUAuthFullPass1 = 0x02;
                        ushort readptr          = 0xFFFF;
                        ushort wordAddress      = 0xFFFF;
                        ushort word             = 0xFFFF;
                        //Read ptr for readsec tagop
                        ushort readSecReadPtr = 0x0000;
                        //Set the tag Identification and writeCredentials
                        Gen2.DenatranIAVWriteCredential writeCredential = new Gen2.DenatranIAVWriteCredential
                                                                              (new byte [] { 0x80, 0x10, 0x00, 0x12, 0x34, 0xAD, 0xBD, 0xC0 },
                                                                              new byte [] { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF });
                        //Set the data and writeCredentials for WriteSec
                        Gen2.DenatranIAVWriteSecCredential writeSecCredential = new Gen2.DenatranIAVWriteSecCredential
                                                                                    (new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 },
                                                                                    new byte[] { 0x35, 0x49, 0x87, 0xbd, 0xb2, 0xab, 0xd2, 0x7c, 0x2e, 0x34, 0x78, 0x8b, 0xf2, 0xf7, 0x0b, 0xa2 });
                        //IAVDenatran secure tag operation - ActivateSecureMode
                        denatranIavCustomTagOp.tagOpActivateSecureMode = new Gen2.Denatran.IAV.ActivateSecureMode(payload);
                        //IAVDenatran secure tag operation - AuthenticateOBU
                        denatranIavCustomTagOp.tagOpAuthenticateOBU = new Gen2.Denatran.IAV.AuthenticateOBU(payload);
                        //IAVDenatran secure tag operation - ActivateSiniavMode
                        denatranIavCustomTagOp.tagOpActivateSiniavMode = new Gen2.Denatran.IAV.ActivateSiniavMode(0x81, new byte[] { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef });
                        //IAVDenatran secure tag operation - OBUAuthFullPass1
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass1 = new Gen2.Denatran.IAV.OBUAuthFullPass1(payload);
                        //IAVDenatran secure tag operation - OBUAuthFullPass2
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass2 = new Gen2.Denatran.IAV.OBUAuthFullPass2(payload);
                        //IAVDenatran secure tag operation - OBUAuthID
                        denatranIavCustomTagOp.tagOpOBUAuthID = new Gen2.Denatran.IAV.OBUAuthID(payload);
                        //IAVDenatran secure tag operation - OBUReadFromMemMap
                        denatranIavCustomTagOp.tagOpOBUReadFromMemMap = new Gen2.Denatran.IAV.OBUReadFromMemMap
                                                                            (payload, readptr);
                        //IAVDenatran secure tag operation - OBUWriteToMemMap
                        denatranIavCustomTagOp.tagOpOBUWriteToMemMap = new Gen2.Denatran.IAV.OBUWriteToMemMap
                                                                           (payload, wordAddress, word, writeCredential);
                        //IAVDenatran secure tag operation - OBUAuthFullPass
                        denatranIavCustomTagOp.tagOpOBUAuthFullPass = new Gen2.Denatran.IAV.OBUAuthFullPass(payload);
                        //IAVDenatran secure tag operation - GetTokenId
                        denatranIavCustomTagOp.tagOpGetTokenId = new Gen2.Denatran.IAV.GetTokenId();
                        //IAVDenatran secure tag operation - ReadSec
                        denatranIavCustomTagOp.tagOpReadSec = new Gen2.Denatran.IAV.ReadSec
                                                                  (payload, readSecReadPtr);
                        //IAVDenatran secure tag operation - WriteSec
                        denatranIavCustomTagOp.tagOpWriteSec = new Gen2.Denatran.IAV.WriteSec
                                                                   (payload, writeSecCredential);

                        // For G0 Tag
                        denatranIavCustomTagOp.tagOpG0PAOBUAuth          = new Gen2.Denatran.IAV.G0PAOBUAuth((byte)(payload | OBUAuthID));
                        denatranIavCustomTagOp.tagOpG0PAOBUAuthFullPass  = new Gen2.Denatran.IAV.G0PAOBUAuth((byte)(payload | OBUAuthFullPass));
                        denatranIavCustomTagOp.tagOpG0PAOBUAuthFullPass1 = new Gen2.Denatran.IAV.G0PAOBUAuth((byte)(payload | OBUAuthFullPass1));
                        //Uncomment this  for PA tag
                        //denatranIavCustomTagOp.tagOpG0PAOBUAuth = new Gen2.Denatran.IAV.G0PAOBUAuth(payload);

                        #endregion Tag Operation Initialization

                        #region Standalonetagoperations

                        //Standalone tagop
                        Console.WriteLine("Standalone tagop without filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(null);

                        Console.WriteLine("Standalone tagop with tagdata filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(tagdataFilter);

                        Console.WriteLine("Standalone tagop with gen2Select filter : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.ExecuteTagOpFilter(selectfilter);

                        #endregion Standalonetagoperations

                        #region Embeddedtagoperations

                        //Embedded tagop
                        Console.WriteLine("Embedded tagop without filter and fastsearch : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(null, false);

                        Console.WriteLine("Embedded tagop with tagdata filter and fastsearch enabled : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(tagdataFilter, true);

                        Console.WriteLine("Embedded tagop with gen2select filter and fast search enabled : ");
                        Console.WriteLine();
                        denatranIavCustomTagOp.EmbeddedTagOpFilter(selectfilter, true);

                        #endregion Embeddedtagoperations
                    }
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }