USB 0.93 Library Problem.

AndyW999

Member
Licensed User
Longtime User
I have tried your projects USB, USBDetails and USBpl2303Service to get my Eken T02A Android 4.0.3 kernel 3.0.8 to work with a PL2303 serial USB cable.

The device recognises the cable, creates and populates the 1-1 directory :-

event { 'add', '/devices/platform/sw_hcd_host0/usb1/1-1', 'usb', '', 189, 4 }
path : '/sys/devices/platform/sw_hcd_host0/usb1/1-1'
VID :size 5,vid_path '/sys/devices/platform/sw_hcd_host0/usb1/1-1/idVendor',VID '067b'.
PID :size 5,Pid_path '/sys/devices/platform/sw_hcd_host0/usb1/1-1/idProduct',PID '2303'.


But when I run any of the above projects and add :-

Log("Device Count " & usbdevices.Length)

the number of devices found is zero.

The device does have usb_modeswitch installed but I don't think that should affect anything.

cmd=/system/etc/usb_modeswitch.sh /system/etc/usb_modeswitch.d/067b_2303 &,
excute ret : 0,err:No such file or directory


I don't think I am doing anything wrong, maybe has something changed in Android 4 to screw up your USB library?

I also modified your USB ADB example as follows :-

Sub FindAdbDevice As Boolean
Dim usbacc() As UsbAccessory
Dim usbdevices() As UsbDevice
usbdevices = manager.GetDevices
usbacc = manager.GetAccessories
Log("Device Count " & usbdevices.Length)
Log("Acc Count " & usbacc.Length)


It appears that the GetAccessories has a problem too :-

main_findadbdevice (java line: 503)
java.lang.NullPointerException
at anywheresoftware.b4a.objects.usb.UsbManagerWrapper.GetAccessories(UsbManagerWrapper.java:88)
at anywheresoftware.b4a.samples.usb.main._findadbdevice(main.java:503)
at anywheresoftware.b4a.samples.usb.main._btnconnect_click(main.java:257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:124)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49)
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

Please could you check Android 4 compatibility with USB library?

Thanks

Andy.
 

agraham

Expert
Licensed User
Longtime User
There is no problem (apart from the fact that the Android USB implementation seems pretty broken) with the USBDetails and USBpl2303Service on Android 4.0.3 or Android 4.0.4 on my Xoom. As I have indicated several times some devices seem to not pass unrecognised USB devices that Android doesn't know how to use to UsbManager. Your device is probably one of them.

However there does seem to be a little bugette in GetAccessories. UsbManager.getAccessoryList is documented to return "a list of USB accessories, or null if none are attached". There is no null test in GetAccessories and so an exception is thrown if there are no attached USB accessories.
B4X:
  public UsbAccessoryWrapper[] GetAccessories()
  {
    UsbAccessory[] h = manager.getAccessoryList(); // can return null!
    UsbAccessoryWrapper[] uw = new UsbAccessoryWrapper[h.length];
    int i = 0;
    for (UsbAccessory u : h) {
      uw[i] = new UsbAccessoryWrapper();
      uw[i].accessory = u;
      i++;
    }
    return uw;
  }
 
Upvote 0

AndyW999

Member
Licensed User
Longtime User
So in effect I have been Scroogled by Android not working properly, sounds about right!

Thanks

Andy.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm not sure that it is Google fault. It is highly possible that it is the device manufacturer who didn't build this feature correctly.

From my experience, Android is focused on end users (unlike Windows CE for example).
USB will work fine when connected to a mass storage or a keyboard / mouse. However for custom USB clients, the behavior and reliability varies.

I had similar experience with Bluetooth. The common Bluetooth features work fine. However when you try to build a custom solution using SPP things doesn't always look so good.
 
Upvote 0

AndyW999

Member
Licensed User
Longtime User
I have asked the manufacturer about implementing PL2303 but not had any reply, at least they let me have the update FTP site.

I will try asking for the source and build environment... don't hold your breath!

I mentioned this device had usb_modeswitch in it - Draisberghof - Software - USB_ModeSwitch - I don't know if it is a standard Android package though.

Bluetooth and SPP, don't get me started on that, I had a very unpleasant time with a £3000 CSR BT development kit for remote controlling our mobile radio's from a Windows Mobile PDA several years ago, I don't know which is worse, VS2003 and Compact Framework or CSR's attitude to people.

Thankfully we never had to deploy it...
 
Upvote 0

wtheobald

New Member
Licensed User
Longtime User
USB lib

Hello!
I want to connect the Teensy board via USB to my Tablet PC (ZT ICS , Android 4.0.3). I have the same Problem with unknown USB devices. I tried it with a USB mouse too. The mouse works, but is a unknown device. I am a beginner and I dont know what to do with the wrapper program part. I only need a working USB lib.
Thanks
wtheobald
 
Upvote 0

wtheobald

New Member
Licensed User
Longtime User
USB lib

Hello!
I want to use my Tablet PC (ZT ICS , Android 4.0.3) as a terminal for my hardware. I did this before with a PC programmed with "Purebasic".That was nearly perfect. Now I want to do the same with "Basic4Android". I need a working interface USB or Serial like COM. Is there somewhere a working library or a (on my machine) working tutorial. I want only to program in B4A.

Many thanks
wtheobald
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Upvote 0

Essie5

Member
Licensed User
Longtime User
I'm having the same issue with Android 4.0.3. I have my application and USB device (custom) tested on Android 3.2.1 (Acer Iconia A500), but I run the same application and the same USB hardware on 4.0.3 (Xtex My Tablet 7) and I get the following:

event { 'add', '/devices/platform/sw-ohci.1/usb3/3-1', 'usb', '', 189, 263 }
path : '/sys/devices/platform/sw-ohci.1/usb3/3-1'
VID :size 5,vid_path '/sys/devices/platform/sw-ohci.1/usb3/3-1/idVendor',VID '1c40
'.
PID :size 5,Pid_path '/sys/devices/platform/sw-ohci.1/usb3/3-1/idProduct',PID '0bbd
'.
cmd=/system/etc/usb_modeswitch.sh /system/etc/usb_modeswitch.d/1c40_0bbd &,
excute ret : 0,err:No such file or directory
[1] 5.onFinished: Installation state replication succeeded.

So did the USB implementation change on Android 4?
 
Upvote 0

Essie5

Member
Licensed User
Longtime User
Do you see the USB device when you call manager.GetDevices?

No, it seems like the system is waiting for a mode switch command or something that never happens, so it simply doens't register the device on the bus. The manager.GetDevices returns an empty Array.

I also checked to make sure it is not a USB power issue (even though my board has a LED power indicator that lights up the second I plug in) by using a powered USB cable...same result.
 
Last edited:
Upvote 0

Essie5

Member
Licensed User
Longtime User
Weird, when I check DMESG after the connect I get
"usb 3-1: new full speed USB device number 3 using sw-ohci."
 
Upvote 0

Essie5

Member
Licensed User
Longtime User
Solved

Okay, one of those times where it really pays to buy proper equipment.

Apparantly the $100 difference between an XTEX My Tablet 7 and a Samsung Galaxy Tab 2 (7.0) is ACTUAL USB Host capabilities. Same app with the Samsung had working USB instantly.

Seriously, why do people hang full size USB connectors off devices and claim it is USB host when it really isn't???

Sorry for wasting your time!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…