private void ReadFileToBuffer(string filename)
        {
            var ext = Path.GetExtension(filename);

            this.Title = "GSM AVR Burner - " + Path.GetFileName(filename);
            if (ext == ".hex")
            {
                _flashBuffer = new IntelHex();
                _flashBuffer.Read(filename);
                AppendLog("Flash Buffer loaded..." + _flashBuffer.DataLength + " bytes");
                UpdateFlashBufferDisplay("");
                UpdateFlashBufferDisplay(ByteArrayToHexString(_flashBuffer.RawData));
            }
            else if (ext == ".eep")
            {
                _eepromBuffer = new IntelHex();
                _eepromBuffer.Read(filename);
                AppendLog("EEPROM Buffer loaded..." + _eepromBuffer.DataLength + " bytes");
                UpdateEepromBufferDisplay("");
                UpdateEepromBufferDisplay(ByteArrayToHexString(_eepromBuffer.RawData));
            }
            else if (ext == ".fuse")
            {
                ReadFuseFile(filename);
            }
            else
            {
                PopupError("Format Not Supported!");
            }
        }
        private void ReloadFileToBuffer()
        {
            try
            {
                if (!string.IsNullOrEmpty(_flashBuffer.Source))
                {
                    AppendLog("Reloading Flash Buffer...", false);
                    _flashBuffer.Read();
                    UpdateFlashBufferDisplay("");
                    UpdateFlashBufferDisplay(ByteArrayToHexString(_flashBuffer.RawData));
                    AppendLog("OK");
                }

                if (!string.IsNullOrEmpty(_eepromBuffer.Source))
                {
                    AppendLog("Reloading EEPROM Buffer...", false);
                    _eepromBuffer.Read();
                    UpdateEepromBufferDisplay("");
                    UpdateEepromBufferDisplay(ByteArrayToHexString(_eepromBuffer.RawData));
                    AppendLog("OK");
                }
            }
            catch (Exception ex)
            {
                AppendLog("FAILED");
                PopupError(ex.Message);
            }
        }
Example #3
0
        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();
        }
Example #4
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();
        }