Ejemplo 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]);
                        }
                    }

                    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);
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Ejemplo n.º 2
0
        public static string SaveSimpleReadPlan(Object value)
        {
            string   readPlan = string.Empty;
            ReadPlan rp       = (ReadPlan)value;

            readPlan += "SimpleReadPlan:[";
            SimpleReadPlan srp = (SimpleReadPlan)rp;

            readPlan += "Antennas=" + ArrayToString(srp.Antennas);
            readPlan += "," + "Protocol=" + srp.Protocol.ToString();
            if (srp.Filter != null)
            {
                if (srp.Filter is Gen2.Select)
                {
                    Gen2.Select sf = (Gen2.Select)srp.Filter;
                    readPlan += "," + string.Format("Filter=Gen2.Select:[Invert={0},Bank={1},BitPointer={2},BitLength={3},Mask={4}]",
                                                    (sf.Invert?"true" : "false"), sf.Bank, sf.BitPointer, sf.BitLength, ByteFormat.ToHex(sf.Mask));
                }
                else
                {
                    Gen2.TagData td = (Gen2.TagData)srp.Filter;
                    readPlan += "," + string.Format("Filter=TagData:[EPC={0}]", td.EpcString);
                }
            }
            else
            {
                readPlan += ",Filter=null";
            }
            if (srp.Op != null)
            {
                if (srp.Op is Gen2.ReadData)
                {
                    Gen2.ReadData rd = (Gen2.ReadData)srp.Op;
                    readPlan += "," + string.Format("Op=ReadData:[Bank={0},WordAddress={1},Len={2}]", rd.Bank, rd.WordAddress, rd.Len);
                }
                else
                {
                    readPlan += ",Op=null";
                }
            }
            else
            {
                readPlan += ",Op=null";
            }
            readPlan += "," + "UseFastSearch=" + srp.UseFastSearch.ToString();
            readPlan += "," + "Weight=" + srp.Weight.ToString() + "]";
            return(readPlan);
        }
        private void PerformWriteOperation()
        {
            Gen2.TagData epc = new Gen2.TagData(new byte[] {
                        0x01, 0x23, 0x45, 0x67, 0x89, 0xAB,
                        0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67,
                    });
            Console.WriteLine("Write on epc mem: " + epc.EpcString);
            Gen2.WriteTag tagop = new Gen2.WriteTag(epc);
            reader.ExecuteTagOp(tagop, null);
            Console.WriteLine();

            ushort[] data = new ushort[] { 0x1234, 0x5678 };
            Console.WriteLine("Write on reserved mem: " + ByteFormat.ToHex(data));
            Gen2.BlockWrite blockwrite = new Gen2.BlockWrite(Gen2.Bank.RESERVED, 0, data);
            reader.ExecuteTagOp(blockwrite, null);
            Console.WriteLine();

            data = null;
            data = new ushort[] { 0xFFF1, 0x1122 };
            Console.WriteLine("Write on user mem: " + ByteFormat.ToHex(data));
            blockwrite = new Gen2.BlockWrite(Gen2.Bank.USER, 0, data);
            reader.ExecuteTagOp(blockwrite, null);
            Console.WriteLine();
        }
Ejemplo n.º 4
0
        private TagReadData ParseRqlResponse(string row, DateTime baseTime)
        {
            String[] fields = row.Split(_selFieldSeps);

            if (_readFieldNames.Length != fields.Length)
            {
                throw new ReaderParseException(String.Format("Unrecognized format."
                    + "  Got {0} fields in RQL response, expected {1}.",
                    fields.Length, _readFieldNames.Length));
            }
            byte[] epccrc = ByteFormat.FromHex(fields[ID].Substring(2));
            byte[] epc = new byte[epccrc.Length - 2];
            Array.Copy(epccrc, epc, epc.Length);
            byte[] crc = new byte[2];
            Array.Copy(epccrc, epc.Length, crc, 0, 2);

            TagProtocol proto = CodeToProtocol(fields[PROTOCOL_ID]);
            string idfield = fields[ID];
            TagData tag = null;

            switch (proto)
            {
                case TagProtocol.GEN2:
                    byte[] pcbits = null;
                    if (_readFieldNames.Length > 7)
                    {
                        pcbits = ByteFormat.FromHex(fields[METADATA].ToString());
                    }
                    tag = new Gen2.TagData(epc, crc,pcbits);
                    break;
                case TagProtocol.ISO180006B:
                    tag = new Iso180006b.TagData(epc, crc);
                    break;
                case TagProtocol.IPX64:
                    tag = new Ipx64.TagData(epc, crc);
                    break;
                case TagProtocol.IPX256:
                    tag = new Ipx256.TagData(epc, crc);
                    break;
                default:
                    throw new ReaderParseException("Unknown protocol code " + fields[PROTOCOL_ID]);
            }

            int antenna = int.Parse(fields[ANTENNA_ID]);
            TagReadData tr = new TagReadData();
            tr.Reader = this;
            tr._tagData = tag;
            tr._antenna = antenna;
            tr._baseTime = baseTime;
            tr.ReadCount = int.Parse(fields[READ_COUNT]);
            if (_readFieldNames.Length > 7)
            {
                tr._data = ByteFormat.FromHex(fields[DATA]);
                tr._phase = int.Parse(fields[PHASE]);
            }
            tr._readOffset = int.Parse(fields[DSPMICROS]) / 1000;
            tr._frequency = int.Parse(fields[FREQUENCY]);
            

            if ("Mercury5" != _model)
            {
                tr._lqi = int.Parse(fields[LQI]);
            }

            return tr;
        }
Ejemplo n.º 5
0
 private static Gen2.TagData MakeGen2TagData(string pcstring, string epcstring, string crcstring)
 {
     byte[] pcbytes = ByteFormat.FromHex(pcstring);
     byte[] epcbytes = ByteFormat.FromHex(epcstring);
     byte[] crcbytes = ByteFormat.FromHex(crcstring);
     Gen2.TagData td = new Gen2.TagData(epcbytes, crcbytes, pcbytes);
     return td;
 }
Ejemplo n.º 6
0
        private void ParseNotifyTag(MSG_RO_ACCESS_REPORT msg)
        {
            if (null == tagReads)
            {
                tagReads = new List<TagReadData>();
            }
            TagReadData tag = null;
            if (null != msg)
            {
                for (int i = 0; i < msg.TagReportData.Length; i++)
                {
                    try
                    {
                        tag = new TagReadData();
                        if (msg.TagReportData[i].EPCParameter.Count > 0)
                        {
                            string epc;
                            // reports come in two flavors.  Get the right flavor
                            if (msg.TagReportData[i].EPCParameter[0].GetType() == typeof(PARAM_EPC_96))
                            {
                                epc = ((PARAM_EPC_96)(msg.TagReportData[i].EPCParameter[0])).EPC.ToHexString();
                            }
                            else
                            {
                                epc = ((PARAM_EPCData)(msg.TagReportData[i].EPCParameter[0])).EPC.ToHexString();
                            }
                            TagData td = new TagData(ByteFormat.FromHex(epc));
                            TagProtocol tagProtocol = 0;
                            //Match the recieved rospec id with the rospec id stored in the hashtable at the time of setting readplan
                            if (roSpecProtcolTable.ContainsKey(msg.TagReportData[i].ROSpecID.ROSpecID))
                            {
                                tagProtocol = (TagProtocol)roSpecProtcolTable[msg.TagReportData[i].ROSpecID.ROSpecID];
                            }
                            if (TagProtocol.GEN2.Equals(tagProtocol))
                            {
                                //Get crc and pc bits
                                UNION_AirProtocolTagData tagdata = msg.TagReportData[i].AirProtocolTagData;
                                td = new Gen2.TagData(ByteFormat.FromHex(epc), ByteConv.EncodeU16(((PARAM_C1G2_CRC)tagdata[1]).CRC), ByteConv.EncodeU16(((PARAM_C1G2_PC)tagdata[0]).PC_Bits));
                            }
                            else if (TagProtocol.ISO180006B.Equals(tagProtocol))
                            {
                                td = new Iso180006b.TagData(ByteFormat.FromHex(epc));
                            }
                            else
                            {
                                td = new TagData(ByteFormat.FromHex(epc));
                            }
                            tag.Reader = this;
                            tag._tagData = td;
                            tag._antenna = (int)msg.TagReportData[i].AntennaID.AntennaID;
                            UInt64 usSinceEpoch = msg.TagReportData[i].LastSeenTimestampUTC.Microseconds;
                            tag._baseTime = epochTime.AddMilliseconds(usSinceEpoch / 1000);
                            tag._readOffset = 0;
                            // Since Spruce release firmware doesn't support phase, there won't be PARAM_ThingMagicTagReportContentSelector 
                            // custom paramter in ROReportSpec
                            string[] ver = softwareVersion.Split('.');
                            if (((Convert.ToInt32(ver[0]) == 4) && (Convert.ToInt32(ver[1]) >= 17)) ||
                                (Convert.ToInt32(ver[0]) > 4))
                            {
                                tag._phase = Convert.ToInt32(((PARAM_ThingMagicRFPhase)msg.TagReportData[i].Custom[0]).Phase);
                            }
                            tag.Rssi = Convert.ToInt32(msg.TagReportData[i].PeakRSSI.PeakRSSI.ToString());
                            tag.ReadCount = msg.TagReportData[i].TagSeenCount.TagCount;

                            int chIndex = Convert.ToInt32(msg.TagReportData[i].ChannelIndex.ChannelIndex);
                            List<uint> freq = frequencyHopTable[0].Frequency.data;
                            tag._frequency = Convert.ToInt32(freq[chIndex - 1]);
                            UNION_AccessCommandOpSpecResult opSpecResult = msg.TagReportData[i].AccessCommandOpSpecResult;

                            tag._data = EMPTY_DATA;
                            // Use try-finally to to keep failed tagops from preventing report of TagReadData
                            try
                            {
                                if (null != opSpecResult)
                                {
                                    if (opSpecResult.Count > 0)
                                    {
                                        ParseTagOpSpecResultType(opSpecResult, ref tag);
                                    }
                                }
                            }
                            finally
                            {
                                if (continuousReading)
                                {
                                    OnTagRead(tag);
                                }
                                else
                                {
                                    tagReads.Add(tag);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ReaderException rx;
                        if (ex is ReaderException)
                        {
                            rx = (ReaderException)ex;
                        }
                        else
                        {
                            rx = new ReaderException(ex.ToString());
                        }
                        //Release the TagQueueEmptyEvent when parsing exception raised
                        TagQueueEmptyEvent.Set();
                        ReadExceptionPublisher expub = new ReadExceptionPublisher(this, rx);

                        Thread trd = new Thread(expub.OnReadException);
                        trd.Name = "OnReadException";
                        trd.Start();
                    }
                    finally
                    {
                        tag = null;
                    }
                }
                TagQueueEmptyEvent.Set();
            }
        }