B4R Question stoped on "for each" loop

Discussion in 'B4R Questions' started by Tayfur, Jul 9, 2019.

  1. Tayfur

    Tayfur Well-Known Member Licensed User

    WEMIS D1 borad

    I run sub of "Ayar_Kaydet_Yukle"

    Code:
    If b.Length>0 Then
            
    Log("#####START READ FILE SYSTEM####")
            Ayar_Kaydet_Yukle(b,
    False)
            
    Log("---FINIS FILE SYSTEMM--------")
            Delay(
    3000)
            
    Log("---<>>> AYAR yükleme tamam")
        
    Else
            
    Log("\\\\\\\ayar içieriği boş//////")
        
    End If
    running code with like under below. and it stoped on "for each" loop

    it s not contiune . it s like stoped.:eek::eek::eek:
    I cant found problem. (I added logs)

    Code:
    Private Sub Ayar_Kaydet_Yukle (Buffer() As Byte,Kaydet As Boolean)
        
    If Kaydet Then
            
    Log("***AYAAR KAYIT*******")
            Dosya.intalize
            Dosya.sil(
    "ayar.txt")
            Dosya.intalize
            Dosya.Kaydet(
    "ayar.txt",Buffer)
           
            
    Log("KAYIT EDİLİEN DATA>>>>>>>>>>")
            
    Log(Buffer)
        
    '    Dosya.ListFiles
        End If
       
        Main.sensor(
    0).TersKapi=False
        Main.sensor(
    1).TersKapi=False
        Main.sensor(
    2).TersKapi=False
        Main.sensor(
    3).TersKapi=False
        
    Log("****>>>AYAR_YUKLE:",Buffer)
       
        
    For Each s() As Byte In bc.Split(Buffer, "&")
            
    Log("Split: ", s)
            
    If bc.IndexOf(s, "mno=") <> -1 Then
                GlobalStore.Put(
    3,bc.SubString(s,"mno=".Length))
                
    'Log("mno=:",GlobalStore.Slot3)
            End If
            
    If bc.IndexOf(s, "ssid=") <> -1 Then
                GlobalStore.Put(
    0,bc.SubString(s,"ssid=".Length))
                
    'Log("wifi_ssid:",GlobalStore.Slot0)
            End If
            
    If bc.IndexOf(s, "psw=") <> -1 Then
                GlobalStore.Put(
    1,bc.SubString(s,"psw=".Length))
                
    'Log("wifi_pass:",GlobalStore.Slot1)
            End If
            
    If bc.IndexOf(s, "a1=") <> -1 Then 'server bağlantı ıp
                Dim o4(4As Byte=SplitIP((bc.SubString(s,"a1=".Length)))          
                GlobalStore.Put(
    2,o4)
                
    'Log("Server_IP:",GlobalStore.Slot2.Length)'returned >> Server_IP:0
                'Log("Server_IP:",GlobalStore.Slot2(0),".",GlobalStore.Slot2(1),".",GlobalStore.Slot2(2),".",GlobalStore.Slot2(3))'returned >> Server_IP:0
            End If
            
    If bc.IndexOf(s, "a2=") <> -1 Then ' server bağlantı poru
                Dim o5 As String=bc.StringFromBytes(bc.SubString(s,"a2=".Length))
                Server_PORT=o5
                
    'Log("Server_PORT:",Server_PORT)
            End If
           
    '        If bc.IndexOf(s, "s1=") <> -1 Then
    '            Log("S1 çalıştı")
    '            Log(bc.SubString(s,"s1=".Length)) 'kapı
    '            Dim z()As Byte=bc.SubString(s,"s1=".Length)
    '            Dim i As UInt=z(0)
    '            If i>48 Then
    '                Main.sensor(1).SensorNo=i-48
    '            Else
    '                Main.sensor(1).SensorNo=0
    '            End If
    '            'Log("sensor-1:::",Main.sensor(1).SensorNo)
    '        End If
    '        If bc.IndexOf(s, "s2=") <> -1 Then
    '            Log("S2 çalıştı")
    '            Log(bc.SubString(s,"s2=".Length)) 'motor
    '            Dim z()As Byte=bc.SubString(s,"s2=".Length)
    '            Dim i As UInt=z(0)
    '            If i>48 Then
    '                Main.sensor(2).SensorNo=i-48
    '            Else
    '                Main.sensor(2).SensorNo=0
    '            End If
    '            'Log("sensor-2:::",Main.sensor(2).SensorNo)
    '        End If
    '        If bc.IndexOf(s, "s3=") <> -1 Then
    '            Log("S3 çalıştı")
    '            Log(bc.SubString(s,"s3=".Length)) 'otomatik
    '            Dim z()As Byte=bc.SubString(s,"s3=".Length)
    '            Dim i As UInt=z(0)
    '            If i>48 Then
    '                Main.sensor(3).SensorNo=i-48
    '            Else
    '                Main.sensor(3).SensorNo=0
    '            End If
    '            'Log("sensor-3:::",Main.sensor(3).SensorNo)
    '        End If
    '        If bc.IndexOf(s, "s4=") <> -1 Then
    '          
    '                Dim z()As Byte=bc.SubString(s,"s4=".Length)
    '                Dim i As UInt=z(0)
    '                If i>48 Then
    '                Main.sensor(0).SensorNo=i-48
    '                Else
    '                Main.sensor(0).SensorNo=0
    '                End If
    '            'Log("sensor-0:::",Main.sensor(0).SensorNo)
    '        End If
            'sayac :0 --- kapı:1----motor:2---lamba:3
            If bc.IndexOf(s, "t4=") <> -1 Then
                Main.sensor(
    0).TersKapi=True
            
    End If
           
            
    If bc.IndexOf(s, "t3=") <> -1 Then
                Main.sensor(
    3).TersKapi=True
            
    End If
           
            
    If bc.IndexOf(s, "t2=") <> -1 Then
                Main.sensor(
    2).TersKapi=True
            
    End If
           
            
    If bc.IndexOf(s, "t1=") <> -1 Then
                Main.sensor(
    1).TersKapi=True
            
    End If
            
    Log("siplit sonu----")
        
    Next
       
        
    If Kaydet Then
            Astream.Write(
    "HTTP/1.1 200").Write(CRLF).Write(CRLF)
            Astream.Write(
    "<html><body>")
            Astream.Write(
    "<head><meta charset='UTF-8' /></head>")
            Astream.Write(
    "<h2>BAGLANTI & AYARLAR KAYIT EDILDI</h2>")
            Astream.Write(
    "<form action='/ayar'>")
            Astream.Write(
    "  <br /> <input Type='submit' value='AYAR sayafasına geri dön' /></form>")
            Astream.Write(
    "<br /><form action='/test'>")
            Astream.Write(
    "  <br /> <input Type='submit' value='TEST sayafasına geri dön' /></form>")
            
    Dim v As String=Rnd(100,999)
            Astream.Write(
    "<br><h1>").Write(v)
            Astream.Write(
    "</body></html>")
        
    End If
       
        
    Log("ayarlar yüklendi...")
    End Sub
    Loading configuration...
    Initializing packages...
    Preparing boards...
    Verifying...
    Wrote 339120 bytes (240799 compressed) at 0x00000000 in 5.5 seconds (effective 497.1 kbit/s)...
    Hash of data verified.
    Leaving...
    Hard resetting via RTS pin...
    ********************* PROGRAM BAŞLIYOR ****************
    Kartek_Metalurji-57
    KARTEK_URETIM-65
    CANPAS_SATIS-82
    File System Initialize result: 1
    dosya okundu
    sending: /ayar.txt
    size: 95
    ------->>
    Read complate:mno=M-23&ssid=KARTEK_URETIM&psw=kalite1980&a1=192.168.1.5&a2=5000&s1=2&s2=7&s3=6&s4=1&t1=0&t4=0
    #####START READ FILE SYSTEM####
    ****>>>AYAR_YUKLE:mno=M-23&ssid=KARTEK_URETIM&psw=kalite1980&a1=192.168.1.5&a2=5000&s1=2&s2=7&s3=6&s4=1&t1=0&t4=0
    Split: mno=M-23
    siplit sonu----
    Split: ssid=KARTEK_URETIM
    siplit sonu----
    Split: psw=kalite1980
    siplit sonu----
    Split: a1=192.168.1.5
    siplit sonu----
    Split: a2=5000
    siplit sonu----
    Split: s1=2
    siplit sonu----
    Split: s2=7
    siplit sonu----
    Split: s3=6
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Does it hang if you comment all the code inside the For Each loop?

    Add Log(StackBufferUsage) in the loop. What is the output?
     
  3. Tayfur

    Tayfur Well-Known Member Licensed User

    #StackBufferSize: 1000

    log is :1664 (after update 2000)

    What is wemos buffer limit?
     
    Last edited: Jul 9, 2019
  4. tigrot

    tigrot Well-Known Member Licensed User

    The limit is free ram.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    You still haven't answered my questions.

    Does it hang if you comment all the code inside the For Each loop?
     
  6. Tayfur

    Tayfur Well-Known Member Licensed User

    Only this loop. I tried first action for called ForEach Loop. and code run normally.

    Now; Stockbuffersize solved my problem.
    thanks
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Another possible (and better) solution is to move all the loop inner code to a different sub. This way the stack will be released after each iteration.
     
    Peter Simpson and Tayfur like this.
  8. Tayfur

    Tayfur Well-Known Member Licensed User

    That's an expert experience.
    I will apply it.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    It should look like this:
    Code:
    For Each s() As Byte In bc.Split(Buffer, "&")
     DoSomething(s)
    Next

    End Sub

    Sub DoSomething(s() As Byte)
     ...
    End Sub
     
    DonManfred and Tayfur like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice