예제 #1
0
        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();
        }
예제 #2
0
        private static void TestSRecord(String title, String fileName, byte[] data)
        {
            SRecord srec = new SRecord();
            StreamWriter sw = new StreamWriter(fileName);

            // Create a new S0 record with the title
            SRecordStructure srecs = srec.NewRecord(0, 0, Encoding.ASCII.GetBytes(title), title.Length);
            srec.Write(sw);

            // Create a S1 data record
            srec.NewRecord(1, 0, data, data.Length);
            srec.Write(sw);

            // Create a S5 transmission record
            srec.NewRecord(5, 1, null, 0);
            srec.Write(sw);

            // Create a S9 program start record
            srec.NewRecord(9, 0, null, 0);
            srec.Write(sw);
            sw.Close();

            Console.WriteLine("Wrote Motorola S-Record formatted file: " + fileName);
            Console.WriteLine("Reading back Motorola S-Record file:");

            // Open up the new file and attempt to read the records and print to the console
            StreamReader sr = new StreamReader(fileName);
            srecs = srec.Read(sr);
            Console.WriteLine((srecs != null)? srec.Print() : "Could not read record!");
            srecs = srec.Read(sr);
            Console.WriteLine((srecs != null) ? srec.Print() : "Could not read record!");
            srecs = srec.Read(sr);
            Console.WriteLine((srecs != null) ? srec.Print() : "Could not read record!");
            srecs = srec.Read(sr);
            Console.WriteLine((srecs != null) ? srec.Print() : "Could not read record!");
            sr.Close();
        }