GithubHelp home page GithubHelp logo

menghang / intelhexformatreader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from twinearthsoftware/intelhexformatreader

0.0 1.0 0.0 192 KB

A .NET library to parse an Intel HEX file and emit a representative memory representation.

License: MIT License

C# 100.00%

intelhexformatreader's Introduction

IntelHexFormatReader

A .NET library to parse an Intel HEX file and emit a representative memory representation. This file format is used often for representing code when programming microprocessors and microcontrollers.

IntelHexFormatReader

How to use the .NET library

NuGet version

Link the following nuget package in your project in order to use the Intel HEX format reader: https://www.nuget.org/packages/IntelHexFormatReader/

Alternatively, install the package using the nuget package manager console:

Install-Package IntelHexFormatReader

1. Using HexFileReader

The following minimal snippet demonstrates loading an Intel HEX file and printing out it's resulting memory representation:

using IntelHexFormatReader;

namespace IntelHexFormatReaderDemo
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            HexFileReader reader = new HexFileReader(@"C:\\MyHexFiles\\myHexFile.hex", 32768);
            MemoryBlock memoryRepresentation = reader.Parse();
            foreach (MemoryCell cell in memoryRepresentation.Cells)
                Console.WriteLine(cell);
        }
    }
}

This will resulting in output which might look like this:

MemoryCell : 00000000 Value: 0C (modified = True)
MemoryCell : 00000001 Value: 94 (modified = True)
MemoryCell : 00000002 Value: 72 (modified = True)
MemoryCell : 00000003 Value: 00 (modified = True)
MemoryCell : 00000004 Value: 0C (modified = True)
MemoryCell : 00000005 Value: 94 (modified = True)
MemoryCell : 00000006 Value: 9A (modified = True)
MemoryCell : 00000007 Value: 00 (modified = True)
MemoryCell : 00000008 Value: 0C (modified = True)
MemoryCell : 00000009 Value: 94 (modified = True)
MemoryCell : 0000000A Value: 9A (modified = True)
MemoryCell : 0000000B Value: 00 (modified = True)
MemoryCell : 0000000C Value: 0C (modified = True)
MemoryCell : 0000000D Value: 94 (modified = True)
MemoryCell : 0000000E Value: 9A (modified = True)
MemoryCell : 0000000F Value: 00 (modified = True)
...

Please note that HexFileReader has a second constructor which allows you to pass any IEnumerable<string> directly.

2. Using HexFileLineParser

Alternatively, if you have only a single HEX record line to parse, you can use HexFileLineParser.ParseLine directly:

string hexRecordLine = ":100130003F0156702B5E712B722B732146013421C7";
IntelHexRecord record = HexFileLineParser.ParseLine(hexRecordLine);
Console.WriteLine(record.ByteCount);
Console.WriteLine(record.Address.ToString("X4"));
Console.WriteLine(record.RecordType.ToString());
Console.WriteLine(record.Bytes[5]);
Console.WriteLine(record.Bytes[9]);
Console.WriteLine(record.CheckSum);

This will result in the following output:

16
0130
Data
94
43
199

The HexFileLineParser does fairly exhaustive validation so you should not be able to construct invalid IntelHexRecord objects.

intelhexformatreader's People

Contributors

christophediericx avatar

Watchers

Hang Meng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.