Page 1 of 1
Include binary problem
Posted: Mon May 28, 2007 1:40 pm
by dsw
I am including a data file into some code. When I compile the code the size of the exe file suggests that the data has been included. When I run the program it works as expected but when I try to run the exe on a different machine the program fails at the data read stage. A picture which is also included is fine.
DataSection
#file_1:
IncludeBinary "data.hex"
Image_Image_1:
IncludeBinary "picture.JPG"
EndDataSection
Any pointers would be appreciated this is driving me nuts!
Running PB4 and Windows
Thanks
David
Re: Include binary problem
Posted: Mon May 28, 2007 1:44 pm
by PB
> the program fails at the data read stage
So please post this code so we can see why it's failing.
Posted: Mon May 28, 2007 1:48 pm
by netmaestro
Get rid of the character in front of file_1: and your problem should disappear.
Posted: Mon May 28, 2007 2:28 pm
by dsw
Thanks netmaestro, I tried that but it didn't work. As PB suggests here is the main bit of code (experienced programmers please close your eyes now)
When running on a different machine (or a different location on the main PC) the program fails in Procedure send at the Eof "while" loop
DataSection ;>
file_1:
IncludeBinary "data.hex"
Image_Image_1:
IncludeBinary "picture.JPG"
EndDataSection ;<
;}
;{ Image Plugins
UseJPEGImageDecoder()
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
OpenWindow_Window_0()
Global Conn$
Procedure Send()
serport()
ReadFile(file_1, "data.hex")
Hcom.l = ComOpen(Conn$,#HandShakeModeRtsCts,255,255)
ComSetDTR(Hcom,1)
If Hcom=0
StatusBarText(#StatusBar_Window_0,0,"Connection failed - Check serial port settings")
Else
StatusBarText(#StatusBar_Window_0,0,"Connected to "+Conn$)
Delay(300);to allow receiver to settle after switch on
Beep_(1500,250)
While Eof(file_1)=0 ; loop as long the 'end of file' isn't reached
MyBuffer1.s=ReadString(file_1)+#CR$
ComWrite(Hcom, @MyBuffer1, Len(MyBuffer1))
sizeleft.f=(Lof(file_1)-Loc(file_1))
size.f=Lof(file_1)
percent.f=(1-(sizeleft/size))*100
SetGadgetState(#ProgressBar_5, percent)
Wend ;until the whole file is sent
CloseFile(file_1)
Posted: Mon May 28, 2007 2:34 pm
by Kaeru Gaman
if you had put your code in codetags, it would have been readable.
use the Code-button above the posting area. it will produce these tags: [code][/code]
> Thanks netmaestro, I tried that but it didn't work.
then there is a bug elsewhere, too, but you have to remove the '#' in every case.
a leading '#' describes a constant. the compiler cant recocnize this as a label.
Posted: Mon May 28, 2007 2:37 pm
by Derek
This line in your program
is reading the file from disk even though you have it stored in your program which is why it works on your computer and not on someone elses or yours if you move the file to a different location.
Edit. In fact you are using several disk file commands when you should be reading from memory.
Posted: Mon May 28, 2007 2:53 pm
by dsw
Kaeru Gaman - OK I know how to use the Code button now, thanks for pointing that out.
I did remove the #'s while I was debugging before..
Derek, It sounds like you have it! Trouble is, how do I read a local file(i.e. a file contained in the exe) as opposed to one on the PC...
Thanks for your help
David
Posted: Mon May 28, 2007 2:59 pm
by Derek
Use Restore (with a label name) to set the pointer to the start of the file and then use Read a$ or Read a.s etc
You will have to use a different method instead of eof() to end the loop, something along the lines of counting the length of the strings until you reach the size of the file, which you can work out if you subtract a label at the start of the file from a label at the end.
Try this.
Code: Select all
DataSection
begin:
Data.s "one"
Data.s "two"
Data.s "three"
finish:
EndDataSection
Restore begin
l=0
fl=?finish-?begin
Repeat
Read b$
l+Len(b$)+1
Debug b$
Until l>=fl
Posted: Mon May 28, 2007 3:09 pm
by dsw
Thanks a lot for the tip. That was something I hadn't thought about at all.
Posted: Mon May 28, 2007 3:12 pm
by Derek
You're welcome.

Should be simple
Posted: Wed May 30, 2007 11:57 pm
by manu
Try this:
Code: Select all
file_1_begin:
IncludeBinary "data.hex"
file_1_end:
[...]
size=?file_1_end-?file_1_begin
ComWrite(Hcom, ?file_1_begin, size)
or in smaller blocks to get the progressbar running:
written=0
size=?file_1_end-?file_1_begin
*ptr=?file_1_begin
While written<size
bs=256
If bs>(size-written):bs=size-written:Endif
ComWrite(Hcom, *ptr+written, bs)
written+bs
SetGadgetState(#ProgressBar_5, (100*written)/size)
Wend
--manu
Posted: Thu May 31, 2007 8:09 pm
by dsw
manu,
Thank you! Nice piece of code and it works well
David