Android Question [SOLVED] felUSBSerial usage for DeLock USB-serial adaptor

Asoka

Member
Licensed User
Longtime User
Hi, Please help!
I want to use an USB to Serial adapter (type: FTDI) , (VID: 1027, PID: 24577) with my ODROID- XU3 device.
I planned to use it with LIB, felUSBSerial.

my try is:

B4X:
Sub btnConnect_Click
    Dim I As Int
    If manager.GetDevices.Length = 0 Then
        Log("No connected usb devices.")
    Else
        For I = 0 To manager.GetDevices.Length - 1
            Dim D As UsbDevice
            d = manager.GetDevices(I)
           
            Log(D.DeviceName )
            Log(D.VendorId)
            Log(D.ProductId)
        Next
        Dim device As UsbDevice = manager.GetDevices(1) 'assuming that there is exactly one device
        If manager.HasPermission(device) = False Then
            ToastMessageShow("Please allow connection and click again.", True)
            manager.RequestPermission(device)
        Else
            usbserial.Initialize("serial", device, -1)
            usbserial.BaudRate = 115200
            usbserial.DataBits = usbserial.DATA_BITS_8
            usbserial.StartReading
        End If
    End If
End Sub

The LOG content is:

B4X:
Logger connected to:  HARDKERNEL Co., Ltd. ODROID-XU3
--------- beginning of /dev/log/main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
/dev/bus/usb/006/003
3034
33107
/dev/bus/usb/002/002
1027
24577

my device name is "/dev/bus/usb/002/002"

i've no permission for this (as the "haspermission" says), but requestpermission dialog is not visible.
How can I give permission to device for usage.

Thanks a lot!
 

Asoka

Member
Licensed User
Longtime User
thank you Your answer!

my manifest:

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
AddPermission("android.permission.ACCESS_SUPERUSER")
AddActivityText(main, <intent-filter>
        <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
    </intent-filter>
    <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
        android:resource="@xml/device_filter" />)


and device_filter.xml file is:

B4X:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- 0x0403 / 0x6001: FTDI FT232R UART -->
    <usb-device vendor-id="1027" product-id="24577" />

    <!-- 0x2341 / Arduino -->
    <usb-device vendor-id="9025" />

    <!-- 0x16C0 / 0x0483: Teensyduino  -->
    <usb-device vendor-id="5824" product-id="1155" />
    
    <!-- 0x067b / 0x2303 Prolific PL2303 -->
    <usb-device vendor-id="1659" product-id="8963"/>

    <!-- 0x03eb / Atmel -->
    <usb-device vendor-id="1003" />
    
    <!-- 0x10c4 / 0xea60 Silicon Labs CP1202 -->
    <usb-device vendor-id="4292" product-id="60000"/>

</resources>

the xml file contains the adaptor's data, as I see.
The permission dialog not shown.

is there another way to give permission (e.g. "chmod", or as SuperUser)
 
Upvote 0

Asoka

Member
Licensed User
Longtime User
Thank You Erel!

I tried Your suggest:

1.: When I plug in the device while app is not running: nothing happens.
2.: I installed the "USB Host Diagnostics" apk, and when it asks to connect a device: nothing happens.

Seems the device (ODROID-XU3) locks the ports (but my wireless mouse+kbd's receiver works).
I think I must be run app with Admin rights ...
Whatis Your opinion?
 
Upvote 0

Asoka

Member
Licensed User
Longtime User
The solution was born!

Here:

1.: I give r/w permission to device "/dev/USB0" as superuser. When these rows are in program, the ODROID device asks me to run app as administrator:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    
    
    stdOut.Initialize
    stdErr.Initialize
    
    iRet = P.Shell("su", Array As String("-c", "chmod 666 " & DevName), stdOut, stdErr)
    CreateScreen
    
End Sub


the DevName is "/dev/USB0"

2.: The connection and port settings are here:
B4X:
Sub cmdConnect_Click
    d.SetPort(DevName,9600,2)
    AStream.Initialize(d.InputStream , d.OutputStream, "AStream")
    If AStream.IsInitialized = True Then
        cmdSend.Enabled = True
        cmdSend1.Enabled =True
        ToastMessageShow("Connected",False)
    Else     
        cmdSend.Enabled = False
        ToastMessageShow("Couldn't connect to: " & DevName,False)
    End If
    'ProgressDialogHide
End Sub

If We want to open the native serial port, then correct devname is: "/tty/SAC0"

I hope it can help others too.

Thank You for Your answers.
 
Upvote 0

MomoWen

Member
Licensed User
I'm using the felUsbSerial library for reading and writing, but when I have multiple serial ports sending messages to Android devices, I don't know that the devices in them are sending data
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
It is a mistake to post to old threads.

You already created a thread for your issue (exactly two). That should be enough. Be patient and wait for answers
 
Upvote 0
Top