private static void TestAtmelGeneric(string fileName, UInt16[] data16) { UInt16 address = 0; AtmelGeneric grec = new AtmelGeneric(); StreamWriter sw = new StreamWriter(fileName); // Create the first record with data AtmelGenericStructure grecs = grec.NewRecord(address++, data16[0]); grec.Write(sw); // Create another record with the next data point grec.NewRecord(address++, data16[1]); grec.Write(sw); // Create another record with the next data point grec.NewRecord(address++, data16[2]); grec.Write(sw); // Create the last data record with the last data point grec.NewRecord(address++, data16[3]); grec.Write(sw); sw.Close(); Console.WriteLine("Wrote Atmel Generic formatted file: " + fileName); Console.WriteLine("Reading back Atmel Generic file:"); // Open up the new file and attempt to read the records and print to the console StreamReader sr = new StreamReader(fileName); grecs = grec.Read(sr); Console.WriteLine((grecs != null) ? grec.Print() : "Could not read record!"); grecs = grec.Read(sr); Console.WriteLine((grecs != null) ? grec.Print() : "Could not read record!"); grecs = grec.Read(sr); Console.WriteLine((grecs != null) ? grec.Print() : "Could not read record!"); grecs = grec.Read(sr); Console.WriteLine((grecs != null) ? grec.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(); }