WRITE HEX File Format


function writeline(ADDR,RECLEN,RECTYPE:integer;
var buf:buffer):string;
var i:integer;
CHKSUM:byte;

begin
CHKSUM:=0;
result:=':'+inttohex(RECLEN,2)+
inttohex(ADDR,4)+inttohex(RECTYPE,2);
CHKSUM:=RECLEN+lo(ADDR)+hi(ADDR);
for i:=0 to RECLEN-1 do begin
result:=result+inttohex(buf[ADDR+i],2);
CHKSUM:=CHKSUM+buf[ADDR+i];
end;
result:=result+inttohex(256-CHKSUM,2);
end;

function write_eof:string;
begin
result:=':00'+'0000'+'01'+'FF'; // :00000001FF
end;


To test the above routine use this example

procedure TForm1.Button2Click(Sender: TObject);
var Fname,line:string;
Fp : textfile;
ErrorCode,StartAddr,ByteCnt:integer;
A_Line,EOF_HEX:string;
begin

StartAddr:=$0000; // start address
ByteCnt:=3; // 3 bytes
SetLength(HexBufOut,ByteCnt);
HexBufOut[0]:=$01;
HexBufOut[1]:=$02;
HexBufOut[2]:=$03;

Fname:='test1.hex';
AssignFile(Fp,Fname); { File selected in dialog }
Rewrite(Fp);
// write 16 bytes in HexBuf
A_Line:=writeline(StartAddr,ByteCnt,$00,HexBufOut);
EOF_HEX:=':00'+'0000'+'01'+'FF';// write end of HEX file
writeln(Fp,A_Line);
writeln(Fp,EOF_HEX);
closefile(Fp);
end;


Wyszukiwarka

Podobne podstrony:
READ HEX File Format
File Formats And Extensions
def file format
Differing file formats
File Format
file formats recovered by photorec
db tech file format
Auxiliary File Format
POS File Format
fun160 file reg read write en
file8885
Fadal Format 2 (AC) B807 12
file D Download Polki Wirtualna Polska8
Fadal Format 2 [MM] MW60 89
Fadal Format 2 [PEP] M116 89 1
SGH Flasher Dumper v 07 dif format

więcej podobnych podstron