void writeEpcWithSrc() { try { foreach (var currentEpc in epcList) { TagOpSequence seq = new TagOpSequence(); seq.TargetTag.MemoryBank = MemoryBank.Epc; seq.TargetTag.BitPointer = BitPointers.Epc; seq.TargetTag.Data = currentEpc; string newEpc = getNewEpc(currentEpc); TagWriteOp writeEpc = new TagWriteOp(); writeEpc.AccessPassword = TagData.FromHexString(textBox1_password.Text.Trim()); 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); mReader.AddOpSequence(seq); } } catch (Exception) { } }
void writeEpcSeqMode() { try { foreach (var currentEpc in epcList) { TagOpSequence seq = new TagOpSequence(); seq.TargetTag.MemoryBank = MemoryBank.Epc; seq.TargetTag.BitPointer = BitPointers.Epc; seq.TargetTag.Data = currentEpc; string newEpc = getNewEpc(currentEpc); TagWriteOp writeEpc = new TagWriteOp(); writeEpc.AccessPassword = TagData.FromHexString(textBox1_password.Text.Trim()); 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); mReader.AddOpSequence(seq); if (!selfAddCurEpc()) { mReader.Stop(); SetInventoryResult(1); playSound(false); Invoke(new Action(() => { dataGridView1_msg.Rows.Insert(0, "写入失败"); dataGridView1_msg.Rows[0].DefaultCellStyle.BackColor = Color.Red; })); break; } saveWriteEpc(textBox2_curWriteEPC.Text.Trim()); } } catch (Exception) { } }
static void BulkWrite(TagData accessPassword, MemoryBank bank, ushort wordPointer, TagData data) { TagOpSequence seq; TagWriteOp op; // How many words are we going to write? ushort wordCount = (ushort)(data.CountBytes / 2); // Initialize variables numOpsExecuted = 0; numOpsAdded = 0; numWordsWritten = 0; // Each TagWriteOp can only access up to 32 words. // So, we need to break this write up into multiple operations. while (wordCount > 0) { // Define a new tag operation sequence. seq = new TagOpSequence(); // 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; // Define a tag read operation op = new TagWriteOp(); op.AccessPassword = accessPassword; op.MemoryBank = bank; op.WordPointer = wordPointer; ushort opSizeWords = (wordCount < 32) ? wordCount : (ushort)32; op.Data = TagData.FromWordList(data.ToList().GetRange(wordPointer, opSizeWords)); // Add the write op to the operation sequence seq.Ops.Add(op); // Adjust the word count and pointer for the next reader operation wordCount -= opSizeWords; wordPointer += opSizeWords; // Add the operation sequence to the reader reader.AddOpSequence(seq); numOpsAdded++; } }
static void Main(string[] args) { try { // Connect to the reader. // Pass in a reader hostname or IP address as a // command line argument when running the example if (args.Length != 1) { Console.WriteLine("Error: No hostname specified. Pass in the reader hostname as a command line argument when running the Sdk Example."); return; } string hostname = args[0]; reader.Connect(hostname); // Assign the TagOpComplete event handler. // This specifies which method to call // when tag operations are complete. reader.TagOpComplete += OnTagOpComplete; // Configure the reader with the default settings. reader.ApplyDefaultSettings(); // 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; // Setting this to null will specify any tag. // Replace this line with the one below it to target a particular tag. seq.TargetTag.Data = null; //seq.TargetTag.Data = "11112222333344445555666677778888"; // 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. TagWriteOp writeOp = new TagWriteOp(); // Write to user memory writeOp.MemoryBank = MemoryBank.User; // Write two (16-bit) words writeOp.Data = TagData.FromHexString("ABBAD00D"); // Starting at word 0 writeOp.WordPointer = 0; // Add this tag write op to the tag operation sequence. seq.Ops.Add(writeOp); // Add the tag operation sequence to the reader. // The reader supports multiple sequences. reader.AddOpSequence(seq); // Start the reader 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); } }
public void Write(Tag tag) { //disable the on tags reported event handler while we write Program.App.r.reader.TagsReported -= EventHandlers.OnTagsReported; //query the current tags epc string currentEpc = tag.Epc.ToHexString(); ushort currentPcBits = tag.PcBits; //grab the user input for the new tag epc TextBox userEpc = Program.App.tagWriter.Controls["UserInput"] as TextBox; string newEpc = userEpc.Text; try { if ((currentEpc.Length % 4 != 0) || (newEpc.Length % 4 != 0)) { //check that the length of the new epc is a multiple of 4, if it's not: throw new Exception("EPC's must be a multiple of 16 bits (4 hex chars)"); } else { //if it is the rigth length, notify that we are beginning the write operation System.Diagnostics.Debug.WriteLine("Adding a write operation to change the EPC from :"); Console.WriteLine("{0} to {1}\n", currentEpc, newEpc); } } catch (OctaneSdkException err) { System.Diagnostics.Debug.WriteLine("Octane SDK exception: " + err.Message); } catch (Exception err) { System.Diagnostics.Debug.WriteLine("Exception: " + err.Message); } //System.Diagnostics.Debug.WriteLine("writing: " + newEpc); //disable the tag reader for now EventHandlers.writingTag = false; //create a tag op 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; //create a tag write operation to change the EPC TagWriteOp writeEpc = new TagWriteOp(); writeEpc.Id = EPC_OP_ID; //write EPC to memory writeEpc.MemoryBank = MemoryBank.Epc; //specify the new EPC data writeEpc.Data = TagData.FromHexString(newEpc); //start 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); 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); System.Diagnostics.Debug.WriteLine("Adding a write operation to change the PC bits from :"); System.Diagnostics.Debug.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 dta 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 Program.App.r.reader.AddOpSequence(seq); }
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("Adding 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); //writeEpc.Data = TagData.FromHexString("415543313041303031313631"); // writeEpc.Data = TagData.FromHexString("525543313041303031313631"); // Starting writing at word 2 (word 0 = CRC, word 1 = PC bits) writeEpc.WordPointer = WordPointers.Epc; //writeEpc.WordPointer = 0x23; // 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; writePc.WordPointer = 0x23; // 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 { // Connect to the reader. // Change the ReaderHostname constant in SolutionConstants.cs // to the IP address or hostname of your reader. reader.Connect(SolutionConstants.ReaderHostname); // Assign the TagOpComplete event handler. // This specifies which method to call // when tag operations are complete. reader.TagOpComplete += OnTagOpComplete; // Configure the reader with the default settings. reader.ApplyDefaultSettings(); // Create a tag operation sequence. // You can add multiple read, write, lock, kill and QT // operations to this sequence. TagOpSequence seq = new TagOpSequence(); // Define a tag write operation that sets the access password. TagWriteOp writeOp = new TagWriteOp(); // Assumes that current access password is not set // (zero is the default) writeOp.AccessPassword = null; // The access password is in the Reserved memory bank. writeOp.MemoryBank = MemoryBank.Reserved; // A pointer to the start of the access password. writeOp.WordPointer = WordPointers.AccessPassword; // The new access password to write. writeOp.Data = TagData.FromHexString("11112222"); // Add this tag write op to the tag operation sequence. seq.Ops.Add(writeOp); // Create a tag lock operation to lock the // access password and User memory. TagLockOp lockOp = new TagLockOp(); lockOp.AccessPasswordLockType = TagLockState.Lock; lockOp.UserLockType = TagLockState.Lock; // Add this tag lock op to the tag operation sequence. seq.Ops.Add(lockOp); // Add the tag operation sequence to the reader. // The reader supports multiple sequences. reader.AddOpSequence(seq); // Start the reader reader.Start(); } 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); } // 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(); }
static void Main(string[] args) { try { // Connect to the reader. // Pass in a reader hostname or IP address as a // command line argument when running the example if (args.Length != 1) { Console.WriteLine("Error: No hostname specified. Pass in the reader hostname as a command line argument when running the Sdk Example."); return; } string hostname = args[0]; reader.Connect(hostname); // Assign the TagOpComplete event handler. // This specifies which method to call // when tag operations are complete. reader.TagOpComplete += OnTagOpComplete; // Configure the reader with the default settings. reader.ApplyDefaultSettings(); // 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. // This is very important, since a kill operation is irreversible. target = new TargetTag(); // Select a target tag based on the EPC. target.MemoryBank = MemoryBank.Epc; target.BitPointer = BitPointers.Epc; // The EPC of the target tag. target.Data = TARGET_EPC; // Apply the target tag to the tag operation sequence. seq.TargetTag = target; // Define a tag write operation that sets the kill password. // Tags cannot be killed with a zero password, so we must // set the password to a non-zero value first. TagWriteOp writeOp = new TagWriteOp(); // Assumes that current access password is not set // (zero is the default) writeOp.AccessPassword = null; // The kill password is in the Reserved memory bank. writeOp.MemoryBank = MemoryBank.Reserved; // A pointer to the start of the kill password. writeOp.WordPointer = WordPointers.KillPassword; // The new kill password to write. writeOp.Data = TagData.FromHexString(KILL_PW); // Add this tag write op to the tag operation sequence. seq.Ops.Add(writeOp); // Add the tag operation sequence to the reader. // The reader supports multiple sequences. reader.AddOpSequence(seq); // Start the reader 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 ProgramEpc(string currentEpc, ushort currentPcBits, string newEpc) { try { // Check that the specified EPCs are a valid length if (newEpc.Length % 4 != 0) { MessageBox.Show("El nuevo EPC debe ser multiplo de 4"); return; } // 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); 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); MessageBox.Show("EPC escrito"); } catch { MessageBox.Show("Error al grabar"); return; } }
//bool tag_writeTag(ref ImpinjReader stReader, ref TagInfo stTagInfo,string newEpc, ushort usEpcOpId, ushort usPcBitOpId) bool tag_writeTag(ImpinjReader stReader, TagInfo stTagInfo, string newEpc, ushort usEpcOpId, ushort usPcBitOpId) { Log.WriteLog(LogType.Trace, "come in tag_writeTag"); string currentEpc; ushort currentPcBits; currentEpc = stTagInfo.sEpcHx; currentPcBits = stTagInfo.usPcBits; // 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)"); Log.WriteLog(LogType.Trace, "EPCs must be a multiple of 16 bits (4 hex chars)"); return(false);; } Log.WriteLog(LogType.Trace, "Adding a write operation to change the EPC from :" + currentEpc + " to " + newEpc + ""); try{ // 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 = usEpcOpId; // 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); #if false Console.WriteLine("Adding a write operation to change the PC bits from :"); Console.WriteLine("{0} to {1}\n", currentPcBits.ToString("X4"), newPcBits.ToString("X4")); #else Log.WriteLog(LogType.Trace, "Adding a write operation to change the PC bits from :" + currentPcBits.ToString("X4") + " to " + newPcBits.ToString("X4") + "."); #endif TagWriteOp writePc = new TagWriteOp(); writePc.Id = usPcBitOpId; // 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); //设置tag写标志位 stTagInfo.iTagWState = Macro.TAG_WRITE_INIT; } else { stTagInfo.iTagWState = Macro.TAG_WRITE_MODIFY_LEN; } //将最新的ecp值记录到tag info中,供后续使用 stTagInfo.sEpc = newEpc; // Add the tag operation sequence to the reader. // The reader supports multiple sequences. stReader.AddOpSequence(seq); Log.WriteLog(LogType.Trace, "success to add operation for tag[" + stTagInfo.sTid + "] with ecp op id[" + usEpcOpId + "] and pc bit op id[" + usPcBitOpId + "]"); return(true); } catch (Exception ex) { Log.WriteLog(LogType.Error, "error at tag_writeTag, the message is " + ex.Message + ""); return(false);; } }