Reading Intel Hex files 
Author Message
 Reading Intel Hex files

Hi
I have managed to read the contents of a Hex file using
fscanf(fp, %c, *temp), and I now need to remove the first character, :,
and then extract all the relevant information, ie addresses, word
values, etc.
Given that a hex file is written in bytes, ie one char = one nibble, how
does one go about doing this.
All assistance will be gratefully received
TIA
Chris.


Fri, 26 Jan 2001 03:00:00 GMT  
 Reading Intel Hex files

Quote:

> Hi
> I have managed to read the contents of a Hex file using
> fscanf(fp, %c, *temp), and I now need to remove the first character, :,
> and then extract all the relevant information, ie addresses, word
> values, etc.
> Given that a hex file is written in bytes, ie one char = one nibble, how
> does one go about doing this.
> All assistance will be gratefully received
> TIA
> Chris.

Intel Hex files have a standard format.  The method to read them in is
to read the entire line into a buffer than disect it.

You could place a structure "template" over the string to make access
easier.

For example:

typedef struct intel_struct
{
  char  colon;
  char  address[ADDRESS_SIZE];
  char  separator;
  char  bytes_in_record;
  char  separator;
  char  checksum[CHECKSUM_SIZE];
  char  separator2;
  char  data[DATA_RECORD_LENGTH];
  char  terminating_null;

Quote:
} Intel_Hex_String;

Intel_Hex_String  record_read;

int Read_Intel_Hex_String(FILE * input_stream)
{
  int bytes_read;

  bytes_read = fread((char *) &record_read, sizeof(Intel_Hex_String), 1,
input_stream);
  return (bytes_read == sizeof(Intel_Hex_String);

Quote:
}

After the string has been read, use sscanf, strtol, or strtod to convert
the string fields to integer values.

--
Thomas Matthews



Fri, 26 Jan 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Intel hex file format?

2. Intel hex file format?

3. Converting .com or .exe file to Intel hex format

4. Intel hex to Motorola S-record code wanted

5. Reading Hex from File and Putting it in a Packet

6. Reading Disks Directly (Hex Read)

7. Pity Me (Reading Intel Binary on Solaris)

8. Read intel processerid

9. Reading Intel on a SUN in C

10. Read/Write in hex?

11. reading hex

12. How to read Binary/Hex data from the registry

 

 
Powered by phpBB® Forum Software