Exemplo n.º 1
0
        /// <summary>
        /// Each subdir of <paramref name="rootDirectory"/> is considered a project.
        /// </summary>
        /// <param name="rootDirectory">the root path to start scanning from</param>
        /// <param name="scanner">the scanner to use</param>
        /// <returns></returns>
        public IEnumerable<ProjectBuilder> CreateProjectBuilders(string rootDirectory, IResourceIdFactory resourceIdFactory, IComponentFactory componentFactory)
        {
            foreach (var dir in GetProjectDirectories(rootDirectory))
            {
                if (IsExcluded(dir))
                    continue;

                var filter = new MultiFilter<string>(Configuration.FileFilters);
                ProjectBuilder builder = new ProjectBuilder(dir, filter, resourceIdFactory, componentFactory);

                yield return builder;
            }
        }
Exemplo n.º 2
0
 private void Processor(Bitmap[] bitmap, MultiFilter filter)
 {
     // check if null
     if (bitmap != null)
     {
         Cursor = Cursors.WaitCursor;
         Image  = (filter != null) ? filter(bitmap) : null; // not implemented
         GetHistogram(Image);
         ResetAdjustments();
         pictureBox1.Image = Image;
         Cursor            = Cursors.Arrow;
     }
     return;
 }
Exemplo n.º 3
0
        // read multiple registers from one tag singulated by its EPC
        public static short[] ReadMemBlockByEpc(Reader reader, TagReadData tag, Gen2.Bank bank, int address, int length, int attempts)
        {
            Gen2.Select resetFilter = CreateGen2Select(4, 4, Gen2.Bank.TID, 0x00, 16, new byte[] { 0xE2, 0x82 });
            Gen2.Select epcFilter   = CreateGen2Select(4, 0, Gen2.Bank.EPC, 0x20, tag.Epc.Length * 8, tag.Epc);
            MultiFilter selects     = new MultiFilter(new Gen2.Select[] { resetFilter, epcFilter });

            Gen2.ReadData  operation = new Gen2.ReadData(bank, (uint)address, (byte)length);
            SimpleReadPlan config    = new SimpleReadPlan(new int[] { tag.Antenna }, TagProtocol.GEN2, selects, operation, 1000);

            short[] values = null;
            try
            {
                reader.ParamSet("/reader/read/plan", config);
                for (int i = 0; i < attempts; i++)
                {
                    if (values != null)
                    {
                        break;
                    }
                    TagReadData[] readResults = reader.Read(readTime);
                    foreach (TagReadData readResult in readResults)
                    {
                        if (tag.EpcString.Equals(readResult.EpcString))
                        {
                            byte[] dataBytes = readResult.Data;
                            if (dataBytes.Length != 0)
                            {
                                values = ConvertByteArrayToShortArray(dataBytes);
                                break;
                            }
                        }
                    }
                }
            }
            catch (ReaderException e)
            {
                Console.WriteLine("Error: " + e.ToString());
                Environment.Exit(-1);
            }
            if (values == null)
            {
                throw new SystemException("Tag not found");
            }
            return(values);
        }
