B4A Library UsbSerial library 2.0 - supports more devices

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

  1. Stulish

    Stulish Active Member Licensed User

    hi davelew1s,

    Have you tried putting the text into a string first
    SomeString = "H101" & chr(13) & chr(10)
    Not sure if it helps


  2. davelew1s

    davelew1s Active Member Licensed User

    Thanks stulish it now works.
    One more question can the RTS DTR lines be set from this lib?
    Thanks Dave.
  3. agraham

    agraham Expert Licensed User

    No. This due to lack off technical information on how each chip implements the control functionality which the manufacturers generally only provide to their OEM customers and not to end-users.
  4. davelew1s

    davelew1s Active Member Licensed User

    Thanks agraham that's a pity perhaps in the future. I'll have to hard wire them.
    thanks again Dave.
  5. Rigsby

    Rigsby Member Licensed User

    Thanks for that I understand now.

    I have several no-name unidentified chip USB/Rs232 cables. Using usb.deviceinfo I can get the vendorID and productID.

    If I hardcode these values for the time being as below into one of them that I am guessing is a Prolific(ish) clone....

    dev = usb.Open(baud)

    Then it always sends at 19200 no matter what you use as the baud.

    If you accept the values for vendorID and productID from your table inside the library on detected FTDI and Prolific it works just fine, it is just when you use setCustomDevice.

    Now I know you said it may be unpredictable using this function, fair enough I realise that, just letting you know my findings.


    Last edited: Apr 26, 2013
  6. GMan

    GMan Well-Known Member Licensed User

    I have an LENOVO 2109 tablet with JB 4.1.1 - but nothing happens when i connect something.
    Also when i press start always the same message: no usb device is connected
  7. Erel

    Erel Administrator Staff Member Licensed User

    Which USB device are you connecting?
  8. GMan

    GMan Well-Known Member Licensed User

    I tried several, FTDI, Prolific and CP2102 /2103 and some others.

    i connected a external keyboard from my other tablet (there it works with 2.2 without problems - connect - works)

    All in USB debugging is activated and allowed...
  9. agraham

    agraham Expert Licensed User

    USB debugging is irrelevant here. The USB keyboard should be recognised by Android and should work but will not be visible to programs so is not an indicator as whether USB host mode is supported. It's not clear from your post whether it is working on the Lenovo or not.

    It looks like your tablet does not support USB host mode. I assume you are using an OTG cable. Check you have the file android.hardware.usb.host.xml in /system/etc/permissions as mentioned here
  10. GMan

    GMan Well-Known Member Licensed User

    Aha, not found ... several in there, but not this.

    Found the solutin in the link but this Lenovo 2109 isnt rooted - so...:sign0148:
  11. GMan

    GMan Well-Known Member Licensed User

    i contacted the ebay seller of the adapter cable.
    he said, i need a cable with OTG support (which this one not have - its only a Adapter for connecting 2 handys).

    I bought the new one and will mail what happens ;-
  12. GMan

    GMan Well-Known Member Licensed User

    Got the new cable - now it works.
    Without the
    Keyboards, Devices - all are found and are working :)
    Last edited: Apr 30, 2013
  13. ralphie911

    ralphie911 Member Licensed User

    Multiple USB devices

    I have a tablet with an internal USB wireless device.

    When I use the UsbSerial library, it finds the first device only which is on bus 1, device 1. However, the prolific serial adapter which is on bus 2, device 1 it cannot connect to.

    The USB Host Controller app finds both devices successfully.

    Does anyone know of any tricks to work around this?
  14. agraham

    agraham Expert Licensed User

    To avoid complication UsbPresent, HasPermission, RequestPermission and DeviceInfo all work with the first USB device they encounter. This is a valid assumption for 99% of cases. However you might get it to work in your case as follows.

    In the code for your app take out any permission checks from your app and just Open the port.

    Try giving the PL2303 automatic permission by following the steps in the first post of this thread with the manifest additions and the device_filter.xml file. Then, once your app is installed, when you plug in the PL2303 you should be asked something like "Open ... when this USB device is connected". Press OK.

    Now your app will open and you may be able to immediately open the port. Check the return from Open which should be UsbSerial.USB_DEVICE if it has succeeded.
  15. drponciano

    drponciano Member Licensed User


    Is there a simple example of a timer based character reader from a USBSerial connected device? I'd like to have control myself of the bytes received instead of using asyncstream. I'm receiving large amounts of data in*115 or 230kbps so I need complete control. I'll appreciate any help.
  16. agraham

    agraham Expert Licensed User

    I don't understand why a Timer would give you any more control than using AsyncStreams. The InputStream that UsbSerial returns is not a full implementation and is intended for use only with AsyncStrreams.
  17. dune3000

    dune3000 Member Licensed User

    Hi, agraham

    Does the library support an event (like USB_CONNECTED) after I give it permission?
  18. agraham

    agraham Expert Licensed User

    I don't really understand the question but the answer is no. If you explicitly request permission within your app the USB device must already be connected for your app to see it. If you have the intent filter in the manifest and give the "always open" permission when the USB device is first plugged in after app installation then your app will be opened by Android with permission already available.
  19. rauldasel

    rauldasel Member Licensed User

    Android 2.3.4

    I try tu execute the UsbSerialDemo in a device with Android 2.3.4 and don't works.
    I've seen that it's necesary an Android 3.1 or later.

    It's possible works in my version? How?

    Thanks for replies and sorry for my english
  20. agraham

    agraham Expert Licensed User

    It needs 3.1 or later and a device with USB Host mode capability.
  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