Exemple #1
0
    /// <summary>
    /// Read a block from a memory bank and print in hex
    /// </summary>
    /// <param name="bank">  MemoryBank to read a block from </param>
    /// <param name="addr">  address to start reading from </param>
    /// <param name="len">   length of data to read </param>
    public static void dumpBankBlock(MemoryBank bank, int addr, int len)
    {
        try
        {
            byte[] read_buf = new byte [len];

            // read the entire bank
            bank.read(addr, false, read_buf, 0, len);
            hexPrint(read_buf, 0, len);
            Debug.WriteLine("");
        }
        catch (Exception e)
        {
            Debug.WriteLine(e);
        }
    }
Exemple #2
0
        private void ReadMemoryBank(MemoryBank mb, out byte[] readBuf)
        {
            int size = mb.Size;

            readBuf = new byte[size];

            byte[][] extraInfo = null;
            try
            {
                Debug.WriteLine("Reading memory...");

                if (mb is PagedMemoryBank)
                {
                    PagedMemoryBank pmb       = (PagedMemoryBank)mb;
                    int             len       = pmb.PageLength;
                    int             numPgs    = (size / len) + (size % len > 0 ? 1 : 0);
                    bool            hasExtra  = pmb.hasExtraInfo();
                    int             extraSize = pmb.ExtraInfoLength;
                    if (hasExtra)
                    {
                        extraInfo[numPgs] = new byte[numPgs];
                        for (var i = 0; i < numPgs; i++)
                        {
                            extraInfo[0] = new byte[extraSize];
                        }
                    }
                    int retryCnt = 0;
                    for (int i = 0; i < numPgs;)
                    {
                        try
                        {
                            bool readContinue = (i > 0) && (retryCnt == 0);
                            if (hasExtra)
                            {
                                pmb.readPage(i, readContinue, readBuf, i * len, extraInfo[i]);
                                Debug.WriteLine("Read Extra Info!");
                            }
                            else
                            {
                                pmb.readPage(i, readContinue, readBuf, i * len);
                            }
                            i++;
                            retryCnt = 0;
                        }
                        catch (Exception e)
                        {
                            if (++retryCnt > 15)
                            {
                                throw e;
                            }
                        }
                    }
                }
                else
                {
                    int retryCnt = 0;
                    while (true)
                    {
                        try
                        {
                            mb.read(0, false, readBuf, 0, size);
                            break;
                        }
                        catch (Exception e)
                        {
                            if (++retryCnt > 15)
                            {
                                throw e;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
                Debug.Write(e.StackTrace);
                return;
            }

            Debug.WriteLine("Done Reading memory...");
        }
Exemple #3
0
    /// <summary>
    /// Dump all of the 1-Wire readable memory in the provided
    /// MemoryContainer instance.
    ///
    /// @parameter owd device to check for memory banks.
    /// @parameter showContents flag to indicate if the memory bank contents will
    ///                      be displayed
    /// </summary>
    public static void dumpDeviceRaw(OneWireContainer owd, bool showContents)
    {
        byte[]    read_buf;
        bool      found_bank = false;
        int       i, reps = 10;
        Stopwatch stopWatch = new Stopwatch();

        // loop through all of the memory banks on device
        // get the port names we can use and try to open, test and close each
        for (System.Collections.IEnumerator bank_enum = owd.MemoryBanks; bank_enum.MoveNext();)
        {
            // get the next memory bank
            MemoryBank bank = (MemoryBank)bank_enum.Current;

            // display bank information
            displayBankInformation(bank);

            // found a memory bank
            found_bank = true;

            try
            {
                read_buf = new byte [bank.Size];

                // get overdrive going so not a factor in time tests
                bank.read(0, false, read_buf, 0, 1);

                // dynamically change number of reps
                reps = 1500 / read_buf.Length;

                if (owd.MaxSpeed == DSPortAdapter.SPEED_OVERDRIVE)
                {
                    reps *= 2;
                }

                if ((reps == 0) || showContents)
                {
                    reps = 1;
                }

                if (!showContents)
                {
                    Debug.Write("[" + reps + "]");
                }

                // start timer to time the dump of the bank contents
                stopWatch.Start();

                // read the entire bank
                for (i = 0; i < reps; i++)
                {
                    bank.read(0, false, read_buf, 0, bank.Size);
                }

                stopWatch.Stop();

                Debug.WriteLine("     (time to read RAW = " + (stopWatch.ElapsedMilliseconds / reps).ToString() + "ms)");

                if (showContents)
                {
                    hexPrint(read_buf, 0, bank.Size);
                    Debug.WriteLine("");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception in reading raw: " + e + "  TRACE: ");
                Debug.WriteLine(e.ToString());
                Debug.Write(e.StackTrace);
            }
        }

        if (!found_bank)
        {
            Debug.WriteLine("XXXX Does not contain any memory bank's");
        }
    }