Beispiel #1
0
        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);
        }
Beispiel #2
0
        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;
            }
        }
Beispiel #3
0
        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);
        }
        //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);;
            }
        }