B4A Library UsbSerial library 2.0 - supports more devices

Discussion in 'Additional libraries, classes and official updates' started by agraham, Apr 9, 2013.

  1. Ferraz71

    Ferraz71 Member Licensed User

    I would like to use comunication from usb port to control i2c peripherals, like ADC´s and GPIOS expanders, without external microcontrolers. The android apk, will do control trough a USB port, with only an FT232H IC or an MCP2221 IC like bridge. Is it possible with SerialUSB Library?
  2. Erel

    Erel Administrator Staff Member Licensed User

    I don't think so.
  3. Creideiki

    Creideiki Member Licensed User

    How can I create the library from the sources myself? I have to debug it a bit...
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. Creideiki

    Creideiki Member Licensed User

    The source is in the zip file...
    I need the possibility to use ASyncStreams; felUsbSerial doesn't seem to use them.

    I have an adapter with a FT232R, but it throws exceptions (e.g. java.lang.NullPointerException), so I have to figure out what happens.
  6. Erel

    Erel Administrator Staff Member Licensed User

    felUsbSerial implements a similar solution internally. If you are using AsyncStreamsText then you can use the modified version that I posted (I will help you find it).

    If you have the source code then you should be able to build it.
  7. Creideiki

    Creideiki Member Licensed User

    The same code uses Bluetooth with AsyncStreams, so that should work with UsbSerial, too.

    Is there a HowTo, how to make a B4A-library from java source code?
  8. DonManfred

    DonManfred Expert Licensed User

    Creideiki likes this.
  9. Creideiki

    Creideiki Member Licensed User

    Hm, sorry, this time I haven't searched indeed... Thanks for the link.
  10. BarryW

    BarryW Active Member Licensed User

    How to remove the message box after the connection is successfull.

    I try to connect a arduino to my phone the executes the program. It works fine but there is a messagebox if the connection success.

  11. Erel

    Erel Administrator Staff Member Licensed User

    The library doesn't show any msgbox. Search your code for msgbox.
  12. slugger

    slugger Member Licensed User


    I have been using this library in one of my apps for the last 2 years and it worked just fine in my old smartphone running Android 4.3.

    Basically there is a foreground service which reads and writes from/to the USB to RS232 adapter and everything works Ok even when the screen turns off.

    Now I am trying to run it on a new smartphone with Android 6.0.1 on it.

    The very same APK stops working when the screen turns off.

    At that point the USBPRESENT always returns no adapters even if I use a timer to periodically check for the presence of the USB-RS232 adapter.

    When I turn the screen back on the adapter is found and the serial communication resumes.

    The only solution I have found is to use the Phone library to keep the screen always on but although the backlight is dimmed it doesn't do too much good to the screen and the battery life.

    Is it a new feature of Android 6 ?

    Any workarounds?

    Thank you in advance.
  13. jahswani

    jahswani Active Member Licensed User

    I think this is the best moment to pass either to a background service or use a different thread for the background task.
  14. Erel

    Erel Administrator Staff Member Licensed User

    A different thread will not help.

    You should use PhoneWakeState to acquire a partial lock.
  15. slugger

    slugger Member Licensed User

    Thanks for the replies.

    I use the PhoneWakeState's PartialLock and KeepAlive to keep the screen ON and dimmed.

    If I use only the PartialLock the screen goes OFF and then the library doesn't find the adapter anymore...when I turn the display back on I am greeted again with the Android's request to grant USB permission to the application and then the communication starts to work again.

    The same APK installed in my old smartphone running Android 4.3 works perfectly even after the display turns off.

    I guess there's something in Android 6 that deactivates the USB permission granted to the app as soon as the screen goes off.
  16. rtek1000

    rtek1000 Active Member Licensed User

    App example for test of USB Serial Port cable

    Tested with FT232LR and PL2303 cables

    (for personal non-commercial use only)

    You can use this for test Arduino board, PIC (Microchip) and other systems!

    Attached Files:

    Last edited: Nov 23, 2016
  17. GaNdAlF89

    GaNdAlF89 Active Member Licensed User

    Hi to all! I have an usb barcode reader but it is not detected from this library (usbReader.UsbPresent(1) is equal to usbReader.USB_NONE). I think the problem is that the device is like a keyboard (it needs the focus on an editText).
    How can I solve the problem? Or, if the problem is the model of my usb barcode reader, how can I find a device to work correctly with this library? I need asynchronous reading. Thanks!
    Last edited: Nov 30, 2016
  18. rtek1000

    rtek1000 Active Member Licensed User


    I believe a Serial USB library is not for your case if it's like a keyboard.

    Well, if it's like a keyboard, try to see it in the Android Menu, Settings> Language and Input.

    I believe that if you use a common keyboard, maybe you need to define a key function like F2, F6 etc, or by touchscreen to set the focus.

    Does your scanner send initial string?
  19. rtek1000

    rtek1000 Active Member Licensed User

    I think you will need to start a new thread
  20. drponciano

    drponciano Member Licensed User

    Hello Krokiz! Did you get your program workin with FTDI? I have the exact same problem with the 2 bytes error. Any help?
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice