1

我使用 ocatne SDK C# 和 impinj speedway R420 对 RFID UHF gen2 标签进行编码。

我使用 SDK 的示例写入标签并且它正在工作,当我想要连续编码时我的问题开始了,我会解释。

我想在阅读器字段中放置一个标签对其进行编码并将其删除,然后等待第二个标签对其进行编码,依此类推....

我试图将搜索模式设置为“单一目标”并使用会话 2,但它只是读取标签而不对其进行编码,我从来没有让编码序列运行。

任何其他选项它只是保持编码和编码非常快,我不知道什么时候删除标签,所以我可以控制编码数据。

我的代码在这里:

using System;
using System.Threading;
using Impinj.OctaneSdk;
using System.Windows.Threading;


namespace OctaneSdkExamples
{
    class Program
    {
        // Create an instance of the ImpinjReader class.
        static ImpinjReader reader = new ImpinjReader();

        const ushort EPC_OP_ID = 123;
        const ushort PC_BITS_OP_ID = 321;

        static Random random = new Random((int)DateTime.Now.Ticks);

        public static void DelayAction(int millisecond)
        {
            var timer = new DispatcherTimer();
            timer.Tick += delegate

            {
                timer.Stop();
            };

            timer.Interval = TimeSpan.FromMilliseconds(millisecond);
            timer.Start();
        }

        static string GetRandomEpc()
        {
            string epc = "";
            int numWords = random.Next(1, 7);

            for (int i = 0; i < numWords; i++)
                epc += random.Next(0, ushort.MaxValue + 1).ToString("X4");

            return epc;
        }

        static void ProgramEpc(string currentEpc, ushort currentPcBits, string newEpc)
        {
            // Check that the specified EPCs are a valid length
            if ((currentEpc.Length % 4 != 0) || (newEpc.Length % 4 != 0))
                throw new Exception("EPCs must be a multiple of 16 bits (4 hex chars)");

            Console.WriteLine("\nAdding a write operation to change the EPC from :");
            Console.WriteLine("{0} to {1}\n", currentEpc, newEpc);

            // Create a tag operation sequence.
            // You can add multiple read, write, lock, kill and QT
            // operations to this sequence.
            TagOpSequence seq = new TagOpSequence();

            // Specify a target tag based on the EPC.
            seq.TargetTag.MemoryBank = MemoryBank.Epc;
            seq.TargetTag.BitPointer = BitPointers.Epc;
            seq.TargetTag.Data = currentEpc;

            // If you are using Monza 4, Monza 5 or Monza X tag chips,
            // uncomment these two lines. This enables 32-bit block writes
            // which significantly improves write performance.
            //seq.BlockWriteEnabled = true;
            //seq.BlockWriteWordCount = 2;

            // Create a tag write operation to change the EPC.
            TagWriteOp writeEpc = new TagWriteOp();
            // Set an ID so we can tell when this operation has executed.
            writeEpc.Id = EPC_OP_ID;
            // Write to EPC memory
            writeEpc.MemoryBank = MemoryBank.Epc;
            // Specify the new EPC data
            writeEpc.Data = TagData.FromHexString(newEpc);
            // Starting writing at word 2 (word 0 = CRC, word 1 = PC bits)
            writeEpc.WordPointer = WordPointers.Epc;

            // Add this tag write op to the tag operation sequence.
            seq.Ops.Add(writeEpc);

            // Is the new EPC a different length than the current EPC?
            if (currentEpc.Length != newEpc.Length)
            {
                // We need adjust the PC bits and write them back to the 
                // tag because the length of the EPC has changed.

                // Adjust the PC bits (4 hex characters per word).
                ushort newEpcLenWords = (ushort)(newEpc.Length / 4);
                ushort newPcBits = PcBits.AdjustPcBits(currentPcBits, newEpcLenWords);

                Console.WriteLine("Adding a write operation to change the PC bits from :");
                Console.WriteLine("{0} to {1}\n", currentPcBits.ToString("X4"), newPcBits.ToString("X4"));

                TagWriteOp writePc = new TagWriteOp();
                writePc.Id = PC_BITS_OP_ID;
                // The PC bits are in the EPC memory bank.
                writePc.MemoryBank = MemoryBank.Epc;
                // Specify the data to write (the modified PC bits).
                writePc.Data = TagData.FromWord(newPcBits);
                // Start writing at the start of the PC bits.
                writePc.WordPointer = WordPointers.PcBits;

                // Add this tag write op to the tag operation sequence.
                seq.Ops.Add(writePc);

            }

            // Add the tag operation sequence to the reader.
            // The reader supports multiple sequences.
            reader.AddOpSequence(seq);
        }

