Please help, how to work with USB devices

Goldz

Member
Licensed User
Longtime User
Hello
Use and ricomagic mk802
I connect to it via USB Host webcam
I write lyrics
B4X:
Sub Process_Globals
     Dim UsbAcc As UsbAccessory
     Dim UsbMan As UsbManager

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("template1")

 UsbMan.Initialize
    Dim ListaAccesorios () As UsbAccessory
    ListaAccesorios = UsbMan.GetAccessories

End Sub
The compiler gives an error : java.lang.NullPointerException
Android 4.01 camera sees
The same result when connecting any device USB
Please help, how to work with USB devices connected via USB HOST (not OTG)
 
Last edited:

Goldz

Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
     Dim UsbAcces As UsbAccessory
    Dim UsbMan As UsbManager
    
End Sub

Sub Globals
    Dim Button1 As Button
    Dim Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("template1")
        If FirstTime = True Then
            UsbFind
        End If
End Sub

Sub Activity_Resume
    UsbFind
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub UsbFind
    UsbMan.Initialize
    Dim ListaAccesorios () As UsbAccessory
    ListaAccesorios = UsbMan.GetAccessories

End Sub

Logs
B4X:
** Activity (main) Create, isFirst = true **
** Activity (main) Create, isFirst = true **
main_usbfind (B4A line: 43)
ListaAccesorios = UsbMan.GetAccessories
java.lang.NullPointerException
   at anywheresoftware.b4a.objects.usb.UsbManagerWrapper.GetAccessories(UsbManagerWrapper.java:88)
   at b4a.example.main._usbfind(main.java:366)
   at b4a.example.main._activity_create(main.java:248)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
   at b4a.example.main.afterFirstLayout(main.java:89)
   at b4a.example.main.access$100(main.java:16)
   at b4a.example.main$WaitForLayout.run(main.java:74)
   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 **


main_usbfind (B4A line: 43)


ListaAccesorios = UsbMan.GetAccessories
Libs:
Core(version 2.47)
USB(version 0.96)

Android 4.01
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
Are you sure that the camera is an Android USB Accessory? Android Accessories are USB hosts that implement the Android accessory protocol with the Android device USB port in device mode. A standard Webcam is unlikely to be an Accessory.

Assuming the camera is a standard device then to connect it to your OTG mini-USB port you will need an OTG cable to switch the port to host mode. I take it you have connected it to your other full size USB port which is stated to be a Host on the Rikomagic web site. In either case the camera will appear (if if appears at all) as a device in UsbManager.GetDevices. If Android itself recognises the camera then it is unlikely that it will appear as Android only passes unrecognised devices to UsbManager. Some versions of Android seem buggy and don't pass on any devices at all when in host mode.

If it is a device you will need some technical information about how the device works and will need to manage the device EndPoints and communication yourself. This is a non-trivial task as you can see in the source of my Prolific PL2303 driver
 
Upvote 0

Goldz

Member
Licensed User
Longtime User
Dear agraham!
Thanks for the answer
I tried your advice - did not help
In general, I am suffering with Arduino Nano 3.0
Reviewed the entire Internet, but could not find a working example
All the examples above error end
Maybe advise yet!
 
Upvote 0
Top