コード例 #1
0
        public IntelHEXfile(string filename)
        {
            StreamReader sr  = new StreamReader(filename);
            bool         eof = false;

            while (!eof)
            {
                HEXline line = new HEXline(sr.ReadLine());

                switch (line.recordtype)
                {
                case HEXline.RecordType.DataRecord:
                    data.AddRange(line.data);
                    break;

                case HEXline.RecordType.EndOfFile:
                    eof = true;
                    break;
                }

                if (sr.EndOfStream)
                {
                    eof = true;
                }
            }

            sr.Close();
            sr.Dispose();
        }
コード例 #2
0
ファイル: IntelHEXfile.cs プロジェクト: vehar/STM8uLoader
    public IntelHEXfile(string filename)
    {
        if (filename.EndsWith(".hex") != true)
        {
            FileErrorMessages.Add("Файл имеет расширение отличное от hex");
        }

        try
        {
            StreamReader sr         = new StreamReader(filename);
            bool         eof        = false;
            int          lineNumber = 0;
            while (!eof)
            {
                lineNumber++;
                HEXline line = new HEXline(sr.ReadLine(), lineNumber);
                //if (ErrorMessage == "") ErrorMessage = line.ErrorMessages;
                FileErrorMessages.AddRange(line.LineErrorMessages);
                if (line.CriticalErrors == true)
                {
                    CriticalError = true;
                }

                switch (line.recordtype)
                {
                case HEXline.RecordType.DataRecord:
                    //data.AddRange(line.data);
                    int ij = 0;
                    foreach (byte bt in line.data)
                    {
                        AddressByteSorted.Add((long)(line.address + ij), line.data[ij]);
                        ij++;
                    }

                    break;

                case HEXline.RecordType.EndOfFile:
                    eof = true;
                    break;
                }
                if (sr.EndOfStream)
                {
                    eof = true;
                }
            }

            foreach (KeyValuePair <long, byte> dabs in AddressByteSorted)
            {
                Addresses.Add(dabs.Key);
                Bytes.Add(dabs.Value);
            }

            for (int i = 0; i < AddressByteSorted.Count; i++)
            {
                if (Addresses[i] < minAddress)
                {
                    minAddress = Addresses[i];
                }
            }

            for (int i = 0; i < AddressByteSorted.Count; i++)
            {
                if (Addresses[i] > maxAddress)
                {
                    maxAddress = Addresses[i];
                }
            }



            sr.Close();
            sr.Dispose();
        }
        catch (Exception ex)
        {
            ErrorMessage  = ex.Message;
            CriticalError = true;
        }
    }