Beispiel #1
0
        public void ReadMemory(ulong address, uint size, OnMemoryRead onMemoryRead)
        {
            var command = new ReadMemory(address, size, OnMemoryRead);

            OnMemoryReadMap.Add(command, onMemoryRead);

            GDBClient.SendCommand(command);
        }
Beispiel #2
0
 public void ReadToBuffer()
 {
     ReadMemory.Clear();
     ReadMemory = ReadBuffer;
     ReadBuffer.Clear();
     string[] cleanedInput = Console.ReadLine().ToLower().Trim().Split(Delimiters, StringSplitOptions.RemoveEmptyEntries);
     foreach (string x in cleanedInput)
     {
         ReadBuffer.Add(x);
     }
 }
        public static List <byte> MemoryLockStatus(Reader reader, byte blockLength, TagProtocol protocol, string uid)
        {
            List <byte> lockStatus = new List <byte>();
            TagFilter   filter;

            byte[] _uid = ByteFormat.FromHex(uid);

            switch (protocol)
            {
            case TagProtocol.ISO14443A:
                break;

            case TagProtocol.ISO14443B:
                break;

            case TagProtocol.ISO15693:
                //Iso15693.TagType tag = (Iso15693.TagType)tagType;//(Enum.GetName(typeof(Iso15693.TagType), tagType));
                filter = new Select_UID((byte)(_uid.Length * 8), _uid);
                MemoryType type        = MemoryType.BLOCK_PROTECTION_STATUS_MEMORY;
                ReadMemory blockStatus = new ReadMemory(type, 0, blockLength);
                lockStatus.AddRange((byte[])reader.ExecuteTagOp(blockStatus, filter));
                break;

            case TagProtocol.ISO180003M3:
                break;

            case TagProtocol.ISO180006B:
                break;

            case TagProtocol.ISO180006B_UCODE:
                break;

            case TagProtocol.ISO18092:
                break;

            case TagProtocol.LF125KHZ:
                break;

            case TagProtocol.LF134KHZ:
                break;

            case TagProtocol.NONE:
                break;

            default:
                break;
            }

            return(lockStatus);
        }
Beispiel #4
0
        private void startProbe(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                if (bgwMemProbe.CancellationPending == true)
                {
                    e.Cancel = true;
                    break;
                }
                else
                {
                    Thread.Sleep(Convert.ToInt32(numPollRate.Value));

                    long   memAddress = long.Parse(txtMemAddr.Text, NumberStyles.HexNumber);
                    string memValue;
                    memValue = ReadMemory.GetString(memAddress, txtProcName.Text, Convert.ToInt32(numChunkSize.Value));

                    bgwMemProbe.ReportProgress(0, memValue);
                }
            }
        }
        /// <summary>
        /// Get the Memory Architecture of the ISO15693 tags.
        /// </summary>
        /// <param name="reader">Connected reader</param>
        /// <param name="tag">ISO15693 Tag type of the seclected tag</param>
        /// <param name="uid">UID of the selected tag</param>
        /// <returns>Returns memory organisation in String Array</returns>
        public static Dictionary <string, byte> Get15693AMemoryLayout(Reader reader, Iso15693.TagType tag, string uid)
        {
            Dictionary <string, byte> tagMemorystruct = new Dictionary <string, byte>();

            //paramget to get the memory organisation

            //we will have the object which contains the tag info

            byte[]    _uid   = ByteFormat.FromHex(uid);
            TagFilter filter = new Select_UID((byte)(_uid.Length * 8), _uid);


            //TagFilter filter=new Select_TagType((UInt32)tag);
            MemoryType readType     = MemoryType.BLOCK_SYSTEM_INFORMATION_MEMORY;
            ReadMemory systemInfoOp = new ReadMemory(readType, 0, 0);

            byte[] systemInfo = (byte[])reader.ExecuteTagOp(systemInfoOp, filter);

            #region Info Flag
            byte infoFlag         = systemInfo[0];
            int  systemInfoOffSet = 9;
            if ((infoFlag & 0x0001) == 0x0001)
            {
                byte dsfid = systemInfo[systemInfoOffSet++];
                tagMemorystruct.Add("DSFID", dsfid);
            }
            if ((infoFlag & 0x0002) == 0x0002)
            {
                byte afi = systemInfo[systemInfoOffSet++];
                tagMemorystruct.Add("AFI", afi);
            }
            if ((infoFlag & 0x0004) == 0x0004)
            {
                tagMemorystruct.Add("Block Size", systemInfo[systemInfoOffSet++]);
                tagMemorystruct.Add("Block Count", systemInfo[systemInfoOffSet++]);
            }
            #endregion

            return(tagMemorystruct);
        }
        /// <summary>
        /// Get data after the exception
        /// </summary>
        /// <param name="reader">Connected reader</param>
        /// <param name="filter">Tag filter</param>
        /// <param name="address">Start address</param>
        /// <param name="blockSize">Size of each block</param>
        /// <returns>Returns byte array</returns>
        private static byte[] ReadData(Reader reader, TagFilter filter, uint address, int blockSize)
        {
            byte[]     data     = new byte[blockSize];
            MemoryType readType = MemoryType.BLOCK_MEMORY;
            ReadMemory readData = new ReadMemory(readType, address, 1);

            try
            {
                //throw new Exception("1584");
                data = (byte[])reader.ExecuteTagOp(readData, filter);
            }
            catch (Exception ex)//add the correct exception
            {
                if (ex.Message.Contains("04A7"))
                {
                    for (int i = 0; i < data.Length; i++)
                    {
                        data[i] = 00;
                    }
                }
                //throw;
            }
            return(data);
        }
