2016-11-03 9 views
0

En utilisant ocatne SDK C# et impinj speedway R420 pour coder les tags RFID UHF gen2.Comment encoder une étiquette RFID UHF une seule fois en utilisant Impinj speedway

J'ai utilisé les échantillons du SDK pour écrire sur les tags et cela fonctionne, mes problèmes commencent quand je veux encoder en continu et je vais vous expliquer.

Je veux mettre un tag dans le encode champ du lecteur et retirez-le puis d'attendre encode 2ème tag et ainsi de suite ....

je Tring pour définir le mode de recherche à « unique Ciblez et utilisez Session 2 mais il ne lit que la balise et ne la code pas, je n'obtiens jamais l'encodage seq.

toute autre option, il garde très rapidement l'encodage et l'encodage et je ne sais pas quand retirer l'étiquette pour pouvoir contrôler les données d'encodage.

mon code ici:

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

Répondre

1

Lorsque vous utilisez Session 2 et cible unique, l'étiquette réagira en une seule fois, jusqu'à ce qu'il ait été hors du champ depuis plus d'un certain laps de temps. Cela signifie que lorsque vous le lisez, puis essayez de le programmer, il ne répond plus. Par conséquent, il est nécessaire dans cette configuration d'utiliser Dual Target. Pour savoir si vous avez déjà programmé une étiquette spécifique, gardez la trace du TID d'une étiquette: pour la plupart des étiquettes, elle contient un numéro de série unique programmé sur la production IC qui ne changera jamais, même si vous changez l'EPC. Vous pouvez regarder cette valeur pour une nouvelle balise à entrer dans le champ.

+0

Bonjour Danny, merci pour votre réponse quand j'ai essayé la session 2 en mode simple et je n'ai pas travaillé, maintenant je sais pourquoi:). J'ai utilisé la session 1 dans la cible unique et ajouté un délai pour que l'utilisateur remplace la balise, pour l'instant et son fonctionnement. Je vais essayer votre solution Merci! – idan357