Include binary problem
Include binary problem
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
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
> the program fails at the data read stage
So please post this code so we can see why it's failing.
So please post this code so we can see why it's failing.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Code: Select all
DataSection
#file_1:
BERESHEIT
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)

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)
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
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.
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.
oh... and have a nice day.
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.
Code: Select all
ReadFile(file_1, "data.hex")
Edit. In fact you are using several disk file commands when you should be reading from memory.
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
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
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.
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
Should be simple
Try this:
--manu
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