VB6 access to Android multitouch data

KiloOne

Member
Licensed User
Longtime User
I would like to send multitouch PointerID, Action and X,Y variables to a VB6 program on my PC where I want to analyze the data as soon as I can after the event in Sub GesturesTouch (multitouch tutorial sub) on my Android.

Before I commit to using one of the ways to do this I would like some feedback on which way would be the easiest and/or most efficient.

I think I have at least these ways to get the data to VB6:
1. USB cable
2. Bluetooth
3. Wireless
4. ADB and winsock
5. File writing and reading

If there is a specific example of any of these available, please direct me to it.

I do not prefer 5. as the data could be significantly delayed.

4. may be doable but I need specifics (see http://www.b4x.com/android/forum/threads/how-to-xfer-data-using-usb-only.19771/ )

I have no experience with 3.

I prefer USB since this would also keep the battery charged on my Android.

Any help would be appreciated.

Thanks,
Dale
 

KiloOne

Member
Licensed User
Longtime User
Are you writing it for yourself or for others?
At this point it is only for me.

I have been able to figure out 4. ADB and winsock as follows:
1. b4a project referencing Core2.46, Gestures1.20, Network1.23 and Randomaccessfile1.32
2. This b4a code:
B4X:
#Region Module Attributes
    #FullScreen: True
    #IncludeTitle: False
    #ApplicationLabel: UpClicker
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
    Dim AStreams As AsyncStreams
    Dim Server As ServerSocket
    Dim Socket1 As Socket
End Sub
Sub Globals
    Dim bgd As Panel
    Dim G As Gestures
    Dim Canvas As Canvas
    Dim LastS As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        Server.Initialize(2222,  "Server")
        Server.Listen
        Log("MyIp = " & Server.GetMyIP)
    End If
    'Create a panel and add it to the activity
    bgd.Initialize("")
    Activity.AddView(bgd, 0, 0, 100%x, 100%y)
    Canvas.Initialize(bgd)
    'Add a listener for this panel   
    G.SetOnTouchListener(bgd, "GesturesTouch")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        Log("closing")
        AStreams.Close
        Socket1.Close
    End If
End Sub
Sub GesturesTouch(View As Object, PointerID As Int, Action As Int, X As Float, Y As Float) As Boolean
    Dim buffer() As Byte
    Dim s As String
    Dim st As String
    Dim px, py As Int 'could send float x and y if you want
    Dim tx, ty As Int 'could send float x and y if you want
    tx = x
    ty = Y
    For i = 0 To 4 'change 4 to suit your needs
        px = g.GetX(i)
        py = g.GetY(i)
        If px<>-1 AND py<>-1 Then
            s = s & " " & i & ": " & px & " x " & py
        End If   
    Next       
    s = s & " PID " & PointerID & " Act " & Action
    st = s  & " " & tx & " x " & ty & " " & DateTime.Now & Chr(13) & Chr(10)       
    If AStreams.IsInitialized =  True AND LastS <> s Then
      buffer = st.GetBytes("UTF8")
      AStreams.Write(buffer)
    End If
    LastS = s
    Return True
End Sub
Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
    If Successful Then
        ToastMessageShow("Connected", False)
        Socket1 = NewSocket
        'AStreams.InitializePrefix(Socket1.InputStream, False, Socket1.OutputStream, "AStreams")
        AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams")
    Else
        ToastMessageShow(LastException.Message, True)
    End If
    Server.Listen
End Sub
Sub AStreams_NewData (Buffer() As Byte)
    Dim msg As String
    msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    ToastMessageShow(msg, False)
    Log(msg)
End Sub
Sub AStreams_Error
    ToastMessageShow(LastException.Message, True)
End Sub

vb6 project as follows:
1. create form with a winsock control named winsock1 added to it.
2. put copy of adb.exe in the project directory
3. the following code (replace 192.168.1.3 with address of your android that gets logged when you run the above b4a program) :
B4X:
Option Explicit

Private Sub Form_Load()
  Shell (App.Path & "\adb.exe forward tcp:2222 tcp:2222")
  Winsock1.Connect "192.168.1.3", 2222
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  Dim d As String
  Winsock1.GetData d, vbString
  Debug.Print d;
End Sub

Pretty easy really but a steep learning curve. I will stick with this unless it proves too slow.

Dale

EDITED to send ALL multitouch data to vb6 (I think)
 
Last edited:
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
After searching here for USB related threads (Most others seem to assume the connection is to another Android Device or Serial), this seems to be the closest thing to what I need. It is a weird requirement, but what I need is:

1. An App/Service Running on a Samsung Galaxy Camera that listens over USB for commands.
2. When commands are received they will tell the app/service what needs done with the camera (Send Thumbnail/Frame, Take Picture, Zoom, etc).
3. For some commands a thumbnail or full Picture stream will be sent back to the PC/Laptop on the other end.

I realize this will best be done with Bluetooth or WiFi...and believe me I have suggested it as the coding will be easier too, but there is a big push for USB connectivity. Had I been able to use the other ways of connecting I would have made a type of web server and transmitted commands to it, so this emulating TCP like this seems like it could work with my model.

After using this for a couple weeks, what are your thoughts on it? My first thoughts on points of weakness in it is the relying on the adb app, USB Driver issues, and the IP address changing. The camera will be in an enclosed box, so the user will have limited access to it for modifying or seeing what the current IP is. I don't want setup of this to be too technical or something that needs changed multiple times either. I'll also be using VB(Although the .NET variety to communicate with it). I'm still open to better ways of communicating PC to Android over USB too if anyone has better suggestions.

Thanks in Advance
 
Upvote 0
Top