Serial library and Android 4

dsirio75

Member
Licensed User
Longtime User
Hi all, i have a problem with the serial library on an android 4 device (Galaxy Tab).

My app connects perfectly an OBD device with my motorola atrix (2.3.4) but when i try my app on Galaxy Tab (ICS) it won't connect.

Return me java exceptions saying "Invalid Exchange" and asks me to pair device again (i already did it).

Some idea? Tried Connect3 and ConnectInsecure with port 1 but didn't work...

Here's my code for the connection

B4X:
Sub Admin_DiscoveryFinished
   ProgressDialogHide
   If foundDevices.Size = 0 Then
      ...
   Else
      Dim l As List
      l.Initialize
      For i = 0 To foundDevices.Size - 1
         Dim nm As NameAndMac
         nm = foundDevices.Get(i)
         l.Add(nm.Name)
      Next
      Dim res As Int
      res = InputList(l, "Select", -1)
      If res <> DialogResponse.CANCEL Then
         connectedDevice = foundDevices.Get(res)
         serial1.Connect(connectedDevice.Mac)
      End If
   End If
End Sub

Thanks
 

dsirio75

Member
Licensed User
Longtime User
Today i will connect my Tab with the car and a laptop with B4A to view exact log.

By the way when i try to connect Tab to Phone with Bluetooth example i get this...

B4X:
:78:CA:04:C4:F8:97
:A0:75:91:E7:C0:10
DanAtrix:3C:43:8E:32:43:70
LG GW300:5C:17:D3:0C:2F:A5
E2550:3C:5A:37:B4:DF:A7
Giuliana:78:CA:04:C4:F8:97
:00:1C:43:C1:D2:71
Iva:00:1C:43:C1:D2:71
connected: false
java.io.IOException: Unable to start Service Discovery

When i connect phone to tab instead all works
 
Upvote 0

dsirio75

Member
Licensed User
Longtime User
Is There difference between WiFI Mac address and Bluetooth Mac? As i can see i discover my phone with a Mac which ends with 2 chars different from real Mac (i read it in wifi advanced settings)...
 
Upvote 0

dsirio75

Member
Licensed User
Longtime User
Ok, so my problem is in Serial1.Connect. I get "Unable to start Service Discovery" with .Connect and "Connection refused" with .Connect3 ...

Some Idea?
If is not related to Android 4 can be related to Galaxy Tab? And why? :)
 
Upvote 0

dsirio75

Member
Licensed User
Longtime User
I already did that...
It asks always to pair devices ... but they are already paired...

I tried to install CM9 (Android4) to my Atrix and it works too... Don't know what to do now...
 
Upvote 0

dsirio75

Member
Licensed User
Longtime User
I have a doubt:
My Tab 2 has bluetooth 3
Atrix has 2

Maybe a bluetooth 2 can't receive connections from 3 with Serial library?
 
Upvote 0

dsirio75

Member
Licensed User
Longtime User
So Galaxy Tab 2 can't use Serial library to connect other bluetooth devices (OBDII in this case) ...
This is a problem for me because other apps can connect to that device from Tab ...

Thank you Erel for your support for now.
 
Upvote 0

dsirio75

Member
Licensed User
Longtime User
After many searches i found an interesting thing on last torque update change log: it says "Workaround for Galaxy Tab 2 OS bug". I Suppose there's some Samsung personalization that is causing problems...

Since torque programmers found a solution, do you think is possible to understand what to do to fix it here too?

Thanks...
 
Upvote 0

dsirio75

Member
Licensed User
Longtime User
Ok, i finally found my personal solution and it seems to work fine.
What i do? I call serial1.Connect(connectedDevice.Mac) the first time, on every connection error i call serial1.Connect3(connectedDevice.Mac, port) with port alwys incremented ... It fails 6/7 connections for example but connects 8th...

B4X:
Sub Admin_DiscoveryFinished
   ProgressDialogHide
   If foundDevices.Size = 0 Then
      ' some code
   Else
      Dim l As List
      l.Initialize
      For i = 0 To foundDevices.Size - 1
         Dim nm As NameAndMac
         nm = foundDevices.Get(i)
         l.Add(nm.Name)
      Next
      Dim res As Int
      res = InputList(l, "Seleziona il dispositivo da connettere", -1)
      If res <> DialogResponse.CANCEL Then
         connectedDevice = foundDevices.Get(res)
         Try
            serial1.Connect(connectedDevice.Mac)
         Catch
            Log(LastException)
         End Try
      End If
   End If
End Sub

Sub Serial1_Connected (Success As Boolean)
   ProgressDialogHide
   Log("connected: " & Success)
   If Success = False Then
      Log(LastException.Message)
      If port < 100 Then
         port = port + 1
         serial1.Connect3(connectedDevice.Mac, port)
      End If
   Else
      ' do something (connected)
   End If
End Sub

I hope this will help someone ;-)
 
Upvote 0

priusfan

Member
Licensed User
Longtime User
@desirio75
thank you for your workaround for BT and galaxy tab 7.

I made a small dev using BT with STN1110 for electric cars mitsubishi iMiev & peugeot iOn.
it was working well with any android device but galaxy tab 7. now it is ok.
thanks again.
 
Upvote 0

GaNdAlF89

Active Member
Licensed User
Longtime User
I have Samsung Galaxy Tab 2 with Android 4.0.3, I tried the desirio75 solution but it doesn't work. How can I resolve?
 
Upvote 0
Top