private static void TestIntelHex(string fileName, byte[] data) { IntelHex irec = new IntelHex(); StreamWriter sw = new StreamWriter(fileName); // Create a new type-0 record with data IntelHexStructure irecs = irec.NewRecord(0, 0, data, data.Length); irec.Write(sw); // Create another type-0 record with new data irec.NewRecord(0, 8, data, data.Length); irec.Write(sw); // Create another type-0 record with new data irec.NewRecord(0, 16, data, data.Length); irec.Write(sw); // Create an end of record type-1 record irec.NewRecord(1, 0, null, 0); irec.Write(sw); sw.Close(); Console.WriteLine("Wrote Intel HEX formatted file: " + fileName); Console.WriteLine("Reading back Intel HEX file:"); // Open up the new file and attempt to read the records and print to the console StreamReader sr = new StreamReader(fileName); irecs = irec.Read(sr); Console.WriteLine((irecs != null) ? irec.Print() : "Could not read record!"); irecs = irec.Read(sr); Console.WriteLine((irecs != null) ? irec.Print() : "Could not read record!"); irecs = irec.Read(sr); Console.WriteLine((irecs != null) ? irec.Print() : "Could not read record!"); irecs = irec.Read(sr); Console.WriteLine((irecs != null) ? irec.Print() : "Could not read record!"); sr.Close(); }
static void Main(string[] args) { AtmelGeneric generic; IntelHex ihex; SRecord srec; StreamReader sr = null; if (args.Length < 2) { Console.WriteLine("Usage: TestGIS_RecDump.exe <file format> <file>"); Console.WriteLine("This program will print the records saved in a generic, Intel HEX, or Motorola\nS-Record formatted file.\n"); Console.WriteLine(" <file format> can be generic, ihex, or srecord."); Console.WriteLine(" <file> is the path to the formatted object file."); Environment.Exit(-1); } try { sr = new StreamReader(args[1]); } catch (Exception e) { Console.WriteLine("Error opening file: " + e.Message); Environment.Exit(-1); } if (string.Compare(args[0], "generic") == 0) { generic = new AtmelGeneric(); AtmelGenericStructure gen_s; while (true) { gen_s = generic.Read(sr); if (gen_s != null) { Console.WriteLine(generic.Print(true)); } else { break; } } } else if (string.Compare(args[0], "ihex") == 0) { ihex = new IntelHex(); IntelHexStructure ihex_s; while (true) { ihex_s = ihex.Read(sr); if (ihex_s != null) { Console.WriteLine(ihex.Print(true)); } else { break; } } } else if (string.Compare(args[0], "srecord") == 0) { srec = new SRecord(); SRecordStructure srec_s; while (true) { srec_s = srec.Read(sr); if (srec_s != null) { Console.WriteLine(srec.Print(true)); } else { break; } } } else { Console.WriteLine("Unknown file format specified!"); sr.Close(); Environment.Exit(-1); } sr.Close(); }