B4R Question Joinbytes resets system?

tigrot

Well-Known Member
Licensed User
Longtime User
Hi Everybody
I have a strange issue with Joinbytes.
I'm preparing records to write on a SD file. I use joinbytes to setup the row(it's a text file).
The code is:
B4X:
Dim tmp() As Byte
Main.sd.OpenReadWrite(nome)
Main.Sd.Position = Main.Sd.CurrentFile.Size
If inreportr=False Then      'Scrive intestazione
        inreportr = True
        print ( "COEL METALREMOTE")
        Dim tmp2() As Byte=leggilabel("report", "DR4")
        Log("tmp2:",tmp2," ",Main.d," ",Main.m," ",Main.y)
        tmp=JoinBytes(Array(tmp2 , " ",Main.d,"-",Main.m,"-",Main.y))
        Log(tmp)
        print (tmp )   ' Report degli errori
        tmp=JoinBytes( Array("METAL DETECTOR   : " , Nomemet))
        print (tmp)
        print ( "--------------------------------------------")
End If
The print sub is
B4X:
Sub print (dato() As Byte)
    Log(dato," Lungo:",dato.length)
    Main.sd.Stream.WriteBytes(dato,0,dato.Length)
    Main.sd.Stream.WriteBytes(Array As Byte(13,10),0,2)
    Log(dato)
End Sub
The log is:
B4X:
AppStart
SD init
18Anno:2018
Logouterroridate1
18Anno:2018
Logouterroridate2:2
/logmetal/segnala/METAL1/_2_7.txt
COEL METALREMOTE Lungo:16
COEL METALREMOTE
Search for:DR4=
Findstring:DR4=
Findstring11110123456789101112131415161718192021222324252627282930DR4=SEGNALAZIONE ERRORI
statica.stringa:DR4=SEGNALAZIONE ERRORI
tmp2:DR4=SEGNALAZIONE ERRORI 7 2 2018
AppStart

Appstart repeats after tmp2 log, so I can think the
B4X:
tmp=JoinBytes(Array(tmp2 , " ",Main.d,"-",Main.m,"-",Main.y))
has reset the micro. To void power shortage I have used a V12 A2 power supply, but Issue goes on.
Tmp is built on a byte array(infact a string, tmp2) and three int's(day, month, year)

Any idea?

Thank you for support

Mauro Zanin
 
Last edited:

tigrot

Well-Known Member
Licensed User
Longtime User
Update:
if i put
B4X:
 print ( "COEL METALREMOTE")
main.sd.close
return
The row(along with CR/NL) is printed in SD. No record is written without close , probably because main.sd.close at the end of sub is not reached.
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Hi Erel, I have a lot of spare RAM, so I can try to encrease the stack size. This is a porting of an old and large VB6 program, so using single WriteBytes has a large impact on coding. I didn't realize I was running out of stack.
Thank you
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Unfortunatelly I have encreased stackbuffer size to 2000(2500 ram bytes left) and have the same issue. This is the failing statement:
B4X:
tmp=JoinBytes(Array( " ".GetBytes,Main.d,"-".GetBytes,Main.m,"-".GetBytes,Main.y))
I have taken out the byte array, but no success.
from log you can see that the int's contains correct data.
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
B4X:
    tmp=JoinBytes(Array(tmp2, " ".GetBytes,NumberFormat(Main.d,2,0),"-".GetBytes,NumberFormat(Main.m,2,0),"-".GetBytes,Main.anno))
This crashes the Mega 2560 as well. anno is a string, m and n integers, amd tmp2 a byte array.
I decided to change everything and get rid of JoinBytes.
 
Upvote 0
Top