1 Attachment(s)
VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)
This code will enable you to encode binary files to Intel HEX format, using I8HEX (8 Byte), I16HEX (16 Byte) or I32HEX (32 Byte).
It also has a separate Checksum calculation function based on something i found here on the forum.
To encode a HEX file, simply add this module to you project and call the function like so :
Code:
Bin2HexFile App.Path & "\printerimage.bmp", App.Path & "\hello.hex"
To verify the HEX files created, google for HEX2BIN (freeware). I had initially attached it in the ZIP, but forum policies here advise against this kind of practice, so it's better to download a converter yourself.
This is useful when uploading binary files (bitmaps, wave files, etc.) to microcontrollers, memories or other types of electronic devices. Maximum file size to encode is about 64KiB, as there are a total of 65535 addresses available.
If you have 16 bytes / address, divide 65535/16 and you get ~4096 addresses of 16 bytes each.
Intermec PD42 printers make use of this format to receive pictures, for example...
Use this code however you wish, i claim absolutely NO copyright over it.
Enjoy !
PS: This works for VB4 - VB6 and is optimised for speed, not for small and efficient code. You may find some optimisations are possible....
Re: VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)
Quote:
Originally Posted by
AndreiMhz
i also included a HEX2BIN decoder
And, although we thank you for your CodeBank submission, per this CodeBank policy, I have edited your attachment and removed it.
We welcome and appreciate all entries into our Codebank, but ask that source code only be included with anything attached.
Thank you.
Re: VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)
Re: VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)
It is a short code, not a fast one.
A quick summary for issues regarding speed include use of the variant version of Mid instead of string version Mid$, Val and conversion of numeric data to string to numeric, ReDim Preserve in a tight loop for each new item, and finally IIf which is one of the worst performing language structures in VB as it is very much just a regular function that can be custom written in VB and it'll be faster – even as a Variant version. The biggest issue is that because it is just a regular function it runs both True and False cases no matter what is the result, so it always does work that doesn't need to be done.
But. I guess this procedure always deals so small amount of data that it won't really matter to make it faster.
Re: VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)
[QUOTE=Merri;3933867]It is a short code, not a fast one.
QUOTE]
You are right... it's not the fastest one that could be done, but it's not the shortest one either. A lot of improvements can be made, in both directions : be it size or be it speed.
:thumb:
But, for 64Kbyte files... as you said. Maybe it's not worth the trouble :)
Re: VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)
Hello,
Firstly, I really thank you!
I'm a newbie about vb and trying to solve a problem.
I am using the code and i got an error below:
"By(q) = <Subscript out of range>"
How can I fix this?
Thank you.