首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用Impinj高速公路对RFID超高频标签进行一次编码

如何使用Impinj高速公路对RFID超高频标签进行一次编码
EN

Stack Overflow用户
提问于 2016-11-03 10:28:13
回答 1查看 2.3K关注 0票数 1

我使用ocatne C#和impinj高速公路R420编码RFID超高频gen2标签。

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

我想在“读取器”字段中放置一个标签,对其进行编码和删除,然后等待第二个标签对其进行编码等等.

我尝试将搜索模式设置为‘单目标’并使用会话2,但它只是读取标记而不是编码它,我从来没有让编码seq运行。

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

我的密码是:

代码语言:javascript
运行
复制
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;
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-05 10:55:06

当您使用Session 2和Single时,标记只会响应一次,直到它离开字段超过一段时间为止。这意味着当你阅读它,然后尝试编程它,它不再有反应。因此,在这种设置中,有必要使用双目标。

要弄清楚您是否已经编写了特定的标签,请跟踪标签的TID :对于大多数标签,这包含一个在IC产品上编程的唯一序列号,即使您更改了EPC,它也不会改变。您可以查看此值,以便在字段中输入新标记。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40399153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档