B4R Question How Use Multithreading in Arduino ?

takhmin77

Member
hi
can i use multithread in arduino

when i use ethernetshield , when its wait to connect to host , other sub routines pause until ethernetshield connect to host or fail to connect.
how i can try to connect to host in another thread ?
 

Michael Sergio

Member
Licensed User
Longtime User
I`m using CallSubPlus.
B4X:
Sub Process_Globals
Public Serial1 As Serial
Private net As Ethernet
Private MacAdress() As Byte= Array As Byte(0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xF0) ' i forgot about that
End Sub
Private Sub AppStart
    Serial1.Initialize(115200)
    CallSubPlus("netConnect", 0, 0)
    Log("AppStart")
End Sub

Sub netConnect(tag As Byte)
    If net.InitializeDHCP(MacAdress) = False Then
        Log("Error connecting to network.")
        CallSubPlus("netConnect", 1000, 0)
        Return
    Else
        Log("Connected to network. My ip address: ", net.LocalIp)
    End If
'...
End Sub
I`m not a pro..but maybe its what you want
 
Last edited:
Upvote 0

takhmin77

Member
thanks
its good but two problem :
1 - when CallSubPlus("netConnect", 1000, 0) is call , program pause.
2 - i want pass string parameter to connect sub and with CallSubPlus , i cant
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
- when CallSubPlus("netConnect", 1000, 0) is call , program pause.
CallSubPlus doesn't cause your program to pause. This is the whole point of using it.
Other things can cause your program to pause.

2 - i want pass string parameter to connect sub and with CallSubPlus , i cant
That's true. Check GlobalStore.
 
Upvote 0
Top