Android Question USB Device Recognition

ChocoScope

Member
Licensed User
Longtime User
I have been trying to add a usb IO device to my program without success and using various routines provided by you including "USBdetails" and USBsamples 1.b4a. The programs always report "No USB Devices found" , no matter what combination of routine and connection I use.

I have found an app in the google app store called "USB Host Controller v0.44" and it reports all the devices I plug in to either of the Host Port (mini usb connector via conversion cable) or the OTG labelled (full size usb connector) on my tablet. This is whether the PC USB Debugging is connected or not.

The reports I get back from the app are as follows:-

Host Port (1-1)
FTDI US232B 6001:0403
FTDI UM245R 6001:0403
PROLIFIC USB 2303:067b

OTG Port (3-1)
FTDI US232B 6001:0403
FTDI UM245R 6001:0403
PROLIFIC USB 2303:067b

I have "UsbSerial v2.3" installed in the standard library together with the latest Device_Filter in program xml library and have modified the Manifest as instructed. Can you please give me some guidance as to what I am doing wrong? I am having some difficulty discerning between the USBserial routines and the USBmanager routines and how they interract. I have ordered the book and hope that it puts them more in perspective.
 

ChocoScope

Member
Licensed User
Longtime User
A1CS Fusion5 Model Number M1001
Android Version 4.0.3 (Icecream Sandwich)
Baseband Version 1.1
Kernel Version 3.0.8+ ... inet_dada@inetsoftware#308
Build Number 01F2-D1-H1-H02-BE40.20120413

But shouldn't the software be device independent?

Thank's Erel
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It should be. I mostly wanted to see the Android version.

You can try to write a simple program that enumerates over the connected USB devices: http://www.b4x.com/android/forum/threads/usb-host-library.11290/#content

The USB library is based on the standard USB api. If it doesn't work then I don't know how other apps can work with this USB.

This basically means that your device doesn't recognize the connected USB.

If you are willing to root the device then there is an XML file that you can add which may help.
 
Upvote 0

ChocoScope

Member
Licensed User
Longtime User
It should be. I mostly wanted to see the Android version.

You can try to write a simple program that enumerates over the connected USB devices: http://www.b4x.com/android/forum/threads/usb-host-library.11290/#content

The USB library is based on the standard USB api. If it doesn't work then I don't know how other apps can work with this USB.

This basically means that your device doesn't recognize the connected USB.

If you are willing to root the device then there is an XML file that you can add which may help.
 
Upvote 0

ChocoScope

Member
Licensed User
Longtime User
USB library was already in basic when I installed it. I ticked the box.

I tried putting the subroutine Sub FindAdbDevice into a program and
manager(.GetDevices), device, interface, Inendpoint and Outendpoint
all came up as undefined variables.

Can you define them please.

I don't want to root my device at this stage, as I would have to do that
with every tablet I used.
 
Upvote 0

ChocoScope

Member
Licensed User
Longtime User
OK ... Sorry to be a pain, but when I run the whole untouched version of USBdetails1.b4a this is my runtime error log.

LogCat connected to: 20080411

--------- beginning of /dev/log/system

--------- beginning of /dev/log/main


** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_button1_click (java line: 393)
java.lang.NullPointerException
at anywheresoftware.b4a.objects.usb.UsbManagerWrapper.GetDevices(UsbManagerWrapper.java:100)
at b4a.example.main._button1_click(main.java:393)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:158)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:64)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14109)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Msgbox - no device
 
Upvote 0

ChocoScope

Member
Licensed User
Longtime User
I just tried another tablet. It was an AMPE running Android 4.2.2
It didn't give the error messages but still reported no usb devices found.
I tried it with the debug cable in and the device via a converter cable
as it only has one usb mini socket. Tried switching off usb debugging and
there was no difference.

Did the above message give you any clues as to the problem?
 
Upvote 0

ChocoScope

Member
Licensed User
Longtime User
I have been looking more closely at "USBdetails" and observed the following.

The device_filter activity was not set in the manifest file or entered in the program xml folder.
I added it, but it made no difference.

When I ran the program, there were lots of warnings on different lines of code
saying "Return Type (in sub signature) should be set explicitly"

I don't know if these problems have arisen because I am running b4a version 3.0 or not
Maybe this is why the program is not reporting USB Devices?
 
Upvote 0

ChocoScope

Member
Licensed User
Longtime User
Can you please send me a pre-compiled version of USBdetail1.jar so that I can
run it on my tablet to see if it does the same thing.

Was it compiled on Android4Basic v3.0 or an earlier version?
 
Upvote 0

ChocoScope

Member
Licensed User
Longtime User
Hi Erel ! Hope you had a great Thanksgiving!

I have some good news ... I found an app on Google app store called USB Host Diagnostics by Chainfire.

I ran it and it fixed my tablet ! I don't know whether it rooted my tablet or not but I don't mind if it is that simple and I can can now communicate by usb.

I re-ran USBdetails and it gave the following message before printing out the details.

main_btnconnect_click (java line 313) ... java.lang.NumberFormatException : Invalid

I am not bothered, as I can use AsyncStreams at this stage for my project and am happy to close this thread.

I received the Basic 4 Android book and am delighted with it ! It is a great point of reference.

Keep Up the Good Work !!!
 
Upvote 0

ChocoScope

Member
Licensed User
Longtime User
Hi Erel. Thanks for Liking my post and I need your help again.

I have been playing around with AsyncStreams and have had some great results. However, sometimes the usb port doesn't open properly or asks for permission and the astreams does not always activate on _Resume. It seems that the _Activate or _Resume activities are not set up properly. If I initialize the astreams for a second time during _Resume, the astreams stop working.

Can you please scan over my simplified code to see if I am setting things up wrongly. When I manage to activate it, it works great!
Many Thanks

Sub Process_Globals
....................................
Dim astreams As AsyncStreams
End Sub

Sub Globals
....................................
Dim Uy1 As Float
End Sub

Sub Activity_Create(FirstTime As Boolean)
....................................
usb.RequestPermission
usb.Open(38400)

If usb.UsbPresent <> usb.USB_NONE Then
Msgbox("USB Opened","USB Device")
Else
Msgbox("Error opening USB port","USB Device")
End If
astreams.Initialize(usb.GetInputStream, usb.GetOutputStream, "astreams")
....................................
End Sub

Sub Activity_Resume
....................................
usb.Open(38400)
....................................
End Sub

Sub Button6_Click
....................................
Dim Message As String 'trigger data stream
Message="U" 'from a
astreams.Write(Message.GetBytes("UTF8")) 'single byte
....................................
End Sub

Sub Astreams_NewData (Buffer() As Byte)
Dim y As Int
For y = 0 To Buffer.Length -1
....................................
Uy1 = Buffer(y)+128
....................................
Next
End Sub
 
Upvote 0

ChocoScope

Member
Licensed User
Longtime User
I have taken on your recommendations and have tidied up my code to make sure that the driver is only opened once and the astreams are only initialised once and it works much better.

A problem I am having is ... if I unplug the usb cable and plug it in again, all connection is lost and even restarting the program doesn't re-connect it. I have to have the debug connected to start it up again.

If I have the usbdetails app installed. Plugging in the usb, the tablet magically asks if I want to run usbdetails. There must be something in the usbdetails code which the usb triggers to do this.

Are there a few lines of code I can add to my program which detects the usb being plugged in and initialises it when the program is running or asks me if I want to start my program when it is not?
 
Upvote 0

ChocoScope

Member
Licensed User
Longtime User
Thanks Erel. It turns out that I was using an old version of device_filter. I loaded the correct one and plugging in the usb brings up the program now. However, when it runs "Activity_Create" it has the "FirstTime" set as False. I am using "FirstTime" as my cue to initialize the usb and astreams and so when the usb is plugged in, they dont get initialised. I noticed that starting the program from pressing the icon also gives "FirstTime" as False. Can you please tell me why? I have tried adding "Activity.Finish" to the Pause activity to try to activate the "FirstTime" but it made no difference.
 
Upvote 0
Top