Android Question USB serial and multiple devices [almost solved]

adrian_eb

Member
Licensed User
Longtime User
Hi there,

Im using UsbSerial lib 2.3 to connect to an arduino, it works perfect BUT only if the arduino is the ONLY device connected to the USB to my Android TV BOX

If I have an USB mouse connected, the program doesn't find the arduino.

I can connect the arduino, run the soft, connect, and then plug the mouse...

I run the code using the IR remote control, with the key 3 to run the 'ask for permission' on the first time and the real connection on the second time, it just works

Also, is there any easy option to dont have to ask for permission every time I power on the BOX ?


Thanks in advance!


B4X:
    If KeyCode = KeyCodes.KEYCODE_3  Then
        If usb.UsbPresent = usb.USB_NONE Then
            Msgbox("No USB device or accessory detected!", "Error")
            Log("No USB device or accessory detected!" )
            Return
        End If
        Log("Checking permission")
        If (usb.HasPermission) Then
    '        Msgbox(usb.DeviceInfo, "Device Information")
            Log(usb.DeviceInfo )
            
            Dim dev As Int
            dev = usb.Open(115200)
            If dev <> usb.USB_NONE Then
                Log("Connected successfully!")
                astreams.Initialize(usb.GetInputStream, usb.GetOutputStream, "astreams")
            Else
                Log("Error opening USB port")
            End If
        Else
            Log("Request permission !!")
            usb.RequestPermission
            End If
    End If
 

adrian_eb

Member
Licensed User
Longtime User
It is probably a limitation of Android OS.


See posts #31 and #32: https://www.b4x.com/android/forum/t...e-usb-serial-library.62216/page-2#post-415487

Thanks for the answer, I moved to felUsbSerial library and it helped to point the problem!

I make it work with a mouse pluged, the USB ports order is important! If I plug the Arduino UNO on first USB , and use:

B4X:
Dim device As UsbDevice = manager.GetDevices(0)

it works fine, If I use the arduino on the second USB port, and a mouse on first USB, I have to use:

B4X:
Dim device As UsbDevice = manager.GetDevices(1)

to work!

Can you give me a hint to create something that detects the device number so it finds the arduino automaticaly ?

Thanks!

UPDATE: Found this!

https://www.b4x.com/android/forum/threads/usbdevice-productname-and-serialnumber.77155/#post-667948
 
Last edited:
Upvote 0

adrian_eb

Member
Licensed User
Longtime User
Have the permissions issue fixed, with the help of the device_filter.xml

Now it only bugs me, the SDK shows the warning:

B4X:
 The recommended value for android:targetSdkVersion is 26 or above (manifest editor). (warning #31)

If I put in the manifest

B4X:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/

I lose all access to the USB, it dont even ask for permission on install !!

Im still learning this, I have it working, but bugs me how to fix it or do it on the right way :)

Thanks
 
Upvote 0
Top