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]);
                        }
                    }
                    List<ReadPlan> readPlans = new List<ReadPlan>();
                    TagProtocol[] protocolList = (TagProtocol[])r.ParamGet("/reader/version/supportedProtocols");
                    foreach (TagProtocol protocol in protocolList)
                    {
                        readPlans.Add(new SimpleReadPlan(null, protocol, null, null, 10));
                    }
                    MultiReadPlan testMultiReadPlan = new MultiReadPlan(readPlans);
                    r.ParamSet("/reader/read/plan", testMultiReadPlan);
                    TagReadData[] tagRead = r.Read(1000);
                    foreach (TagReadData tr in tagRead)
                        Console.WriteLine(String.Format("{0} {1}",
                            tr.Tag.Protocol, tr.ToString()));
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Beispiel #2
0
        public static string SaveReadPlan(Object value)
        {
            string   readPlan = string.Empty;
            ReadPlan rp       = (ReadPlan)value;

            if (rp is SimpleReadPlan)
            {
                return(SaveSimpleReadPlan(value));
            }
            else
            {
                MultiReadPlan   mrp = (MultiReadPlan)rp;
                List <ReadPlan> MRP = new List <ReadPlan>(mrp.Plans);
                readPlan += "MultiReadPlan:[";
                foreach (ReadPlan rap in MRP)
                {
                    readPlan += SaveSimpleReadPlan(rap) + ",";
                }
                readPlan  = readPlan.Remove(readPlan.Length - 1, 1);
                readPlan += "]";
                return(readPlan);
            }
        }
Beispiel #3
0
 private static MultiReadPlan MakeMultiReadPlan()
 {
     List<ReadPlan> plans = new List<ReadPlan>();
     plans.Add(new SimpleReadPlan(null, TagProtocol.GEN2, null, 100));
     plans.Add(new SimpleReadPlan(null, TagProtocol.ISO180006B, null, 200));
     //plans.Add(new SimpleReadPlan(null, TagProtocol.IPX256, null, 200));
     MultiReadPlan mrp = new MultiReadPlan(plans);
     return mrp;
 }
