B4A Library Usb Host library

Attachments

  • USB.zip
    14.4 KB · Views: 1,804

dilettante

Active Member
Licensed User
Longtime User
Are you familiar with the PS3 controller protocol? The example code is specific to ADB protocol.

Don't most generic (non-Android) game controllers look like one of the HID Class gamepad or joystick, etc. devices?

I went 'round and 'round with the Bluetooth "Green Throttle" controller which like so many Android game controllers relys on goofy totally custom device types and proprietary APIs every game has to use or remapping game controller actions to buttons/keys and such. Bleh.

Somewhere here I read that USB HID devices get "eaten" by Android and can't be accessed using this library. Is this true even for custom HID Class devices (not a keyboard, mouse, gamepad, etc.)? I really want to use some USB sensors that are HID but don't present as common subtypes.

I guess I need to just try this out, and if it fails look at some even lower level API.
 

dilettante

Active Member
Licensed User
Longtime User
Note that you will need the full version in order to test USB.

Most HID devices are handled internally. In that case it is not possible to access these devices with Android USB Api (there isn't a lower level access available).

Thanks.

Under Windows I look for these devices by enumerating all HID devices and then weed them out. First by UsagePage and UsageID values, and further by VID and PID.

It isn't clear whether this library can provide all of those values, and that presumes non-standard HID device info can be returned at all (Android may "eat" these devices anyway).

I know on conventional Linux-based OSs people are using these devices. But that doesn't predict anything about how Android may handle them or how this particular library might deal with them.
 

pixelpop

Active Member
Licensed User
Longtime User
TaoTronics_Barcode_Scanner.jpg Dymo_M10_Postal_Scale.jpg

I have a very generic mini tablet with Android 4.0.4 and rooted. I have two USB devices--a barcode scanner and a postal scale that I connect to the tablet with a micro USB host OTG cable. The barcode scanner works as expected as a keyboard device (open notepad, scan a barcode and the UPC appears in the notepad). The scale is probably using a data packet of some sort, so it doesn't act as a keyboard. When I use USBDetails with these devices, the results are puzzling. The scanner shows as the RealTek WAN adapter (as has been discussed here and elsewhere) but it works as a keyboard anyway. However, the scale is correctly identified by USBDetails as a DYM M10 (Dymo Model M10), but I cannot interpret the remain info to determine if I can program an interface to read this devices output data. Attached are screen shots of both screen. Any help would be greatly appreciated.
 

pixelpop

Active Member
Licensed User
Longtime User
Thanks, Erel. When I run the USBSerialDemo app, I get this (screen cap). The Vendor and Product IDs are incorrect. Should I ignore this and just read the data on the USB port? I got a USB demo project in VB6 off the Internet that reads the USB data correctly, but only if I define the Vendor and Product IDs first.

Public Const MyVendorID = &H922
Public Const MyProductID = &H8003

Edit: Using SetCustomDevice I was able to get the Dymo M10 correctly recognized. I'm off and running! Thanks!!
 

Attachments

  • Screenshot_2014-02-16-05-08-30.png
    Screenshot_2014-02-16-05-08-30.png
    33 KB · Views: 273
Last edited:

pabloprat2013

New Member
Licensed User
Longtime User
This library has an event for you to send data usb host port?
I need print use port usb host
thanks for you help
 

javiman6969

Member
Licensed User
Longtime User
Hi, Erel.
I've been using this library for a long time with different devices with usb host.
Has been used for printing on different Receipt Printers usb smoothly.

But they have been tested with a new device an Android POS and does not detect any usb device. However with APP downloaded from Google PLay, "USB Host Controller" if it detects USB Hub and USB devices.
Could you tell me where you can be wrong? It would be possible to have the source code for the library to test it? Or some code to test where the error may come?
Thank you for your help
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the relevant Java code:

public void Initialize() {
manager = (UsbManager) BA.applicationContext.getSystemService(Context.USB_SERVICE);
}
public UsbDeviceWrapper[] GetDevices() {
HashMap<String, UsbDevice> h = manager.getDeviceList();
UsbDeviceWrapper[] uw = new UsbDeviceWrapper[h.size()];
int i = 0;
for (UsbDevice u : h.values()) {
uw = new UsbDeviceWrapper();
uw.setObject(u);
i++;
}
return uw;
}

If you can root the device then it is worth trying this solution: http://www.b4x.com/android/forum/threads/pl2303-usb-to-rs232-adaptor-driver.11449/page-3#post-121125
 

javiman6969

Member
Licensed User
Longtime User
Hi Erel.
I tried what you told me and the problem is not resolved. Moreover, the device is root and the correct file android.hardware.usb.host.xml.

When I run this code, I return 0 number of devices.



B4X:
    Dim usbdevices() As UsbAccessory
    Dim interface As UsbInterface
    Dim manager As UsbManager
     
     
    manager.Initialize
    usbdevices = manager.GetAccessories
    Msgbox("USB: " & usbdevices.Length, "")

However, the APP "USB Host Controller" perfectly detects devices and USB HUB.
Any idea, plus?
 
Last edited:

Josef Graessle

New Member
Licensed User
Longtime User
Who developed the USB host library? I would like to get more details how I have to use it, when I connet a non ADB device to an Android tablet. I have no ADB like communication, as the hardware was developed 5 years ago and is sold now for 5 years. The hardware has only 1 Bulk Endpoint IN and 1 Bulk Endpoint OUT. It works at PC's from Win-XP to Win-10 and I would like to use it with Android tablets too. By the USB host tutorial is the hardware correctly recognized, but I cannot transfer data IN and OUT.
 
Top