Exemplo n.º 4
0
        ///<inheritdoc/>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            MultiFilter multiFilter = null;

            JToken token = JToken.ReadFrom(reader);

            if (objectType == typeof(MultiFilter) && token.Type == JTokenType.Object)
            {
                IEnumerable <JProperty> properties = ((JObject)token).Properties();

                JProperty logicProperty = properties.SingleOrDefault(prop => prop.Name == MultiFilter.LogicJsonPropertyName);

                if (logicProperty != null)
                {
                    JProperty filtersProperty = properties.SingleOrDefault(prop => prop.Name == MultiFilter.FiltersJsonPropertyName);
                    if (filtersProperty is JProperty prop && filtersProperty.Value.Type == JTokenType.Array)
                    {
                        JArray filtersArray = token[MultiFilter.FiltersJsonPropertyName].Value <JArray>();
                        int    nbFilters    = filtersArray.Count();
                        if (nbFilters >= 2)
                        {
                            IList <IFilter> filters = new List <IFilter>(nbFilters);
                            foreach (JToken item in filtersArray)
                            {
                                IFilter kf = (IFilter)item.ToObject <Filter>() ?? item.ToObject <MultiFilter>();
                                filters.Add(kf);
                            }

                            multiFilter = new MultiFilter
                            {
                                Logic   = _logics[token[MultiFilter.LogicJsonPropertyName].Value <string>()],
                                Filters = filters
                            };
                        }
                    }
                }
            }

            return(multiFilter?.As(objectType));
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            try
            {
                // connect to and initialize reader
                Reader reader = Common.EstablishReader();

                // setup sensor activation commands and filters ensuring On-Chip RSSI Min Filter is applied
                Gen2.Select globalEnable    = Common.CreateGen2Select(4, 2, Gen2.Bank.USER, 0x3B0, 8, new byte[] { (byte)0x00 });
                Gen2.Select ocrssiMinFilter = Common.CreateGen2Select(4, 0, Gen2.Bank.USER, 0x3D0, 8, new byte[] { (byte)(0x20 | ocrssiMin - 1) });
                Gen2.Select ocrssiMaxFilter = Common.CreateGen2Select(4, 2, Gen2.Bank.USER, 0x3D0, 8, new byte[] { ocrssiMax });
                MultiFilter selects         = new MultiFilter(new Gen2.Select[] { globalEnable, ocrssiMinFilter, ocrssiMaxFilter });

                // parameters to read all three sensor codes at once
                Gen2.ReadData operation = new Gen2.ReadData(Gen2.Bank.RESERVED, 0xA, (byte)5);

                // create configuration
                SimpleReadPlan config = new SimpleReadPlan(Common.antennas, TagProtocol.GEN2, selects, operation, 1000);

                for (int i = 1; i <= readAttempts; i++)
                {
                    Console.WriteLine("\nRead Attempt #" + i);

                    // optimize settings for reading sensors
                    reader.ParamSet("/reader/read/plan", config);
                    reader.ParamSet("/reader/gen2/t4", (UInt32)9000);  // CW delay in microseconds
                    reader.ParamSet("/reader/gen2/session", Common.session);
                    reader.ParamSet("/reader/gen2/q", new Gen2.DynamicQ());

                    // attempt to read sensor tags
                    TagReadData[] results = reader.Read(Common.readTime);

                    reader.ParamSet("/reader/gen2/t4", (UInt32)300);
                    reader.ParamSet("/reader/gen2/session", Gen2.Session.S0);
                    reader.ParamSet("/reader/gen2/q", new Gen2.StaticQ(0));

                    if (results.Length != 0)
                    {
                        foreach (TagReadData tag in results)
                        {
                            String epc = tag.EpcString;
                            Console.WriteLine("* EPC: " + epc);
                            byte[]  dataBytes = tag.Data;
                            short[] dataWords = Common.ConvertByteArrayToShortArray(dataBytes);
                            if (dataWords.Length != 0)
                            {
                                int backport1Code   = dataWords[0];
                                int backport2Code   = dataWords[1];
                                int moistureCode    = dataWords[2];
                                int ocrssiCode      = dataWords[3];
                                int temperatureCode = dataWords[4];

                                // On-Chip RSSI Sensor
                                Console.WriteLine("  - On-Chip RSSI: " + ocrssiCode);

                                // Moisture Sensor
                                String moistureStatus;
                                if (ocrssiCode < 5)
                                {
                                    moistureStatus = "power too low";
                                }
                                else if (ocrssiCode > 21)
                                {
                                    moistureStatus = "power too high";
                                }
                                else
                                {
                                    moistureStatus = moistureCode + " at " + tag.Frequency + " kHz";
                                }
                                Console.WriteLine("  - Moisture: " + moistureStatus);

                                // Temperature Sensor
                                String temperatureStatus;
                                if (ocrssiCode < 5)
                                {
                                    temperatureStatus = "power too low";
                                }
                                else if (ocrssiCode > 18)
                                {
                                    temperatureStatus = "power too high";
                                }
                                else if (temperatureCode < 1000 || 3500 < temperatureCode)
                                {
                                    temperatureStatus = "bad read";
                                }
                                else
                                {
                                    try
                                    {
                                        // read, decode and apply calibration one tag at a time
                                        short[] calibrationWords   = Common.ReadMemBlockByEpc(reader, tag, Gen2.Bank.USER, 0x12, 4);
                                        TemperatureCalibration cal = new TemperatureCalibration(calibrationWords);
                                        if (cal.valid)
                                        {
                                            double temperatureValue = cal.slope * temperatureCode + cal.offset;
                                            temperatureStatus = temperatureValue.ToString("0.00") + " degC";
                                        }
                                        else
                                        {
                                            temperatureStatus = "invalid calibration";
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        temperatureStatus = "failed to read calibration";
                                    }
                                }
                                Console.WriteLine("  - Temperature: " + temperatureStatus);

                                // Backport 1 Sensor
                                String backport1Status;
                                if (ocrssiCode < 5)
                                {
                                    backport1Status = "power too low";
                                }
                                else if (ocrssiCode > 18)
                                {
                                    backport1Status = "power too high";
                                }
                                else
                                {
                                    backport1Status = backport1Code + "";
                                }
                                Console.WriteLine("  - Backport 1: " + backport1Status);

                                // Backport 1 Sensor
                                String backport2Status;
                                if (ocrssiCode < 5)
                                {
                                    backport2Status = "power too low";
                                }
                                else if (ocrssiCode > 18)
                                {
                                    backport2Status = "power too high";
                                }
                                else
                                {
                                    backport2Status = backport2Code + "";
                                }
                                Console.WriteLine("  - Backport 2: " + backport2Status);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("No tag(s) found");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.ToString());
                Environment.Exit(-1);
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            try
            {
                // connect to and initialize reader
                Reader reader = Common.EstablishReader();

                // setup sensor activation commands and filters ensuring On-Chip RSSI Min Filter is applied
                Gen2.Select tempsensorEnable = Common.CreateGen2Select(4, 4, Gen2.Bank.TID, 0x00, 16, new byte[] { (byte)0xE2, (byte)0x82 });
                Gen2.Select ocrssiMinFilter  = Common.CreateGen2Select(4, 0, Gen2.Bank.USER, 0xA0, 8, new byte[] { (byte)(0x20 | ocrssiMin - 1) });
                Gen2.Select ocrssiMaxFilter  = Common.CreateGen2Select(4, 2, Gen2.Bank.USER, 0xA0, 8, new byte[] { ocrssiMax });
                MultiFilter selects          = new MultiFilter(new Gen2.Select[] { tempsensorEnable, ocrssiMinFilter, ocrssiMaxFilter });

                Gen2.ReadData operation;
                if (moistureMode)
                {
                    // read parameters for moisture code
                    operation = new Gen2.ReadData(Gen2.Bank.RESERVED, 0xB, (byte)1);
                }
                else
                {
                    // read parameters for on-chip RSSI code
                    operation = new Gen2.ReadData(Gen2.Bank.RESERVED, 0xD, (byte)1);
                }

                // create configuration
                SimpleReadPlan config = new SimpleReadPlan(Common.antennas, TagProtocol.GEN2, selects, operation, 1000);
                reader.ParamSet("/reader/read/plan", config);

                for (int i = 1; i <= readAttempts; i++)
                {
                    Console.WriteLine("Read Attempt #" + i);

                    // attempt to read sensor tags
                    TagReadData[] results = reader.Read(Common.readTime);

                    if (results.Length != 0)
                    {
                        foreach (TagReadData tag in results)
                        {
                            String epc = tag.EpcString;
                            Console.WriteLine("* EPC: " + epc);
                            byte[]  dataBytes = tag.Data;
                            short[] dataWords = Common.ConvertByteArrayToShortArray(dataBytes);
                            if (dataWords.Length != 0)
                            {
                                if (moistureMode)
                                {
                                    Console.WriteLine("  - Moisture: " + dataWords[0] + " at " + tag.Frequency + " kHz");
                                }
                                else
                                {
                                    Console.WriteLine("  - On-Chip RSSI: " + dataWords[0]);
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("No tag(s) found");
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.ToString());
                Environment.Exit(-1);
            }
        }
Exemplo n.º 7
0
        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 (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]);
                    }
                    string model = (string)r.ParamGet("/reader/version/model").ToString();
                    if (!model.Equals("M3e"))
                    {
                        if (r.isAntDetectEnabled(antennaList))
                        {
                            Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
                            Usage();
                        }
                        //Use first antenna for operation
                        if (antennaList != null)
                        {
                            r.ParamSet("/reader/tagop/antenna", antennaList[0]);
                        }
                    }
                    else
                    {
                        if (antennaList != null)
                        {
                            Console.WriteLine("Module doesn't support antenna input");
                            Usage();
                        }
                    }

                    // This select filter matches all Gen2 tags where bits 32-48 of the EPC are 0x0123
#if ENABLE_FILTER
                    TagFilter filter = new Gen2.Select(false, Gen2.Bank.EPC, 32, 16, new byte[] { 0x01, 0x23 });
#endif
                    if (!model.Equals("M3e"))
                    {
                        //Gen2.TagData epc = new Gen2.TagData(new byte[] {
                        //    0x01, 0x23, 0x45, 0x67, 0x89, 0xAB,
                        //    0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67,
                        //});
                        //Gen2.WriteTag tagop = new Gen2.WriteTag(epc);
                        //r.ExecuteTagOp(tagop, null);
                    }

                    // Reads data from a tag memory bank after writing data to the requested memory bank without powering down of tag
#if ENABLE_READ_AFTER_WRITE
                    {
                        //create a tagopList with write tagop followed by read tagop
                        TagOpList tagopList = new TagOpList();
                        byte      wordCount;
                        ushort[]  readData;

                        //Write one word of data to USER memory and read back 8 words from EPC memory using WriteData and ReadData
                        {
                            ushort[] writeData = { 0x9999 };
                            wordCount = 8;
                            Gen2.WriteData wData = new Gen2.WriteData(Gen2.Bank.USER, 2, writeData);
                            Gen2.ReadData  rData = new Gen2.ReadData(Gen2.Bank.EPC, 0, wordCount);
                            //Gen2.WriteTag wTag = new Gen2.WriteTag(epc);

                            // assemble tagops into list
                            tagopList.list.Add(wData);
                            tagopList.list.Add(rData);

                            Console.WriteLine("###################Embedded Read after write######################");
                            // uncomment the following for embedded read after write.
                            embeddedRead(TagProtocol.GEN2, null, tagopList);

                            // call executeTagOp with list of tagops
                            //readData = (ushort[])r.ExecuteTagOp(tagopList, null);
                            //Console.WriteLine("ReadData: ");
                            //foreach (ushort word in readData)
                            //{
                            //    Console.Write(" {0:X4}", word);
                            //}
                            //Console.WriteLine("\n");
                        }

                        //clearing the list for next operation
                        tagopList.list.Clear();

                        //Write 12 bytes(6 words) of EPC and read back 8 words from EPC memory using WriteTag and ReadData
                        {
                            Gen2.TagData epc1 = new Gen2.TagData(new byte[] {
                                0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
                                0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc,
                            });
                            wordCount = 8;
                            Gen2.WriteTag wtag  = new Gen2.WriteTag(epc1);
                            Gen2.ReadData rData = new Gen2.ReadData(Gen2.Bank.EPC, 0, wordCount);

                            // assemble tagops into list
                            tagopList.list.Add(wtag);
                            tagopList.list.Add(rData);

                            // call executeTagOp with list of tagops
                            //readData = (ushort[])r.ExecuteTagOp(tagopList, null);
                            //Console.WriteLine("ReadData: ");
                            //foreach (ushort word in readData)
                            //{
                            //    Console.Write(" {0:X4}", word);
                            //}
                            //Console.WriteLine("\n");
                        }
                    }
#endif

                    // Perform read and print UID and tagtype of tag found
                    SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.ISO15693, null, null, 1000);
                    r.ParamSet("/reader/read/plan", plan);
                    TagReadData[] tagReads = r.Read(1000);
                    Console.WriteLine("UID: " + tagReads[0].EpcString);
                    Console.WriteLine("TagType:  " + (Iso15693.TagType)(tagReads[0].TagType));
                    MemoryType  type;
                    MultiFilter mulfilter = null;
                    UInt32      address;
                    byte        length;

#if ENABLE_M3E_FILTER
                    //Initialize filter
                    // Filters the tag based on tagtype
                    TagFilter tagTypeFilter = new Select_TagType((UInt64)((Iso15693.TagType)(tagReads[0].TagType)));
                    // Filters the tag based on UID
                    TagFilter uidFilter = new Select_UID(32, ByteFormat.FromHex(tagReads[0].Tag.EpcString.Substring(0, 8)));
                    // Initialize multi filter
                    mulfilter = new MultiFilter(new TagFilter[] { tagTypeFilter, uidFilter });
#endif

#if ENABLE_M3E_BLOCK_READ_WRITE
                    //Initialize all the fields required for Read Data Tag operation
                    type    = MemoryType.BLOCK_MEMORY;
                    address = 0;
                    length  = 1;

                    // Read memory before write
                    ReadMemory bRead    = new ReadMemory(type, address, length);
                    byte[]     dataRead = (byte[])r.ExecuteTagOp(bRead, mulfilter);

                    // prints the data read
                    Console.WriteLine("Read Data before performing block write: ");
                    foreach (byte i in dataRead)
                    {
                        Console.Write(" {0:X2}", i);
                    }
                    Console.WriteLine("\n");
                    // Uncomment this to enable Embedded read memory
                    //embeddedRead(TagProtocol.ISO15693, mulfilter, bRead);

                    // Initialize write memory
                    byte[]      data    = new byte[] { 0x11, 0x22, 0x33, 0x44 };
                    WriteMemory writeOp = new WriteMemory(type, address, data);

                    // Execute the tagop
                    r.ExecuteTagOp(writeOp, mulfilter);
                    // Uncomment this to enable Embedded write data
                    //embeddedRead(TagProtocol.ISO15693, mulfilter, writeOp);

                    //Read memory after block write
                    ReadMemory readOp   = new ReadMemory(type, address, length);
                    byte[]     readData = (byte[])r.ExecuteTagOp(readOp, mulfilter);

                    // prints the data read
                    Console.WriteLine("Read Data after performing block write operation: ");
                    foreach (byte i in readData)
                    {
                        Console.Write(" {0:X2}", i);
                    }
                    Console.WriteLine("\n");
#endif

#if ENABLE_M3E_SYSTEM_INFORMATION_MEMORY
                    //Get the system information of tag. Address and length fields have no significance if memory type is BLOCK_SYSTEM_INFORMATION_MEMORY.
                    type    = MemoryType.BLOCK_SYSTEM_INFORMATION_MEMORY;
                    address = 0;
                    length  = 0;
                    ReadMemory sysInfoOp  = new ReadMemory(type, address, length);
                    byte[]     systemInfo = (byte[])r.ExecuteTagOp(sysInfoOp, mulfilter);

                    // parsing the system info response
                    if (systemInfo.Length > 0)
                    {
                        parseGetSystemInfoResponse(systemInfo);
                    }
#endif

#if ENABLE_M3E_SECURE_ID
                    // Read secure id of tag. Address and length fields have no significance if memory type is SECURE_ID.
                    type    = MemoryType.SECURE_ID;
                    address = 0;
                    length  = 0;
                    ReadMemory secureIdOp = new ReadMemory(type, address, length);
                    byte[]     rspData    = (byte[])r.ExecuteTagOp(secureIdOp, mulfilter);

                    // parse secure id operation response.
                    if (rspData.Length > 0)
                    {
                        parseSecureIdResponse(rspData);
                    }
#endif

#if ENABLE_M3E_BLOCK_PROTECTION_STATUS
                    // Get the block protection status of block 0.
                    type    = MemoryType.BLOCK_PROTECTION_STATUS_MEMORY;
                    address = 0;
                    length  = 1;
                    ReadMemory blkProtectionOp = new ReadMemory(type, address, length);
                    byte[]     statusData      = (byte[])r.ExecuteTagOp(blkProtectionOp, mulfilter);

                    // parse the block protection status response.
                    if (statusData.Length == length)
                    {
                        parseGetBlockProtectionStatusResponse(statusData, address, length);
                    }
#endif
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Exemplo n.º 8
0
        public static List <int> Filter(List <int> intList, SingleFilter singleFilter, MultiFilter multiFilter)
        {
            var intListCopy = new List <int>(intList);  // create copy - only works for value types

            for (int i = 0; i < intListCopy.Count; i++)
            {
                if (!singleFilter(intListCopy[i]))
                {
                    intListCopy.Remove(intListCopy[i]);
                    i--;  // reset counter one step if element was removed
                }
            }
            multiFilter(intListCopy);

            return(intListCopy);
        }
 public void LoadFromConfiguration()
 {
     filter = (MultiFilter)NetReflector.Read(@"<multiFilter><filters><actionFilter><actions><action>Delete</action></actions></actionFilter>
                                                 <userFilter><names><name>bob</name><name>perry</name></names></userFilter></filters></multiFilter>");
     Assert.AreEqual(2, filter.Filters.Length);
 }
 protected void CreateFilter()
 {
     filter = new MultiFilter();
 }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            // Program setup
            if (1 > args.Length)
            {
                Usage();
            }
            int[] antennaList = null;
            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();
                }
            }

            // Create Reader object, connecting to physical device
            try
            {
                Reader        r;
                TagReadData[] tagReads, filteredTagReads;
                TagFilter     filter;

                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();
                }

                // In the current system, sequences of Gen2 operations require Session 0,
                // since each operation resingulates the tag.  In other sessions,
                // the tag will still be "asleep" from the preceding singulation.
                Gen2.Session oldSession = (Gen2.Session)r.ParamGet("/reader/gen2/session");
                Gen2.Session newSession = Gen2.Session.S0;
                Console.WriteLine("Changing to Session " + newSession + " (from Session " + oldSession + ")");
                r.ParamSet("/reader/gen2/session", newSession);
                Console.WriteLine();

                SimpleReadPlan srp = new SimpleReadPlan(antennaList, TagProtocol.GEN2);
                r.ParamSet("/reader/read/plan", srp);
                //To perform standalone operations
                if (antennaList != null)
                {
                    r.ParamSet("/reader/tagop/antenna", antennaList[0]);
                }

                try
                {
                    Console.WriteLine("Unfiltered Read:");
                    // Read the tags in the field
                    tagReads = r.Read(500);
                    foreach (TagReadData tr in tagReads)
                    {
                        Console.WriteLine(tr.ToString());
                    }
                    Console.WriteLine();

                    if (0 == tagReads.Length)
                    {
                        Console.WriteLine("No tags found.");
                    }
                    else
                    {
                        // A TagData object may be used as a filter, for example to
                        // perform a tag data operation on a particular tag.
                        Console.WriteLine("Filtered Tagop:");
                        // Read kill password of tag found in previous operation
                        filter = tagReads[0].Tag;
                        Console.WriteLine("Read kill password of tag {0}", filter);
                        Gen2.ReadData tagop = new Gen2.ReadData(Gen2.Bank.RESERVED, 0, 2);
                        try
                        {
                            ushort[] data = (ushort[])r.ExecuteTagOp(tagop, filter);
                            foreach (ushort word in data)
                            {
                                Console.Write("{0:X4}", word);
                            }
                            Console.WriteLine();
                        }
                        catch (ReaderException ex)
                        {
                            Console.WriteLine("Can't read tag: {0}", ex.Message);
                        }
                        Console.WriteLine();


                        // Filter objects that apply to multiple tags are most useful in
                        // narrowing the set of tags that will be read. This is
                        // performed by setting a read plan that contains a filter.

                        // A TagData with a short EPC will filter for tags whose EPC
                        // starts with the same sequence.
                        filter = new TagData(tagReads[0].Tag.EpcString.Substring(0, 4));
                        Console.WriteLine("EPCs that begin with {0}:", filter);
                        r.ParamSet("/reader/read/plan",
                                   new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000));
                        filteredTagReads = r.Read(500);
                        foreach (TagReadData tr in filteredTagReads)
                        {
                            Console.WriteLine(tr.ToString());
                        }
                        Console.WriteLine();

                        // A filter can also be an full Gen2 Select operation.  For
                        // example, this filter matches all Gen2 tags where bits 8-19 of
                        // the TID are 0x003 (that is, tags manufactured by Alien
                        // Technology).
                        // In case of Network readers, ensure that bitLength is a multiple of 8.
                        Console.WriteLine("Tags with Alien Technology TID");
                        filter = new Gen2.Select(false, Gen2.Bank.TID, 8, 12, new byte[] { 0, 0x30 });
                        r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000));
                        filteredTagReads = r.Read(500);
                        foreach (TagReadData tr in filteredTagReads)
                        {
                            Console.WriteLine(tr.ToString());
                        }
                        Console.WriteLine();

                        if (r is SerialReader)
                        {
                            // A filter can also be Gen2 Truncate  Select operation.
                            // Truncate indicates whether a Tag’s backscattered reply shall be truncated to those EPC bits that follow Mask.
                            // For example, truncated select starting with PC word start address and length of 16 bits
                            // In case of Network readers, ensure that bitLength is a multiple of 8.
                            Console.WriteLine("GEN2 Select Truncate Operation");
                            filter = new Gen2.Select(false, Gen2.Bank.GEN2EPCTRUNCATE, 16, 40, new byte[] { 0x30, 0x00, 0xDE, 0xAD, 0xCA });
                            r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000));
                            filteredTagReads = r.Read(500);
                            foreach (TagReadData tr in filteredTagReads)
                            {
                                Console.WriteLine(tr.ToString());
                            }
                            Console.WriteLine();

                            // A filter can also perform Gen2 Tag Filtering.
                            // Major advantage of this feature is to limit the EPC response to user specified length field and all others will be rejected by firmware.
                            // invert, bitPointer, mask : Parameters will be ignored when TMR_GEN2_EPC_LENGTH_FILTER is used
                            // maskBitLength : Specified EPC Length used for filtering
                            // For example, Tag filtering will be applied on EPC with 128 bits length, rest of the tags will be ignored
                            // In case of Network readers, ensure that bitLength is a multiple of 8.
                            Console.WriteLine("GEN2 Tag Filter Based on EPC Length");
                            filter = new Gen2.Select(false, Gen2.Bank.GEN2EPCLENGTHFILTER, 16, 128, new byte[] { 0x30, 0x00 });
                            r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000));
                            filteredTagReads = r.Read(500);
                            foreach (TagReadData tr in filteredTagReads)
                            {
                                Console.WriteLine(tr.ToString());
                            }
                            Console.WriteLine();
                        }

                        // Gen2 Select may also be inverted, to give all non-matching tags
                        // In case of Network readers, ensure that bitLength is a multiple of 8.
                        Console.WriteLine("Tags without Alien Technology TID");
                        filter = new Gen2.Select(true, Gen2.Bank.TID, 8, 12, new byte[] { 0, 0x30 });
                        r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000));
                        filteredTagReads = r.Read(500);
                        foreach (TagReadData tr in filteredTagReads)
                        {
                            Console.WriteLine(tr.ToString());
                        }
                        Console.WriteLine();

                        // Filters can also be used to match tags that have already been
                        // read. This form can only match on the EPC, as that's the only
                        // data from the tag's memory that is contained in a TagData
                        // object.
                        // Note that this filter has invert=true. This filter will match
                        // tags whose bits do not match the selection mask.
                        // Also note the offset - the EPC code starts at bit 32 of the
                        // EPC memory bank, after the StoredCRC and StoredPC.
                        // In case of Network readers, ensure that bitLength is a multiple of 8.
                        filter = new Gen2.Select(true, Gen2.Bank.EPC, 32, 2, new byte[] { (byte)0xC0 });
                        Console.WriteLine("EPCs with first 2 bits equal to zero (post-filtered):");
                        foreach (TagReadData tr in tagReads) // unfiltered tag reads from the first example
                        {
                            if (filter.Matches(tr.Tag))
                            {
                                Console.WriteLine(tr.ToString());
                            }
                        }
                        Console.WriteLine();

                        /**
                         * Multi filter creation and initialization. This filter will match those tags whose bits matches the
                         * selection mask of both tidFilter(tags manufactured by Alien Technology) and epcFilter(epc of first
                         * tag read from tagReads[0]). Target and action are the two new parameters of Gen2.Select class whose
                         * default values could be "Gen2.Select.Target.Select" and "Gen2.Select.Action.ON_N_OFF" respectively
                         * if not provided by the user.
                         *
                         * Gen2 Select Action indicates which Select action to take
                         * (See Gen2 spec /Select commands / Tag response to Action parameter)
                         * |-----------------------------------------------------------------------------|
                         * |  Action  |        Tag Matching            |        Tag Not-Matching         |
                         * |----------|--------------------------------|---------------------------------|
                         * |   0x00   |  Assert SL or Inventoried->A   |  Deassert SL or Inventoried->B  |
                         * |   0x01   |  Assert SL or Inventoried->A   |  Do nothing                     |
                         * |   0x02   |  Do nothing                    |  Deassert SL or Inventoried->B  |
                         * |   0x03   |  Negate SL or (A->B,B->A)      |  Do nothing                     |
                         * |   0x04   |  Deassert SL or Inventoried->B |  Assert SL or Inventoried->A    |
                         * |   0x05   |  Deassert SL or Inventoried->B |  Do nothing                     |
                         * |   0x06   |  Do nothing                    |  Assert SL or Inventoried->A    |
                         * |   0x07   |  Do nothing                    |  Negate SL or (A->B,B->A)       |
                         *
                         *
                         * To improve readability and ease typing, these names abbreviate the official terminology of the Gen2 spec.
                         * <A>_N_<B>: The "_N_" stands for "Non-Matching".
                         * The <A> clause before the _N_ describes what happens to Matching tags.
                         * The <B> clause after the _N_ describes what happens to Non-Matching tags.
                         * (Alternately, you can pronounce "_N_" as "and", or "&"; i.e.,
                         * the pair of Matching / Non-Matching actions is known as "<A> and <B>".)
                         *
                         * ON: assert SL or inventoried -> A
                         * OFF: deassert SL or inventoried -> B
                         * NEG: negate SL or (A->B, B->A)
                         * NOP: do nothing
                         *
                         * The enum is simply a transliteration of the Gen2 spec's table: "Tag response to Action parameter"
                         */

                        // create and initialize tidFilter
                        // In case of Network readers, ensure that bitLength is a multiple of 8.
                        Gen2.Select tidFilter = new Gen2.Select(false, Gen2.Bank.TID, 32, 16, new byte[] { (byte)0x01, (byte)0x2E });
                        tidFilter.target = Gen2.Select.Target.Select;
                        tidFilter.action = Gen2.Select.Action.ON_N_OFF;

                        // create and initialize epcFilter
                        // In case of Network readers, ensure that bitLength is a multiple of 8.
                        Gen2.Select epcFilter = new Gen2.Select(false, Gen2.Bank.EPC, 32, 16, new byte[] { (byte)0x11, (byte)0x22 });
                        epcFilter.target = Gen2.Select.Target.Select;
                        epcFilter.action = Gen2.Select.Action.ON_N_OFF;

                        // Initialize multifilter with tagFilter array containing list of filters
                        // In case of Network readers, ensure that bitLength is a multiple of 8.
                        MultiFilter multiFilter = new MultiFilter(new TagFilter[] { tidFilter, epcFilter });
                        r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, multiFilter, 1000));
                        Console.WriteLine("Reading tags which matches multi filter criteria \n", filter.ToString());
                        filteredTagReads = r.Read(500);
                        foreach (TagReadData tr in filteredTagReads)
                        {
                            Console.WriteLine(tr.ToString());
                        }
                        Console.WriteLine();
                    }
                }
                finally
                {
                    // Restore original settings
                    Console.WriteLine("Restoring Session " + oldSession);
                    r.ParamSet("/reader/gen2/session", oldSession);
                }

                // Shut down reader
                r.Destroy();
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }