/// <summary> /// Read a page packet from a memory bank and print in hex /// </summary> /// <param name="bank"> PagedMemoryBank to read a page from </param> /// <param name="pg"> page to read </param> public static void dumpBankPagePacket(PagedMemoryBank bank, int pg) { byte[] read_buf = new byte [bank.PageLength]; byte[] extra_buf = new byte [bank.ExtraInfoLength]; int read_rslt; try { // read a page packet (use the most verbose method) if (bank.hasExtraInfo()) { read_rslt = bank.readPagePacket(pg, false, read_buf, 0, extra_buf); } else { read_rslt = bank.readPagePacket(pg, false, read_buf, 0); } Debug.Write("Packet " + pg + ", len " + read_rslt + ": "); hexPrint(read_buf, 0, read_rslt); Debug.WriteLine(""); if (bank.hasExtraInfo()) { Debug.Write("Extra: "); hexPrint(extra_buf, 0, bank.ExtraInfoLength); Debug.WriteLine(""); } } catch (Exception e) { Debug.WriteLine(e); } }
/// <summary> /// Dump valid memory packets from general-purpose memory. /// in the provided MemoryContainer instance. /// /// @parameter owd device to check for memory banks. /// @parameter showContents flag to indicate if the packet memory bank contents will /// be displayed /// </summary> public static void dumpDevicePackets(OneWireContainer owd, bool showContents) { byte[] read_buf, extra_buf; int read_rslt; bool found_bank = false; Stopwatch stopWatch = new Stopwatch(); // 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 mb = (MemoryBank)bank_enum.Current; // check if desired type, only look for packets in general non-volatile if (!mb.GeneralPurposeMemory || !mb.NonVolatile) { continue; } // check if has paged services if (!(mb is PagedMemoryBank)) { continue; } // found a memory bank found_bank = true; // cast to page bank PagedMemoryBank bank = (PagedMemoryBank)mb; // display bank information displayBankInformation(bank); read_buf = new byte [bank.PageLength]; extra_buf = new byte [bank.ExtraInfoLength]; // start timer to time the dump of the bank contents stopWatch.Start(); // loop to read all of the pages in bank bool readContinue = false; for (int pg = 0; pg < bank.NumberPages; pg++) { try { // read a page packet (use the most verbose and secure method) if (bank.hasExtraInfo()) { read_rslt = bank.readPagePacket(pg, readContinue, read_buf, 0, extra_buf); } else { read_rslt = bank.readPagePacket(pg, readContinue, read_buf, 0); } if (read_rslt >= 0) { readContinue = true; if (showContents) { Debug.Write("Packet " + pg + " (" + read_rslt + "): "); hexPrint(read_buf, 0, read_rslt); Debug.WriteLine(""); if (bank.hasExtraInfo()) { Debug.Write("Extra: "); hexPrint(extra_buf, 0, bank.ExtraInfoLength); Debug.WriteLine(""); } } } else { Debug.WriteLine("Error reading page : " + pg); readContinue = false; } } catch (Exception e) { Debug.WriteLine("Exception in reading page: " + e + "TRACE: "); Debug.WriteLine(e.ToString()); Debug.Write(e.StackTrace); readContinue = false; } } stopWatch.Stop(); Debug.WriteLine(" (time to read PACKETS = " + stopWatch.ElapsedMilliseconds + "ms)"); } if (!found_bank) { Debug.WriteLine("XXXX Does not contain any general-purpose non-volatile page memory bank's"); } }