Android Question How to know serial connecting already !?

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi, Every body

How to know my serial1 connect alreay when i want to connect a new device again?

Dim serial1 As Serial

SelectedDevice.Name = lt1l.Get(res)
SelectedDevice.Mac = PairedDevices.Get(SelectedDevice.Mac)

serial1.Connect(SelectedDevice) 'convert the name to mac address and connect
 

sanduro

Member
Licensed User
Longtime User
It raises serial_connected event

This is what works for me:

B4X:
Sub Ser_Connected(Success As Boolean)

If Success Then
Log("serial connected")
Ser.Listen

'************************PreFIX OR NON PREFIX MODE
''Asyx.Initialize(Ser.InputStream, Ser.OutputStream, "Asyx")

Asyx.InitializePrefix(Ser.InputStream, False, Ser.OutputStream, "Asyx")

Do Until Asyx.IsInitialized 'wait for async
Loop

'I have to WAIT here because Asyx.IsInitialized doesn' mean streams are ready
'Tested with debugger when i pauses here and I continue it works
''If no WAIT is here it never sends the data out
Wait(500)

*NOW you can start sending data

Else
Log("serial NOT connected")

End If
End Sub
 
Upvote 0

sanduro

Member
Licensed User
Longtime User
If you use Bluetooth there is a glitch, when your commucation or app fails from whatever reason serial will keep rfcsocket occupied.
So any fixing and reconecting will not help. i am talking about prefix mode
Did lot of research on that one last 2 months.

It keeps the socket busy even when your app is killed or killed by you.

Then you can run your app for 20 times , everytime you do, you start to occupy new socket.
After that, app will fail on serial.listen with java error that no additional socket is available.

On some version of android you kill the bluetooth completely , you can't even turn on and off button by hand anymore.
Only solution is to reboot the Android and then your app will run again for 20-25 times.

It seems that i have found only 1 possible workaround. if you turn off and turn on BT. This will free all those zombie sockets you have.
But you have to do it before you reach that point of no return state I have descibed above.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…