Beispiel #7
0
        void ReleaseDesignerOutlets()
        {
            if (asRingPlusVersion != null)
            {
                asRingPlusVersion.Dispose();
                asRingPlusVersion = null;
            }

            if (BarcodeOption != null)
            {
                BarcodeOption.Dispose();
                BarcodeOption = null;
            }

            if (BarcodeScan != null)
            {
                BarcodeScan.Dispose();
                BarcodeScan = null;
            }

            if (batteryImage != null)
            {
                batteryImage.Dispose();
                batteryImage = null;
            }

            if (buzzerButton != null)
            {
                buzzerButton.Dispose();
                buzzerButton = null;
            }

            if (buzzerTextField != null)
            {
                buzzerTextField.Dispose();
                buzzerTextField = null;
            }

            if (Inventory != null)
            {
                Inventory.Dispose();
                Inventory = null;
            }

            if (labelBluetoothAddr != null)
            {
                labelBluetoothAddr.Dispose();
                labelBluetoothAddr = null;
            }

            if (labelDemoVer != null)
            {
                labelDemoVer.Dispose();
                labelDemoVer = null;
            }

            if (labelFirmwareVer != null)
            {
                labelFirmwareVer.Dispose();
                labelFirmwareVer = null;
            }

            if (LockMemory != null)
            {
                LockMemory.Dispose();
                LockMemory = null;
            }

            if (logoImage != null)
            {
                logoImage.Dispose();
                logoImage = null;
            }

            if (mainScrollView != null)
            {
                mainScrollView.Dispose();
                mainScrollView = null;
            }

            if (ReadMemory != null)
            {
                ReadMemory.Dispose();
                ReadMemory = null;
            }

            if (regionLabel != null)
            {
                regionLabel.Dispose();
                regionLabel = null;
            }

            if (RFIDOption != null)
            {
                RFIDOption.Dispose();
                RFIDOption = null;
            }

            if (snLabel != null)
            {
                snLabel.Dispose();
                snLabel = null;
            }

            if (ufVersion != null)
            {
                ufVersion.Dispose();
                ufVersion = null;
            }

            if (vibratorButton != null)
            {
                vibratorButton.Dispose();
                vibratorButton = null;
            }

            if (vibratorTextField != null)
            {
                vibratorTextField.Dispose();
                vibratorTextField = null;
            }

            if (WriteMemory != null)
            {
                WriteMemory.Dispose();
                WriteMemory = null;
            }
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            // Program setup
            if (1 > args.Length)
            {
                Usage();
            }

            for (int nextarg = 1; nextarg < args.Length; nextarg++)
            {
                string arg = args[nextarg];
                if (arg.Equals("--ant"))
                {
                    if (null != antennaList)
                    {
                        Console.WriteLine("Duplicate argument: --ant specified more than once");
                        Usage();
                    }
                    antennaList = ParseAntennaList(args, nextarg);
                    nextarg++;
                }
                else
                {
                    Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg);
                    Usage();
                }
            }

            try
            {
                // Create Reader object, connecting to physical device.
                // Wrap reader in a "using" block to get automatic
                // reader shutdown (using IDisposable interface).
                using (r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
                    {
                        Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
                        if (supportedRegions.Length < 1)
                        {
                            throw new FAULT_INVALID_REGION_Exception();
                        }
                        r.ParamSet("/reader/region/id", supportedRegions[0]);
                    }
                    string model = (string)r.ParamGet("/reader/version/model").ToString();
                    if (!model.Equals("M3e"))
                    {
                        if (r.isAntDetectEnabled(antennaList))
                        {
                            Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
                            Usage();
                        }
                        //Use first antenna for operation
                        if (antennaList != null)
                        {
                            r.ParamSet("/reader/tagop/antenna", antennaList[0]);
                        }
                    }
                    else
                    {
                        if (antennaList != null)
                        {
                            Console.WriteLine("Module doesn't support antenna input");
                            Usage();
                        }
                    }

                    // This select filter matches all Gen2 tags where bits 32-48 of the EPC are 0x0123
#if ENABLE_FILTER
                    TagFilter filter = new Gen2.Select(false, Gen2.Bank.EPC, 32, 16, new byte[] { 0x01, 0x23 });
#endif
                    if (!model.Equals("M3e"))
                    {
                        //Gen2.TagData epc = new Gen2.TagData(new byte[] {
                        //    0x01, 0x23, 0x45, 0x67, 0x89, 0xAB,
                        //    0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67,
                        //});
                        //Gen2.WriteTag tagop = new Gen2.WriteTag(epc);
                        //r.ExecuteTagOp(tagop, null);
                    }

                    // Reads data from a tag memory bank after writing data to the requested memory bank without powering down of tag
#if ENABLE_READ_AFTER_WRITE
                    {
                        //create a tagopList with write tagop followed by read tagop
                        TagOpList tagopList = new TagOpList();
                        byte      wordCount;
                        ushort[]  readData;

                        //Write one word of data to USER memory and read back 8 words from EPC memory using WriteData and ReadData
                        {
                            ushort[] writeData = { 0x9999 };
                            wordCount = 8;
                            Gen2.WriteData wData = new Gen2.WriteData(Gen2.Bank.USER, 2, writeData);
                            Gen2.ReadData  rData = new Gen2.ReadData(Gen2.Bank.EPC, 0, wordCount);
                            //Gen2.WriteTag wTag = new Gen2.WriteTag(epc);

                            // assemble tagops into list
                            tagopList.list.Add(wData);
                            tagopList.list.Add(rData);

                            Console.WriteLine("###################Embedded Read after write######################");
                            // uncomment the following for embedded read after write.
                            embeddedRead(TagProtocol.GEN2, null, tagopList);

                            // call executeTagOp with list of tagops
                            //readData = (ushort[])r.ExecuteTagOp(tagopList, null);
                            //Console.WriteLine("ReadData: ");
                            //foreach (ushort word in readData)
                            //{
                            //    Console.Write(" {0:X4}", word);
                            //}
                            //Console.WriteLine("\n");
                        }

                        //clearing the list for next operation
                        tagopList.list.Clear();

                        //Write 12 bytes(6 words) of EPC and read back 8 words from EPC memory using WriteTag and ReadData
                        {
                            Gen2.TagData epc1 = new Gen2.TagData(new byte[] {
                                0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
                                0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc,
                            });
                            wordCount = 8;
                            Gen2.WriteTag wtag  = new Gen2.WriteTag(epc1);
                            Gen2.ReadData rData = new Gen2.ReadData(Gen2.Bank.EPC, 0, wordCount);

                            // assemble tagops into list
                            tagopList.list.Add(wtag);
                            tagopList.list.Add(rData);

                            // call executeTagOp with list of tagops
                            //readData = (ushort[])r.ExecuteTagOp(tagopList, null);
                            //Console.WriteLine("ReadData: ");
                            //foreach (ushort word in readData)
                            //{
                            //    Console.Write(" {0:X4}", word);
                            //}
                            //Console.WriteLine("\n");
                        }
                    }
#endif

                    // Perform read and print UID and tagtype of tag found
                    SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.ISO15693, null, null, 1000);
                    r.ParamSet("/reader/read/plan", plan);
                    TagReadData[] tagReads = r.Read(1000);
                    Console.WriteLine("UID: " + tagReads[0].EpcString);
                    Console.WriteLine("TagType:  " + (Iso15693.TagType)(tagReads[0].TagType));
                    MemoryType  type;
                    MultiFilter mulfilter = null;
                    UInt32      address;
                    byte        length;

#if ENABLE_M3E_FILTER
                    //Initialize filter
                    // Filters the tag based on tagtype
                    TagFilter tagTypeFilter = new Select_TagType((UInt64)((Iso15693.TagType)(tagReads[0].TagType)));
                    // Filters the tag based on UID
                    TagFilter uidFilter = new Select_UID(32, ByteFormat.FromHex(tagReads[0].Tag.EpcString.Substring(0, 8)));
                    // Initialize multi filter
                    mulfilter = new MultiFilter(new TagFilter[] { tagTypeFilter, uidFilter });
#endif

#if ENABLE_M3E_BLOCK_READ_WRITE
                    //Initialize all the fields required for Read Data Tag operation
                    type    = MemoryType.BLOCK_MEMORY;
                    address = 0;
                    length  = 1;

                    // Read memory before write
                    ReadMemory bRead    = new ReadMemory(type, address, length);
                    byte[]     dataRead = (byte[])r.ExecuteTagOp(bRead, mulfilter);

                    // prints the data read
                    Console.WriteLine("Read Data before performing block write: ");
                    foreach (byte i in dataRead)
                    {
                        Console.Write(" {0:X2}", i);
                    }
                    Console.WriteLine("\n");
                    // Uncomment this to enable Embedded read memory
                    //embeddedRead(TagProtocol.ISO15693, mulfilter, bRead);

                    // Initialize write memory
                    byte[]      data    = new byte[] { 0x11, 0x22, 0x33, 0x44 };
                    WriteMemory writeOp = new WriteMemory(type, address, data);

                    // Execute the tagop
                    r.ExecuteTagOp(writeOp, mulfilter);
                    // Uncomment this to enable Embedded write data
                    //embeddedRead(TagProtocol.ISO15693, mulfilter, writeOp);

                    //Read memory after block write
                    ReadMemory readOp   = new ReadMemory(type, address, length);
                    byte[]     readData = (byte[])r.ExecuteTagOp(readOp, mulfilter);

                    // prints the data read
                    Console.WriteLine("Read Data after performing block write operation: ");
                    foreach (byte i in readData)
                    {
                        Console.Write(" {0:X2}", i);
                    }
                    Console.WriteLine("\n");
#endif

#if ENABLE_M3E_SYSTEM_INFORMATION_MEMORY
                    //Get the system information of tag. Address and length fields have no significance if memory type is BLOCK_SYSTEM_INFORMATION_MEMORY.
                    type    = MemoryType.BLOCK_SYSTEM_INFORMATION_MEMORY;
                    address = 0;
                    length  = 0;
                    ReadMemory sysInfoOp  = new ReadMemory(type, address, length);
                    byte[]     systemInfo = (byte[])r.ExecuteTagOp(sysInfoOp, mulfilter);

                    // parsing the system info response
                    if (systemInfo.Length > 0)
                    {
                        parseGetSystemInfoResponse(systemInfo);
                    }
#endif

#if ENABLE_M3E_SECURE_ID
                    // Read secure id of tag. Address and length fields have no significance if memory type is SECURE_ID.
                    type    = MemoryType.SECURE_ID;
                    address = 0;
                    length  = 0;
                    ReadMemory secureIdOp = new ReadMemory(type, address, length);
                    byte[]     rspData    = (byte[])r.ExecuteTagOp(secureIdOp, mulfilter);

                    // parse secure id operation response.
                    if (rspData.Length > 0)
                    {
                        parseSecureIdResponse(rspData);
                    }
#endif

#if ENABLE_M3E_BLOCK_PROTECTION_STATUS
                    // Get the block protection status of block 0.
                    type    = MemoryType.BLOCK_PROTECTION_STATUS_MEMORY;
                    address = 0;
                    length  = 1;
                    ReadMemory blkProtectionOp = new ReadMemory(type, address, length);
                    byte[]     statusData      = (byte[])r.ExecuteTagOp(blkProtectionOp, mulfilter);

                    // parse the block protection status response.
                    if (statusData.Length == length)
                    {
                        parseGetBlockProtectionStatusResponse(statusData, address, length);
                    }
#endif
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
        /// <summary>
        /// Get the data from the tag
        /// </summary>
        /// <param name="reader">Connected reader</param>
        /// <param name="filter">Tag Filter</param>
        /// <param name="blockSize">Size of each memory block</param>
        /// <param name="blockCount">No of memory blocks in the tag</param>
        /// <param name="actualBlockCount">Returns the actual block count of the tag</param>
        /// <returns>Return list of data </returns>
        private static List <byte> GetTagData(Reader reader, TagFilter filter, int blockSize, byte blockCount, ref byte actualBlockCount)
        {
            List <byte> data           = new List <byte>();
            byte        blockCountSize = (byte)((blockSize == 16) ? 15 : 60);//RIGHT NOW WE HAVE ONLY BLOCK SIZE A 4 BYTE AND 16 BYTE SO WE ARE SENDING 60 BLOCK AND 15 BLOCK.
            MemoryType  readType       = MemoryType.BLOCK_MEMORY;
            uint        address        = 0;

            Lockstatus.Clear();
            if (blockCount == 0)//this section is for ISO14443A
            {
                try
                {
                    while (true)
                    {
                        ReadMemory readData = new ReadMemory(readType, address, blockCountSize);
                        data.AddRange((byte[])reader.ExecuteTagOp(readData, filter));
                        address += blockCountSize;
                        for (int i = 0; i < blockCountSize; i++)
                        {
                            Lockstatus.Add(00);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("A command was received to write to an invalid address in the tag data address space.") || ex.Message.Contains("04A7"))
                    {
                        try
                        {
                            while (true)
                            {
                                try
                                {
                                    ReadMemory readData = new ReadMemory(readType, address, 1);
                                    data.AddRange((byte[])reader.ExecuteTagOp(readData, filter));
                                    address += 1;
                                    Lockstatus.Add(00);
                                }
                                catch (Exception ex2)
                                {
                                    if (ex2.Message.Contains("04A7"))
                                    {
                                        byte[] defaultData = new byte[blockSize];
                                        for (int i = 0; i < defaultData.Length; i++)
                                        {
                                            defaultData[i] = 00;
                                        }
                                        data.AddRange(defaultData);
                                        address += 1;
                                        Lockstatus.Add(01);
                                        continue;
                                    }
                                    else
                                    {
                                        throw ex2;
                                    }
                                }
                            }
                        }
                        catch (Exception ex1)
                        {
                            if (ex1.Message.Contains("A command was received to write to an invalid address in the tag data address space."))
                            {
                                actualBlockCount = (byte)address;
                                return(data);
                            }
                            else
                            {
                                throw ex1;
                            }
                        }
                        actualBlockCount = (byte)address;
                        return(data);
                    }
                }
            }
            else// this section is for IOS15693
            {
                if ((blockCount * blockSize) <= 240)//it finds can we bring the whole data in one command.
                {
                    ReadMemory readData = new ReadMemory(readType, address, blockCount);
                    //BlockReadErrorHandle(reader, filter, blockCount, 0, blockSize);
                    try
                    {
                        data.AddRange((byte[])reader.ExecuteTagOp(readData, filter));
                    }
                    catch (Exception ex)//proper exception code need to be added
                    {
                        if (ex.Message.Contains("04A7"))
                        {
                            data.AddRange(BlockReadErrorHandle(reader, filter, blockCount, 0, blockSize));
                        }
                        //throw;
                    }

                    return(data);
                }
                else
                {
                    UInt32 startAddress = 0;
                    bool   exitRead     = true;
                    byte   blockLength  = (byte)(240 / blockSize);
                    try
                    {
                        while (exitRead)
                        {
                            if (blockCount > blockLength)
                            {
                                blockCount -= blockLength;
                                ReadMemory readData = new ReadMemory(readType, startAddress, blockLength);
                                data.AddRange((byte[])reader.ExecuteTagOp(readData, filter));
                                startAddress += blockLength;
                            }
                            else if (blockCount <= blockLength)
                            {
                                ReadMemory readData = new ReadMemory(readType, startAddress, blockCount);
                                data.AddRange((byte[])reader.ExecuteTagOp(readData, filter));
                                blockCount -= blockCount;
                            }

                            if (blockCount <= 0)
                            {
                                exitRead = false;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.Contains("04A7"))
                        {
                            data.AddRange(BlockReadErrorHandle(reader, filter, blockCount, startAddress, blockSize));
                        }
                    }
                }
            }
            actualBlockCount = (byte)address;//(byte)(address-4);
            return(data);
        }
Beispiel #10
0
 public void StopApp()
 {
     Console.WriteLine("Stop App");
     ReadMemory.CancelAsync();
 }
Beispiel #11
0
 public void StartApp()
 {
     Console.WriteLine("Starting App");
     ReadMemory.RunWorkerAsync();
 }