Code: Select all
...
ElseIf EventGadget = #Button_4
Result$ = calculation()
SetGadgetText(#Text_6,Result$)
Code: Select all
...
ElseIf EventGadget = #Button_4
Result$ = calculation()
SetGadgetText(#Text_6,Result$)
Code: Select all
EnableExplicit
Structure AscArray
a.a[0]
EndStructure
Global *buffer.AscArray ; *buffer\a[offset]
Procedure OpenFileAndReadData()
Protected FileBytes.q, FileNum, File$, result
File$ = OpenFileRequester("Please choose file to load", "DATA.bin", "bin (*.bin)|*.bin", 0)
If File$
FileNum = ReadFile(#PB_Any, File$)
If FileNum
FileBytes = Lof(FileNum)
If *buffer : FreeMemory(*buffer) : EndIf
*buffer = AllocateMemory(FileBytes)
If *buffer
ReadData(FileNum, *buffer, FileBytes)
result = 1
EndIf
CloseFile(FileNum)
EndIf
EndIf
ProcedureReturn result
EndProcedure
;--------------------------------------
Procedure.s calculation1()
Protected.a data1, data2, data3, data4
Protected Result$
data1 = (*buffer\a[$1E] ! $10) + $25
data2 = (*buffer\a[$1F] ! $10) + $25
data3 = (*buffer\a[$20] ! $10) + $25
data4 = (*buffer\a[$21] ! $10) + $25
;Result$ = Hex(data1) + Hex(data2) + Hex(data3) + Hex(data4)
Result$ = RSet(Hex(data1), 2, "0") + RSet(Hex(data2), 2, "0") + RSet(Hex(data3), 2, "0") + RSet(Hex(data4), 2, "0")
ProcedureReturn Result$
EndProcedure
;--------------------------------------
Procedure getByte(*buffer, offset) ;this procedure is just for convenience and readability
ProcedureReturn PeekB(*buffer + offset)
EndProcedure
Procedure.s calculation2()
Protected.a data1, data2, data3, data4
Protected Result$
data1 = (getByte(*buffer, $1E) ! $10) + $25
data2 = (getByte(*buffer, $1F) ! $10) + $25
data3 = (getByte(*buffer, $20) ! $10) + $25
data4 = (getByte(*buffer, $21) ! $10) + $25
;Result$ = Hex(data1, #PB_Byte )+Hex(data2, #PB_Byte )+Hex(data3, #PB_Byte )+Hex(data4, #PB_Byte )
Result$ = RSet(Hex(data1), 2, "0") + RSet(Hex(data2), 2, "0") + RSet(Hex(data3), 2, "0") + RSet(Hex(data4), 2, "0")
ProcedureReturn Result$
EndProcedure
;--------------------------------------
Procedure.s calculation3()
Protected.a data1, data2, data3, data4
Protected Result$
data1 = (PeekB(*buffer + $1E) ! $10) + $25
data2 = (PeekB(*buffer + $1F) ! $10) + $25
data3 = (PeekB(*buffer + $20) ! $10) + $25
data4 = (PeekB(*buffer + $21) ! $10) + $25
;Result$ = Hex(data1, #PB_Byte)+Hex(data2, #PB_Byte)+Hex(data3, #PB_Byte)+Hex(data4, #PB_Byte)
Result$ = RSet(Hex(data1), 2, "0") + RSet(Hex(data2), 2, "0") + RSet(Hex(data3), 2, "0") + RSet(Hex(data4), 2, "0")
ProcedureReturn Result$
EndProcedure
Enumeration
#txtValue1
#txtValue2
#txtValue3
#btnOpen
#btnShow
EndEnumeration
Define IsReady, event, eg, et
If OpenWindow(0, 0, 0, 200, 150, "test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadget(#txtValue1, 10, 10, 100, 25, "", #PB_Text_Border)
TextGadget(#txtValue2, 10, 50, 100, 25, "", #PB_Text_Border)
TextGadget(#txtValue3, 10, 90, 100, 25, "", #PB_Text_Border)
ButtonGadget(#btnOpen, 130, 10, 50, 25, "Open")
ButtonGadget(#btnShow, 130, 50, 50, 25, "Show")
Repeat
event = WaitWindowEvent()
If event = #PB_Event_Gadget
eg = EventGadget()
et = EventType()
If eg = #btnOpen And et = #PB_EventType_LeftClick
If OpenFileAndReadData()
IsReady = 1
Else
IsReady = 0
EndIf
SetGadgetText(#txtValue1, "")
SetGadgetText(#txtValue2, "")
SetGadgetText(#txtValue3, "")
ElseIf eg = #btnShow And et = #PB_EventType_LeftClick
If IsReady ;or If *buffer ; must test it !
SetGadgetText(#txtValue1, calculation1()) ; 1480D775 (with your DATA.bin file)
SetGadgetText(#txtValue2, calculation2()) ; 1480D775 (with your DATA.bin file)
SetGadgetText(#txtValue3, calculation3()) ; 1480D775 (with your DATA.bin file)
Else
SetGadgetText(#txtValue1, "No data")
EndIf
EndIf
EndIf
Until event = #PB_Event_CloseWindow
EndIf
Code: Select all
...
ElseIf EventGadget = #Button_4
SetGadgetText(#Text_6, calculation())
Code: Select all
EnableExplicit
Global Dim Bytes.a(1)
Procedure GetByte(FileName.s,Array Output.a(1), Size=0, START=0); by Vitor_Boss®
Protected FileHandle, Result
If FileSize(FileName) > 0
FileHandle = OpenFile(#PB_Any,FileName)
If FileHandle <> 0
If Size = 0
Size = Lof(FileHandle)
EndIf
ReDim Output(Size)
If ArraySize(Output.a()) <> -1
FileSeek(FileHandle, START)
ReadData(FileHandle, @Output(0), Size)
Result=#True
EndIf
CloseFile(FileHandle)
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Procedure OpenFileAndReadData()
Protected File$, result
File$ = OpenFileRequester("Please choose file to load", "DATA.bin", "bin (*.bin)|*.bin", 0)
If File$
ProcedureReturn GetByte(File$, Bytes()); by Vitor_Boss®
EndIf
EndProcedure
Procedure.s calculation(); by Vitor_Boss®
Protected.s data1, data2, data3, data4
data1 = RSet(Hex((Bytes($1E) ! $10) + $25, #PB_Byte), 2, "0"); by breeze4me
data2 = RSet(Hex((Bytes($1F) ! $10) + $25, #PB_Byte), 2, "0")
data3 = RSet(Hex((Bytes($20) ! $10) + $25, #PB_Byte), 2, "0")
data4 = RSet(Hex((Bytes($21) ! $10) + $25, #PB_Byte), 2, "0")
ProcedureReturn data1 + " " + data2 + " " + data3 + " " + data4
EndProcedure
;---------------- by breeze4me ------------------------
Enumeration
#txtValue1
#btnOpen
#btnShow
EndEnumeration
Define IsReady, event, eg, et
If OpenWindow(0, 0, 0, 185, 70, "EEPROM Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadget(#txtValue1, 10, 20, 100, 25, "", #PB_Text_Border)
ButtonGadget(#btnOpen, 130, 5, 50, 25, "Open")
ButtonGadget(#btnShow, 130, 35, 50, 25, "Show")
Repeat
event = WaitWindowEvent()
If event = #PB_Event_Gadget
eg = EventGadget()
et = EventType()
If eg = #btnOpen And et = #PB_EventType_LeftClick
IsReady = OpenFileAndReadData()
SetGadgetText(#txtValue1, "")
ElseIf eg = #btnShow And et = #PB_EventType_LeftClick
If IsReady ;or If *buffer ; must test it !
SetGadgetText(#txtValue1, calculation()) ; 11 80 D7 75 (with your DATA.bin file)
Else
SetGadgetText(#txtValue1, "No data")
EndIf
EndIf
EndIf
Until event = #PB_Event_CloseWindow
EndIf
"11" 80 D7 75 ?Vitor_Boss® wrote:Code: Select all
; 11 80 D7 75 (with your DATA.bin file)
RSet() (PB help file)
...
Example:
Debug RSet("LongString", 4) ; will display "Long"
Code: Select all
Procedure.s calculation()
Protected.s data1, data2, data3, data4
;Bytes($1E) = $FF
Debug Hex((Bytes($1E) ! $10) + $25, #PB_Byte) ;14
Debug Hex((Bytes($1E) ! $10) + $25, #PB_Ascii) ;14
Debug ""
Debug Hex((Bytes($1E) ! $10) + $25, #PB_Long) ;114
Debug Hex((Bytes($1E) ! $10) + $25) ;114
Debug ""
Debug RSet(Hex((Bytes($1E) ! $10) + $25), 2, "0") ;11
Debug RSet(Hex((Bytes($1E) ! $10) + $25), 4, "0") ;0114
data1 = RSet(Hex((Bytes($1E) ! $10) + $25), 2, "0")
data2 = RSet(Hex((Bytes($1F) ! $10) + $25), 2, "0")
data3 = RSet(Hex((Bytes($20) ! $10) + $25), 2, "0")
data4 = RSet(Hex((Bytes($21) ! $10) + $25), 2, "0")
ProcedureReturn data1 + " " + data2 + " " + data3 + " " + data4
EndProcedure
Code: Select all
data1 = RSet(Hex((Bytes($1E) ! $10) + $25), 2, "0")
data2 = RSet(Hex((Bytes($1F) ! $10) + $25), 2, "0")
data3 = RSet(Hex((Bytes($20) ! $10) + $25), 2, "0")
data4 = RSet(Hex((Bytes($21) ! $10) + $25), 2, "0")
Code: Select all
data1 = RSet(Hex((Bytes($1E) ! $10) + $25, #PB_Byte), 2, "0")
data2 = RSet(Hex((Bytes($1F) ! $10) + $25, #PB_Byte), 2, "0")
data3 = RSet(Hex((Bytes($20) ! $10) + $25, #PB_Byte), 2, "0")
data4 = RSet(Hex((Bytes($21) ! $10) + $25, #PB_Byte), 2, "0")
;or .... + $25, #PB_Ascii), ....
What code?breeze4me wrote:"11" 80 D7 75 ?Vitor_Boss® wrote:Code: Select all
; 11 80 D7 75 (with your DATA.bin file)
So I have investigated that strange result.
...
Besides, the second code is much faster.
Vitor_Boss® wrote: What code?
You mean my code?
The replaced code is faster than your original code.Besides, the second code is much faster.
Code: Select all
...
data1 = RSet(Hex((Bytes($1E) ! $10) + $25, #PB_Byte), 2, "0")
data2 = RSet(Hex((Bytes($1F) ! $10) + $25, #PB_Byte), 2, "0")
data3 = RSet(Hex((Bytes($20) ! $10) + $25, #PB_Byte), 2, "0")
data4 = RSet(Hex((Bytes($21) ! $10) + $25, #PB_Byte), 2, "0")
;or .... + $25, #PB_Ascii), ....
...