        static void Main(string[] args)
        {
            try
            {

                reader.Connect("10.0.1.201");

                // Assign the TagsReported event handler.
                // This specifies which method to call
                // when tags reports are available.
                reader.TagsReported += OnTagsReported;

                reader.TagOpComplete += OnTagOpComplete;

                Settings settings = reader.QueryDefaultSettings();

                settings.Report.IncludeAntennaPortNumber = true;
                settings.Report.IncludePcBits = true;
                settings.ReaderMode = ReaderMode.AutoSetDenseReader;
                settings.Antennas.DisableAll();
                settings.Antennas.GetAntenna(1).IsEnabled = true;
                settings.Antennas.GetAntenna(1).MaxRxSensitivity = true;
                settings.Antennas.GetAntenna(1).TxPowerInDbm = 10;
                settings.SearchMode = SearchMode.SingleTarget;
                settings.Session =2;
                settings.TagPopulationEstimate = 1;

                reader.ApplySettings(settings);
                // Start reading.
                reader.Start();

                // Wait for the user to press enter.
                Console.WriteLine("Press enter to exit.");
                Console.ReadLine();

                // Stop reading.
                reader.Stop();

                // Disconnect from the reader.
                reader.Disconnect();
            }
            catch (OctaneSdkException e)
            {
                // Handle Octane SDK errors.
                Console.WriteLine("Octane SDK exception: {0}", e.Message);
            }
            catch (Exception e)
            {
                // Handle other .NET errors.
                Console.WriteLine("Exception : {0}", e.Message);
            }
        }

        static void OnTagsReported(ImpinjReader sender, TagReport report)
        {
            // This event handler is called asynchronously 
            // when tag reports are available.
            // Loop through each tag in the report 
            // and print the data.
            reader.TagsReported -= OnTagsReported;
            Tag tag = report.Tags[0];
            ProgramEpc(tag.Epc.ToHexString(), tag.PcBits, GetRandomEpc());

        }

        static void OnTagOpComplete(ImpinjReader reader, TagOpReport report)
        {
            // Loop through all the completed tag operations.
            foreach (TagOpResult result in report)
            {
                // Was this completed operation a tag write operation?
                if (result is TagWriteOpResult)
                {
                    // Cast it to the correct type.
                    TagWriteOpResult writeResult = result as TagWriteOpResult;
                    if (writeResult.OpId == EPC_OP_ID)
                        Console.WriteLine("Write to EPC complete : {0}", writeResult.Result);
                    else if (writeResult.OpId == PC_BITS_OP_ID)
                        Console.WriteLine("Write to PC bits complete : {0}", writeResult.Result);

                    // Print out the number of words written
                    Console.WriteLine("Number of words written : {0}", writeResult.NumWordsWritten);


                }
            }
            //DelayAction(3000);
            //Thread.Sleep(3000);
            reader.TagsReported += OnTagsReported;
        }
    }
}
4

1 回答 1

2

当您使用 Session 2 和 Single Target 时,标签只会响应一次,直到它离开现场超过一定时间。这意味着当您阅读它,然后尝试对其进行编程时,它不再响应。因此,在此设置中必须使用双目标。

要确定您是否已经对特定标签进行了编程,请跟踪标签的 TID:对于大多数标签,它包含在 IC 生产中编程的唯一序列号,即使您更改 EPC,也不会更改。您可以查看此值以在字段中输入新标签。

于 2016-11-05T10:55:06.047 回答