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.
'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" />)
What happens when you connect the USB device while your app is not running? If the device filter is set correctly then you should see a dialog that is asking you whether to open your app.
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?
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'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