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 SetQtMode(QtDataProfile mode, QtAccessRange range) { // 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"; // We will create two tag operations here. // One to set the QT properties (data profile, access range, persistence) // and another to read back the QT properties of the tag. // Create a new operation to set the QT properties TagQtSetOp qtSetOp = new TagQtSetOp(); // Set the distance range that the tag will be accessible over. qtSetOp.AccessRange = range; // Put the tag into Public or Private mode. // Public mode limits data access to the tag. qtSetOp.DataProfile = mode; // The QT mode will persist, even after the tag is no longer powered. qtSetOp.Persistence = QtPersistence.Permanent; // Add the QT operation to the tag operation sequence. seq.Ops.Add(qtSetOp); // Now, create a tag operation to read the current QT configuration. TagQtGetOp qtGetOp = new TagQtGetOp(); // Add the operation to the sequence. seq.Ops.Add(qtGetOp); // Add the tag operation sequence to the reader. // The reader supports multiple sequences. reader.AddOpSequence(seq); }
static void BulkRead(TagData accessPassword, MemoryBank bank, ushort wordPointer, ushort wordCount) { TagOpSequence seq; TagReadOp op; // Initialize variables tagData = ""; numOpsExecuted = 0; numOpsAdded = 0; // Each TagReadOp can only access up to 32 words. // So, we need to break this read up into multiple operations. while (wordCount > 0) { // Define a new tag operation sequence. seq = new TagOpSequence(); // Define a tag read operation op = new TagReadOp(); op.AccessPassword = accessPassword; op.MemoryBank = bank; op.WordPointer = wordPointer; op.WordCount = (wordCount < 32) ? wordCount : (ushort)32; // Add the read op to the operation sequence seq.Ops.Add(op); // Adjust the word count and pointer for the next reader operation wordCount -= op.WordCount; wordPointer += op.WordCount; // Add the operation sequence to the reader reader.AddOpSequence(seq); numOpsAdded++; } }
static void AddKillOp() { // Create a tag operation sequence. TagOpSequence seq = new TagOpSequence(); // Apply the target tag to the tag operation sequence. seq.TargetTag = target; // Define a tag kill operation. TagKillOp killOp = new TagKillOp(); // Specify the kill password for this tag. // The kill password cannot be zero. killOp.KillPassword = TagData.FromHexString(KILL_PW); // Add this tag write op to the tag operation sequence. seq.Ops.Add(killOp); // Add the tag operation sequence to the reader. reader.AddOpSequence(seq); // Start the reader reader.Start(); }
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 block permalock // operation is irreversible. // The target tag is selected by EPC. seq.TargetTag.MemoryBank = MemoryBank.Epc; seq.TargetTag.BitPointer = BitPointers.Epc; // The EPC of the target tag. seq.TargetTag.Data = TARGET_EPC; // Define a Block Permalock operation. TagBlockPermalockOp blockLockOp = new TagBlockPermalockOp(); // Define which block(s) to lock. // A BlockPermalockMask can be created from a single // block number or an array of block numbers. // This mask permalocks block zero. blockLockOp.BlockMask = BlockPermalockMask.FromBlockNumber(0); // Add the block permalock operation to the tag operation sequence. seq.Ops.Add(blockLockOp); // 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(); // 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"); writeOp.Data = TagData.FromHexString("415543313041303031313631"); // Starting at word 0 writeOp.WordPointer = 0x23; // 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 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(); // Specify a target tag. // The target tag is selected by EPC. seq.TargetTag.MemoryBank = MemoryBank.Epc; seq.TargetTag.BitPointer = BitPointers.Epc; // The EPC of the target tag. seq.TargetTag.Data = TARGET_EPC; // Define a Margin Read operation. TagMarginReadOp marginReadOp = new TagMarginReadOp(); // Define the mask to margin read. // A MarginReadMask can be created from a hexadecimal string or a bit string. // This mask is margin reading 1160. marginReadOp.MarginMask = new MarginReadMask(); marginReadOp.MarginMask.SetMaskFromHexString("1160"); //marginReadOp.MarginMask.SetMaskFromBitString("0001000101100000"); // Define the bit pointer (or "place to start looking") and the memory bank. // We're adding 16 to get to the second word of the EPC. Our TargetTag filter // already ensures the EPC starts with "E280" marginReadOp.BitPointer = BitPointers.Epc + 16; marginReadOp.MemoryBank = MemoryBank.Epc; // Add the margin operation to the tag operation sequence. seq.Ops.Add(marginReadOp); // 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 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 Main(string[] args) { try { // Connect to the reader. // Change the ReaderHostname constant in SolutionConstants.cs // to the IP address or hostname of your reader. Console.WriteLine("*** Connecting to a reader at: {0} ...", SolutionConstants.ReaderHostname); reader.Connect(SolutionConstants.ReaderHostname); Console.WriteLine("*** Connected to the reader."); // Get the default settings // and then modify the settings Settings settings = reader.QueryDefaultSettings(); settings.Report.IncludeAntennaPortNumber = true; settings.Report.IncludePcBits = true; settings.Report.IncludePeakRssi = true; // Set the reader mode, search mode and session settings.ReaderMode = ReaderMode.AutoSetDenseReader; settings.SearchMode = SearchMode.DualTarget; settings.Session = 2; // Enable antenna #1. Disable all others. settings.Antennas.DisableAll(); settings.Antennas.GetAntenna(1).IsEnabled = true; // Set the Transmit Power and // Receive Sensitivity to the maximum. settings.Antennas.GetAntenna(1).MaxTransmitPower = true; settings.Antennas.GetAntenna(1).MaxRxSensitivity = true; // Apply the newly modified settings. reader.ApplySettings(settings); Console.Write("*** Settings applied to the reader.\n"); // Create a tag operation sequence. // You can add multiple read, write, lock, kill and QT // operations to this sequence. TagOpSequence seq = new TagOpSequence(); // Create a tag read operation. TagReadOp readOp = new TagReadOp(); // Read from user memory readOp.MemoryBank = MemoryBank.User; // Read two (16-bit) words readOp.WordCount = 2; // Starting at word 0 readOp.WordPointer = 0; // Add this tag read op to the tag operation sequence. seq.Ops.Add(readOp); // 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. seq.TargetTag.Data = null; // Add the tag operation sequence to the reader. // The reader supports multiple sequences. reader.AddOpSequence(seq); Console.Write("*** OpSequence added to the reader.\n"); // Disconnect from the reader. reader.Disconnect(); Console.Write("*** Disconnected from the reader.\n"); } 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; } }
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(); // Create a tag read operation. TagReadOp readOp = new TagReadOp(); // Read from user memory readOp.MemoryBank = MemoryBank.User; // Read two (16-bit) words readOp.WordCount = 2; // Starting at word 0 readOp.WordPointer = 0; // Add this tag read op to the tag operation sequence. seq.Ops.Add(readOp); // 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 = TagData.FromHexString("11112222333344445555666677778888"); // 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); } }
//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);; } }