B4R Question serial communication with android

newbie

Member
Licensed User
Longtime User
Hi,
has somebody a Sample-code (B4A and B4R) how to communicate with a android device
over the android-usb port

Thanks vor hints
 

newbie

Member
Licensed User
Longtime User
It is pretty simple. You should use felUsbSerial or UsbSerial2 libraries. Example of communicating with a XBee module: https://www.b4x.com/android/forum/t...tween-android-and-raspberry-pi.62564/#content

Similar B4A code can be used to communicate with an Arduino.

Hi Erel,

i am using a usb to serial adapter (based on FTDI) like this
http://www.ebay.de/itm/FTDI-FT232RL...o-NePN-/302194919338?var=&hash=item465c3887aa

but i get every time
manager.GetDevices.length = 0

have you any suggestions ?

B4X:
    manager.Initialize
     If manager.GetDevices.Length = 0 Then
       Log("No connected usb devices.")
       ToastMessageShow("No USB", True)
     Else
       Dim device As UsbDevice = manager.GetDevices(0) '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
         Log("USB-Serial installiert")
         ToastMessageShow("USB installiert.", True)
       End If
     End If
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

newbie

Member
Licensed User
Longtime User
The Android device must recognize the USB adapter before it can be used. USB host feature is broken or disabled on many Android devices.
If you can root the device then you can try this:
https://www.b4x.com/android/forum/t...rs232-adaptor-driver.11449/page-3#post-121125

Also try this app: https://play.google.com/store/apps/details?id=eu.chainfire.usbhostdiagnostics&hl=en


I have try both links at a older doogge Android (4.2.2) and a new xgody(Android 5.1):
- the file android.hardware.usb.host.xml is ok on all devices
- the chainfire usbdiagnostics(1.3) cannot installed (parsing error) on all devices
- another tool "UsbHostChek" runs and say the android.hardware.usb.host.xml is ok
but a handheld_core_hardware.xml and tablet_core_hardware.xml are not ok
try to fix it gives a error

???
What can i do ??????
 
Upvote 0
Top