Beispiel #4
0
        private static void TestStrFilterReadPlansFunc(Reader rdr, ArgParser pargs)
        {
            Gen2.Select g2s = new Gen2.Select(false, Gen2.Bank.EPC, 16, 16, new byte[] { 0x12, 0x34 });
            Console.WriteLine(g2s);
            Gen2.Select notg2s = new Gen2.Select(true, Gen2.Bank.EPC, 16, 16, new byte[] { 0x12, 0x34 });
            Console.WriteLine(notg2s);
            Iso180006b.Select i6bs = new Iso180006b.Select(false, Iso180006b.SelectOp.EQUALS, 0, 0xC0, new byte[] { 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
            Console.WriteLine(i6bs);
            Iso180006b.Select noti6bs = new Iso180006b.Select(true, Iso180006b.SelectOp.EQUALS, 0, 0xC0, new byte[] { 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
            Console.WriteLine(noti6bs);
            TagData td = new TagData("1234567890ABCDEF");
            Console.WriteLine(td);
            MultiFilter mf = new MultiFilter(new TagFilter[] { g2s, i6bs, td });
            Console.WriteLine(mf);

            SimpleReadPlan srp1 = new SimpleReadPlan(null, TagProtocol.GEN2, g2s, 1000);
            Console.WriteLine(srp1);
            SimpleReadPlan srp2 = new SimpleReadPlan(new int[] { 1, 2 }, TagProtocol.ISO180006B, i6bs, 1000);
            Console.WriteLine(srp2);
            MultiReadPlan mrp = new MultiReadPlan(new ReadPlan[] { srp1, srp2 });
            Console.WriteLine(mrp);
        }
Beispiel #5
0
        /// <summary>
        /// Parse string representing a parameter value.
        /// </summary>
        /// <param name="name">Name of parameter</param>
        /// <param name="valstr">String to be parsed into a parameter value</param>
        private Object ParseValue(string name, string valstr)
        {
            Object value = ParseValue(valstr);

            switch (name.ToLower())
            {
            case "/reader/antenna/portswitchgpos":
            case "/reader/region/hoptable":
                value = ((ArrayList)value).ToArray(typeof(int));
                break;

            case "/reader/gpio/inputlist":
            case "/reader/read/trigger/gpi":
            case "/reader/probebaudrates":
                value = ((ArrayList)value).ToArray(typeof(int));
                break;

            case "/reader/gpio/outputlist":
                value = ((ArrayList)value).ToArray(typeof(int));
                break;

            case "/reader/antenna/settlingtimelist":
            case "/reader/antenna/txrxmap":
            case "/reader/radio/portreadpowerlist":
            case "/reader/radio/portwritepowerlist":
                value = ArrayListToInt2Array((ArrayList)value);
                break;

            case "/reader/region/lbt/enable":
            case "/reader/antenna/checkport":
            case "/reader/tagreaddata/recordhighestrssi":
            case "/reader/tagreaddata/uniquebyantenna":
            case "/reader/tagreaddata/uniquebydata":
            case "/reader/tagreaddata/reportrssiindbm":
            case "/reader/radio/enablepowersave":
            case "/reader/status/antennaenable":
            case "/reader/status/frequencyenable":
            case "/reader/status/temperatureenable":
            case "/reader/tagreaddata/reportrssiIndbm":
            case "/reader/tagreaddata/uniquebyprotocol":
            case "/reader/tagreaddata/enablereadfilter":
            case "/reader/radio/enablesjc":
            case "/reader/gen2/writeearlyexit":
            case "/reader/gen2/sendselect":
            case "/reader/extendedepc":
                value = ParseBool(valstr);
                break;

            case "/reader/gen2/t4":
                value = Convert.ToUInt32(valstr);
                break;

            case "/reader/read/plan":
                if (valstr.StartsWith("SimpleReadPlan"))
                {
                    value = LoadSimpleReadPlan(valstr);
                }
                else
                {
                    string          str     = string.Empty;
                    List <ReadPlan> RdPlans = new List <ReadPlan>();
                    str = valstr.Remove(0, 14);
                    //Remove leading and trailing square brackets
                    string        remove = Regex.Replace(str, @"]$|^\[", "");
                    int           CurrentIndex = 0, PreviousIndex = 1;
                    List <string> Plans = new List <string>();
                    while (CurrentIndex != -1)
                    {
                        CurrentIndex = str.IndexOf("SimpleReadPlan:", CurrentIndex);
                        string st = string.Empty;
                        if (CurrentIndex != -1)
                        {
                            st            = str.Substring(PreviousIndex, CurrentIndex - PreviousIndex);
                            PreviousIndex = CurrentIndex;
                            CurrentIndex += 1;
                        }
                        else
                        {
                            st = str.Substring(PreviousIndex);
                        }
                        if (st != string.Empty)
                        {
                            st = st.Remove(st.Length - 1, 1);
                            Plans.Add(st);
                        }
                    }
                    foreach (string plan in Plans)
                    {
                        RdPlans.Add(LoadSimpleReadPlan(plan));
                    }
                    MultiReadPlan mrp = new MultiReadPlan(RdPlans);
                    value = mrp;
                }
                break;

            case "/reader/region/id":
                value = Enum.Parse(typeof(Reader.Region), (string)value, true);
                break;

            case "/reader/powermode":
                value = Enum.Parse(typeof(Reader.PowerMode), (string)value, true);
                break;

            case "/reader/tagop/protocol":
                if (value is string)
                {
                    value = Enum.Parse(typeof(TagProtocol), (string)value, true);
                }
                break;

            case "/reader/gen2/accesspassword":
                value = new Gen2.Password(Convert.ToUInt32(valstr, 16));
                break;

            case "/reader/gen2/session":
                value = (Gen2.Session)Enum.Parse(typeof(Gen2.Session), valstr, true);
                break;

            case "/reader/gen2/blf":
                value = (Gen2.LinkFrequency)Enum.Parse(typeof(Gen2.LinkFrequency), valstr, true);
                break;

            case "/reader/gen2/tagencoding":
                value = (Gen2.TagEncoding)Enum.Parse(typeof(Gen2.TagEncoding), valstr, true);
                break;

            case "/reader/iso180006b/blf":
                value = (Iso180006b.LinkFrequency)Enum.Parse(typeof(Iso180006b.LinkFrequency), valstr, true);
                break;

            case "/reader/gen2/target":
                value = (Gen2.Target)Enum.Parse(typeof(Gen2.Target), valstr, true);
                break;

            case "/reader/gen2/tari":
                value = (Gen2.Tari)Enum.Parse(typeof(Gen2.Tari), valstr, true);
                break;

            case "/reader/gen2/protocolextension":
                value = (Gen2.Tari)Enum.Parse(typeof(Gen2.ProtocolExtension), valstr, true);
                break;

            case "/reader/regulatory/mode":
                value = Enum.Parse(typeof(Reader.RegulatoryMode), valstr, true);
                break;

            case "/reader/regulatory/modulation":
                value = Enum.Parse(typeof(Reader.RegulatoryModulation), valstr, true);
                break;

            case "/reader/usermode":
                value = (SerialReader.UserMode)Enum.Parse(typeof(SerialReader.UserMode), (string)valstr, true);
                break;

            case "/reader/stats/enable":
                valstr = valstr.Trim(new char[] { '[', ']' });
                value  = valstr != string.Empty
                        ? (Reader.Stat.StatsFlag)Enum.Parse(typeof(Reader.Stat.StatsFlag), valstr, true)
                        : (Reader.Stat.StatsFlag)Enum.Parse(typeof(Reader.Stat.StatsFlag), "NONE", true);
                break;

            case "/reader/gen2/writemode":
                value = (Gen2.WriteMode)Enum.Parse(typeof(Gen2.WriteMode), valstr, true);
                break;

            case "/reader/iso180006b/delimiter":
                value = (Iso180006b.Delimiter)Enum.Parse(typeof(Iso180006b.Delimiter), valstr, true);
                break;

            case "/reader/iso180006b/modulationdepth":
                value = (Iso180006b.ModulationDepth)Enum.Parse(typeof(Iso180006b.ModulationDepth), valstr, true);
                break;

            case "/reader/gen2/q":
                Gen2.Q setQ = null;
                if (-1 != valstr.IndexOf("DynamicQ"))
                {
                    setQ = new Gen2.DynamicQ();
                }
                else
                {
                    string resultString = Regex.Match(valstr, @"\d+").Value;
                    int    q            = Int32.Parse(resultString);
                    setQ = new Gen2.StaticQ((byte)q);
                }
                value = setQ;
                break;

            case "/reader/gen2/bap":
                MatchCollection    mc  = Regex.Matches(valstr, @"\d+");
                Gen2.BAPParameters bap = new Gen2.BAPParameters();
                bap.POWERUPDELAY        = Convert.ToInt32(mc[0].ToString());
                bap.FREQUENCYHOPOFFTIME = Convert.ToInt32(mc[1].ToString());
                value = bap;
                break;

            case "/reader/gen2/initq":
                Gen2.InitQ queue = new Gen2.InitQ();
                if (valstr.StartsWith("[") && valstr.EndsWith("]"))
                {
                    valstr = valstr.Substring(1, valstr.Length - 2);
                    string[] qValue = valstr.Split(',');
                    foreach (string str1 in qValue)
                    {
                        string str = str1.Trim();
                        if (str.StartsWith("qEnable:"))
                        {
                            int    index      = str.IndexOf(":");
                            string qEnableVal = str.Substring(index + 1).Trim();
                            queue.qEnable = Convert.ToBoolean(qEnableVal);
                        }
                        else if (str.StartsWith("initialQ:"))
                        {
                            int    index      = str.IndexOf(":");
                            string qEnableVal = str.Substring(index + 1).Trim();
                            queue.initialQ = Convert.ToByte(qEnableVal);
                        }
                        else
                        {
                            throw new Exception(str + " is not a valid option");
                        }
                    }
                    value = queue;
                }
                break;

            case "/reader/metadata":
                string[] usermeta = valstr.Split(',');
                SerialReader.TagMetadataFlag val = 0x0000;
                foreach (string meta in usermeta)
                {
                    switch (meta.Trim())
                    {
                    case "NONE":
                        val |= SerialReader.TagMetadataFlag.NONE;
                        break;

                    case "ANTENNAID":
                        val |= SerialReader.TagMetadataFlag.ANTENNAID;
                        break;

                    case "DATA":
                        val |= SerialReader.TagMetadataFlag.DATA;
                        break;

                    case "FREQUENCY":
                        val |= SerialReader.TagMetadataFlag.FREQUENCY;
                        break;

                    case "GPIO":
                        val |= SerialReader.TagMetadataFlag.GPIO;
                        break;

                    case "PHASE":
                        val |= SerialReader.TagMetadataFlag.PHASE;
                        break;

                    case "PROTOCOL":
                        val |= SerialReader.TagMetadataFlag.PROTOCOL;
                        break;

                    case "READCOUNT":
                        val |= SerialReader.TagMetadataFlag.READCOUNT;
                        break;

                    case "RSSI":
                        val |= SerialReader.TagMetadataFlag.RSSI;
                        break;

                    case "TIMESTAMP":
                        val |= SerialReader.TagMetadataFlag.TIMESTAMP;
                        break;

                    case "BRAND_IDENTIFIER":
                        val |= SerialReader.TagMetadataFlag.BRAND_IDENTIFIER;
                        break;

                    default:
                    case "ALL":
                        val |= SerialReader.TagMetadataFlag.ALL;
                        break;
                    }
                }
                value = val;
                break;

            default:
                break;
            }
            return(value);
        }