Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to read a hex file without knowing the memory size? #1

Open
sruthivarghese15 opened this issue Feb 20, 2019 · 4 comments
Open

How to read a hex file without knowing the memory size? #1

sruthivarghese15 opened this issue Feb 20, 2019 · 4 comments

Comments

@sruthivarghese15
Copy link

There seems to have no way to read a hex file without providing the memory size. Or we have to always give a memory size of maximum number in that case?

I'm using

version 2.2.3

.Net core 2.1 Framework

@christophediericx
Copy link
Collaborator

christophediericx commented Feb 22, 2019 via email

@sruthivarghese15
Copy link
Author

In that case what would be the ideal memory size to be provided if I want to read the file for a firmware upgrade?

@dharminec
Copy link

What should be the value of memory size? I passed 0-4096 and all the time I got below exception.

System.IO.IOException: 'Trying to write to position 4096000 outside of memory boundaries (1240000)!'

@lucagiuliodori
Copy link

There seems to have no way to read a hex file without providing the memory size. Or we have to always give a memory size of maximum number in that case?

I'm using

version 2.2.3

.Net core 2.1 Framework

If it can be useful I have inserted the following constructor:

public HexFileReader(string fileName)
        {
            if (!File.Exists(fileName))
                throw new ArgumentException(string.Format("File {0} does not exist!", fileName));

            memorySize = 0;

            System.IO.StreamReader file = new System.IO.StreamReader(fileName);
            while (true)
            {
                string hexRecordLine = file.ReadLine();

                if(hexRecordLine == null)
                {
                    break;
                }

                var hexRecord = HexFileLineParser.ParseLine(hexRecordLine);
                switch (hexRecord.RecordType)
                {
                    case RecordType.Data:
                    {
                        memorySize += hexRecord.ByteCount;
                        break;
                    }
                }
            }
            file.Close();

            Initialize(File.ReadLines(fileName), memorySize);
        }

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants