Hello:
Is it possible to have a delay on serial.connected ?
I tried "callsubdelayed", but it does not work
Thank you:
Exp:
Serial1.Connect3(##########,1) Delay before next line or until return true or false
Do something with true or false............
end sub
Private Sub Serial1_Connected (Success As Boolean) As Boolean
If Success Then
Log("Bt_Connected ")
Return True
Else
Log("Bt_Connected")
Return False
End If
End Sub
It's better you change a bit the logic of your code.
Now your logic is connect and stay put until connection established, all in the same sub.
It is much better something like this
B4X:
Sub OpenSerial
Serial1.initialize("serial1")
Serial1.connect(......)
End sub
Sub serial1_connected(success as Boolean) as Boolean
If success then
Call GoOnWithYouHaveToDo
'Or callSubDelayed if the serial I/O code is in a service module
'and you're calling a sub in an activity (normally is better have
'serial code in a service)
Else
Log("Connection problems")
End if
End sub
I tried just like above but the next line fires before the "GoOnWithYouHaveToDo"
then the next line.
Sub OpenSerial
Dim Y as boolean
Serial1.initialize("serial1")
Serial1.connect(......)
log("Connected or not")' I need this to wait until connected or not
End sub
Sub serial1_connected(success asBoolean) as Boolean
If success then
Call GoOnWithYouHaveToDo
Else
Log("Connection problems")
End if
End sub
You don't need any code after serial1.connect
Look at my code. There is an End Sub after the connect.
You can place your log in the sub Serial1_Connected
Think this way:
The code performs .connect
After that line the code ends (End Sub). Your program at that point do nothing. Is just idling. When the connection is established your code restart automatically from the sub Serial1_Connected. If the connection is ok, then success=true! otherwise success will be false.
You can think your serial1 as a button. When you show a button on the screen you don't have to wait the user to press the button. You don't need a code 'wait until someone press'. When (and if) the user press the button your code will automatically jump to the Sub button_click. No need to wait.
With your serial1 is even better. There is also a timeout. The _Connected event will fire when the connection has been established (success=True) or has bene refused or ti ed out (success=false).
I remember I encountered this problem but no the details.. I solved it in unusual way by calling an external delay sub.. (has to be external and does nothing but waste of time) about 1 second delay.